Skip to content

Commit

Permalink
fix: update dependencies and add language detection in article creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Izobov committed Nov 19, 2024
1 parent ebfec78 commit 7df1a69
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 10 deletions.
52 changes: 48 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
},
"dependencies": {
"@betarena/ad-engine": "0.0.51",
"@betarena/scores-lib": "4.0.29",
"@betarena/scores-lib": "4.0.30",
"@lukeed/uuid": "2.0.1",
"@metamask/sdk": "0.1.0",
"@moralisweb3/client-firebase-auth-utils": "2.18.4",
Expand Down Expand Up @@ -82,6 +82,7 @@
"express": "4.18.2",
"express-sslify": "1.2.0",
"firebase": "9.20.0",
"franc": "6.2.0",
"graphql-request": "5.1.0",
"graphql-subscriptions-client": "0.16.4",
"heroku-ssl-redirect": "0.1.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
let title = "";
let isSaving = false;
let isSaved = false;
let lang = "";
$: translations = (data as any).RESPONSE_PROFILE_DATA
.sportstack2 as TranslationSportstacksSectionDataJSONSchema;
$: init(article);
Expand Down Expand Up @@ -141,9 +142,11 @@
isSaved = false;
const res = await updateArticle();
isSaving = false;
lang = res.lang;
if (res.success) {
isSaved = true;
}
if (res.id && !$page.url.searchParams.get("draft")) {
id = res.id;
const url = $page.url;
Expand Down Expand Up @@ -223,6 +226,8 @@
<span class="dot">.</span><span class="dot">.</span><span
class="dot">.</span
>
{:else if lang}
<span>{lang.toLocaleUpperCase()}</span>
{/if}
</div>
{/if}
Expand Down
25 changes: 22 additions & 3 deletions src/lib/components/page/profile/pupblication/editor/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ import session from "$lib/store/session.js";
import type { AuthorsAuthorsMain, TranslationSportstacksSectionDataJSONSchema } from "@betarena/scores-lib/types/v8/_HASURA-0.js";
import { type Writable, writable } from "svelte/store";
import type { IPageAuthorArticleData, IPageAuthorAuthorData } from "@betarena/scores-lib/types/v8/preload.authors.js";
import { franc, francAll } from "franc";


const francLangMap = {
"eng": "en",
"spa": "es",
"por": "pt",
"fra": "fr",
"ita": "it",
"ron": "ro",
"srp": "sr",
}

export function getAllImages(editor: Editor)
{
const json = editor.getJSON();
Expand All @@ -30,17 +43,23 @@ export function getAllImages(editor: Editor)
}


export async function upsert({ editor, title, author, reload = false, showLoaders = true, id, translations }: {
export async function upsert({ editor, title, author, reload = false, showLoaders = true, id, translations, detectLanguage = true }: {
translations: TranslationSportstacksSectionDataJSONSchema
| undefined, editor: Editor, title: string, author: AuthorsAuthorsMain, reload?: boolean, showLoaders?: boolean, id?: number
| undefined, detectLanguage: boolean, editor: Editor, title: string, author: AuthorsAuthorsMain, reload?: boolean, showLoaders?: boolean, id?: number
})
{
const v = DOMPurify.sanitize(editor.getHTML());
const t = DOMPurify.sanitize(title);
const images = getAllImages(editor);

const { seo, tags } = create_article_store.get();
let lang = "en";
if (detectLanguage)
{
const res = franc(editor.getText());
lang = francLangMap[res] || "en";

}
const loadingId = showLoaders && infoMessages.add({ type: "loading", text: translations?.saving || "Saving article..." });
const res = await postv2("/api/data/author/article", {
content: v,
Expand All @@ -57,7 +76,7 @@ export async function upsert({ editor, title, author, reload = false, showLoader
{
infoMessages.remove(loadingId);
}
if (!showLoaders) return res;
if (!showLoaders) return { ...res, lang };
if (res.success)
{
infoMessages.add({ type: "success", text: translations?.article_saved || "Article saved!" });
Expand Down
3 changes: 2 additions & 1 deletion src/lib/sveltekit/endpoint/sportstack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ async function getSportstackByUserId
offset?: number
)
{
const ql = (await new _GraphQL().wrapQuery<ITableAuthorAuthorQuery4Var, ITableAuthorAuthorQuery4Out>(TableAuthorAuthorQuery4, {
const type = !limit && !offset ? 'all' : 'pagination';
const ql = (await new _GraphQL().wrapQuery<ITableAuthorAuthorQuery4Var, ITableAuthorAuthorQuery4Out>(TableAuthorAuthorQuery4(type), {
uid,
limit,
offset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const load: LayoutServerLoad = (async ({ locals, fetch, params }) =>
async function getSportsTacks(uid?: string)
{
if (!uid) return [];
const response = await fetch(`/api/data/author/sportstack?user=${uid}&limit=200`);
const response = await fetch(`/api/data/author/sportstack?user=${uid}`);
const data = await response.json() as { sportstacks: AuthorsAuthorsMain[]; };
return data.sportstacks;
}
Expand Down

0 comments on commit 7df1a69

Please sign in to comment.