Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #2120

Merged
merged 19 commits into from
May 9, 2024
Merged

Dev #2120

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/pr-main-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ jobs:

dev-branch-reset:
name: Git Reset Dev
if: false
needs: create-release
runs-on: ubuntu-22.04
steps:
Expand Down
7 changes: 6 additions & 1 deletion src/lib/constants/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,10 @@ export const
* @description
* 📣 Target `path` for **scores page**.
*/
routeIdScores = '/(scores)/[[lang=lang]]/scores'
routeIdScores = '/(scores)/[[lang=lang]]/scores',
/**
* @description
* 📣 Target `path` for **home page**.
*/
routeIdHome = '/(scores)/[[lang=lang]]'
;
46 changes: 46 additions & 0 deletions src/lib/firebase/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,52 @@ import type { Page } from '@sveltejs/kit';

// #region 🔥 USER

/**
* @author
* @izobov
* @summary
* - 🟥 MAIN
* - 🟦 HELPER
* @description
* 📣 Retrieves `Firebase/Firestore` data for **current user**.
* @param { string } uid
* 💠 **[required]** Target user **uid**.
* @return { Promise < void > }
*/
export async function getUserById
(
uid: string
)
{
// [🐞]
dlog
(
'🚏 checkpoint ➤ getUserById(..)',
true
);

console.log("db_firestore",db_firestore)
console.log("UID",uid)

const
docRef
= doc
(
db_firestore,
'betarena_users',
uid
),
docSnap
= await getDoc
(
docRef
)
;

if (!docSnap.exists()) return;

return docSnap.data();
}
/**
* @author
* @migbash
Expand Down
4 changes: 3 additions & 1 deletion src/lib/store/user-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ function createLocalStore
extract:
<Typ1>
(
dataPoint: 'geo-bookmaker' | 'lang' | 'lang-user' | 'uid'
dataPoint: 'geo-bookmaker' | 'lang' | 'lang-user' | 'uid' | 'user'
): Typ1 | NullUndef =>
{
const
Expand All @@ -539,6 +539,8 @@ function createLocalStore
return localStore?.user?.scores_user_data?.lang as Typ1 | NullUndef;
else if (dataPoint == 'uid')
return localStore?.user?.firebase_user_data?.uid as Typ1 | NullUndef;
else if (dataPoint === 'user')
return localStore?.user?.scores_user_data as Typ1 | NullUndef;
;

return;
Expand Down
40 changes: 33 additions & 7 deletions src/lib/utils/deeplink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ import { isSignInWithEmailLink, signInWithCustomToken, signInWithEmailLink } fro
import { auth } from '$lib/firebase/init.js';
import { setCookie } from '$lib/store/cookie.js';
import sessionStore from '$lib/store/session.js';
import userBetarenaSettings from '$lib/store/user-settings.js';
import { authWithMoralis, successAuthComplete } from './authentication.js';
import { AU_W_TAG, dlog, dlogv2, errlog } from './debug.js';

import type { Page } from '@sveltejs/kit';
import { routeIdHome } from '$lib/constants/paths.js';
import type { B_NAV_T } from '@betarena/scores-lib/types/navbar.js';
import { generateUrlCompetitions } from './string.js';

// #endregion ➤ 📦 Package Imports

Expand Down Expand Up @@ -51,13 +55,35 @@ export async function mainDeepLinkCheck
* @description
* 📝 Data for `page`.
*/
page = sessionStore.extract<Page>('page'),
/**
* @description
* 📝 Data for `page`.
*/
revertUrl = `${page?.url.origin}${page?.url.pathname}`
;
page = sessionStore.extract<Page>('page')
;
let /**
* @description
* 📝 Data for `page`.
*/
revertUrl = `${page?.url.origin}${page?.url.pathname}`
if (page?.route.id === routeIdHome)
{
const lang = sessionStore.extract<string>('lang');
const [preferedPage] = userBetarenaSettings.extract<{buttons_order: string[]}>('user')?.buttons_order || ["scores"];
const translations = page.data.B_NAV_T as B_NAV_T | null | undefined;
switch (preferedPage) {
case "competitions":
revertUrl = generateUrlCompetitions(
lang || "",
page.data.B_SAP_D3_CP_H
);
break;
case "content":
revertUrl =
translations?.scores_header_translations?.section_links
?.sports_content_url as string;
break;
case "scores":
default:
revertUrl = `/${lang === "en" ? "" : `${lang}/`}scores`;
}
}

await goto
(
Expand Down
89 changes: 43 additions & 46 deletions src/routes/(scores)/[[lang=lang]]/+page.server.ts
Original file line number Diff line number Diff line change
@@ -1,65 +1,62 @@
// ╭──────────────────────────────────────────────────────────────────────────────────╮
// │ 📌 High Order Component Overview │
// ┣──────────────────────────────────────────────────────────────────────────────────┫
// │ ➤ Internal Svelte Code Format :|: V.8.0 │
// │ ➤ Status :|: 🔒 LOCKED │
// │ ➤ Author(s) :|: @migbash │
// ┣──────────────────────────────────────────────────────────────────────────────────┫
// │ 📝 Description │
// ┣──────────────────────────────────────────────────────────────────────────────────┫
// │ Main Scores Platform Page Loader ('Client-Side') │
// ╰──────────────────────────────────────────────────────────────────────────────────╯

// #region ➤ 📦 Package Imports
// // ╭──────────────────────────────────────────────────────────────────────────────────╮
// // │ 📌 High Order Component Overview │
// // ┣──────────────────────────────────────────────────────────────────────────────────┫
// // │ ➤ Internal Svelte Code Format :|: V.8.0 │
// // │ ➤ Status :|: 🔒 LOCKED │
// // │ ➤ Author(s) :|: @migbash │
// // ┣──────────────────────────────────────────────────────────────────────────────────┫
// // │ 📝 Description │
// // ┣──────────────────────────────────────────────────────────────────────────────────┫
// // │ Main Scores Platform Page Loader ('Client-Side') │
// // ╰──────────────────────────────────────────────────────────────────────────────────╯

// // #region ➤ 📦 Package Imports

// import { ServerLoadEvent, redirect } from '@sveltejs/kit';

// import { main } from '$lib/sveltekit/load/load.lang.js';
// import { dlogv2 } from '$lib/utils/debug.js';
// import { getUserById, userDataFetch } from '$lib/firebase/common.js';

// #endregion ➤ 📦 Package Imports
// // #endregion ➤ 📦 Package Imports

// #region ➤ 🔄 LIFECYCLE [SVELTE]
// // #region ➤ 🔄 LIFECYCLE [SVELTE]

// /**
// * @type {import('./$types').PageLoad}
// */
// // /**
// // * @type {import('./$types').PageLoad}
// // */
// export async function load
// (
// event: ServerLoadEvent
// ): Promise < any >
// {
// console.log("EVENT :", event);
// const userId = await JSON.parse(event.locals.user);
// console.log("COOKIES :", userId["user-uid"]);
// if (!userId) redirect(300, "/scores");
// const user = await getUserById(userId);
// const { langParam } = await event.parent();
// // [🐞]
// dlogv2
// (
// '🚏 checkpoint ➤ src/routes/(scores)/[[lang=lang]]/+page.server.ts',
// [
// `🔹 [var] ➤ langParam :|: ${langParam}`,
// ],
// true
// );
// const defaultRedirectURL = `${langParam !== "en" ? `/${langParam}` : ""}/scores`;
// console.log("langParam1 :", langParam);
// const event_user = await JSON.parse(event.locals.user);
// const userId = event_user["user-uid"];
// console.log("COOKIES UID:", userId);

// const user = userId ? await getUserById(userId) : null;
// console.log("USER :", user);
// if (!user) redirect(300, "/scores");
// const
// d = await event.parent()
// ;
// console.log("PARENT DATA :", d);
// const {langParam} = d;
// // [🐞]
// dlogv2
// (
// '🚏 checkpoint ➤ src/routes/(scores)/[[lang=lang]]/+page.server.ts',
// [
// `🔹 [var] ➤ langParam :|: ${langParam}`,
// ],
// true
// );
// if (user)
// {
// return {}
// };
// console.log("REDIRECTING...", defaultRedirectURL)
// redirect(300, defaultRedirectURL)


// return await main
// (
// event,
// {
// langParam
// }
// );

// }

// #endregion ➤ 🔄 LIFECYCLE [SVELTE]
// // #endregion ➤ 🔄 LIFECYCLE [SVELTE]
20 changes: 9 additions & 11 deletions src/routes/(scores)/[[lang=lang]]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@
import { goto } from "$app/navigation";
import { page } from "$app/stores";
import { generateUrlCompetitions } from "$lib/utils/string.js";
import { browser } from "$app/environment";
import type { B_NAV_T } from "@betarena/scores-lib/types/navbar.js";

$: ({ serverLang } = $sessionStore);
$: [preferedPage] = $userBetarenaSettings.user?.scores_user_data
?.buttons_order || ["scores"];
$: trsanslationData = $page.data.B_NAV_T as B_NAV_T | null | undefined;
let isRedirect = false;
$: {
let url = $page.url.pathname;
switch (preferedPage) {
Expand All @@ -59,27 +60,24 @@
break;
case "content":
url =
trsanslationData?.scores_header_translations?.section_links
?.sports_content_url;
trsanslationData?.scores_header_translations?.section_links
?.sports_content_url;
break;
case "scores":
case "scores":
default:
url = `/${serverLang === "en" ? "" : `${serverLang}/`}scores`;
}
if (!isRedirect) {
goto(url);
isRedirect = true;
}
}
if (browser) {
goto(url);
}
}
// #endregion ➤ 📦 Package Imports
</script>

<section />


<style>
section {
height: 100%;
}
</style>

2 changes: 1 addition & 1 deletion src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@
// ╰─────
$: if (browser) {
_DEBUG_("Option1");
mainDeepLinkCheck();
userBetarenaSettings.useLocalStorage();
scoresAdminStore.useLocalStorage();
mainDeepLinkCheck();
}

// ╭─────
Expand Down
Loading