Files
classroomio/apps/dashboard/src/routes/+layout.svelte
T

239 lines
6.5 KiB
Svelte
Raw Normal View History

2023-10-29 12:07:34 +00:00
<script lang="ts">
// import { browser } from '$app/environment';
2024-11-19 19:45:31 +01:00
import { page } from '$app/stores';
import debounce from 'lodash/debounce';
2024-12-26 07:23:46 +01:00
import { course } from '$lib/components/Course/store';
import OrgNavigation from '$lib/components/Navigation/app.svelte';
2024-12-26 07:23:46 +01:00
import LandingNavigation from '$lib/components/Navigation/index.svelte';
import LMSNavigation from '$lib/components/Navigation/lms.svelte';
import OrgLandingPage from '$lib/components/Org/LandingPage/index.svelte';
import PlayQuiz from '$lib/components/Org/Quiz/Play/index.svelte';
import { PageRestricted } from '$lib/components/Page';
2025-11-01 15:49:29 +01:00
// import PageLoadProgressBar from '$lib/components/Progress/PageLoadProgressBar.svelte';
2024-12-26 07:23:46 +01:00
import Snackbar from '$lib/components/Snackbar/index.svelte';
2024-04-07 06:08:34 +01:00
import UpgradeModal from '$lib/components/Upgrade/Modal.svelte';
2025-11-01 16:18:29 +01:00
import {
isCoursesPage,
isLMSPage,
isOrgPage
// toggleBodyByMode
} from '$lib/utils/functions/app';
2024-12-26 07:23:46 +01:00
import { getProfile, setupAnalytics } from '$lib/utils/functions/appSetup';
import hideNavByRoute from '$lib/utils/functions/routes/hideNavByRoute';
import { getSupabase } from '$lib/utils/functions/supabase';
import { setTheme } from '$lib/utils/functions/theme';
import { initOrgAnalytics } from '$lib/utils/services/posthog';
import { globalStore } from '$lib/utils/store/app';
import { currentOrg } from '$lib/utils/store/org';
import { isMobile } from '$lib/utils/store/useMobile';
import merge from 'lodash/merge';
import { onMount } from 'svelte';
import { MetaTags } from 'svelte-meta-tags';
2025-11-08 05:02:17 +01:00
import isPublicRoute from '$lib/utils/functions/routes/isPublicRoute';
import { hasSession } from '$lib/utils/functions/supabase';
2025-11-08 05:02:17 +01:00
import { goto } from '$app/navigation';
2020-12-24 20:32:05 +02:00
2025-11-01 16:18:29 +01:00
import { ModeWatcher } from '@cio/ui/base/dark-mode';
import '../app.css';
2025-11-01 15:49:29 +01:00
let { data, children } = $props();
2023-08-14 06:22:03 +01:00
let supabase = getSupabase();
2025-11-01 15:49:29 +01:00
let path = $derived($page.url?.pathname?.replace('/', ''));
2024-03-22 06:30:24 +01:00
let queryParam = $page.url?.search;
2021-07-31 23:06:14 +03:00
2021-09-17 06:33:49 +03:00
function handleResize() {
isMobile.update(() => window.innerWidth <= 760);
}
const getProfileDebounced = debounce(getProfile, 1000);
function pageSetup() {
2023-05-13 07:16:32 +01:00
console.log(
'Welcome to ClassroomIO, we are grateful you chose us.',
$page.url.host,
2025-11-08 05:34:17 +01:00
`\nIs student domain: ${data.isOrgSite}`,
data
2023-05-13 07:16:32 +01:00
);
// $globalStore.isDark = localStorage.getItem('mode') === 'dark';
// toggleBodyByMode($globalStore.isDark);
2023-10-30 06:04:53 +00:00
setupAnalytics();
2021-09-17 06:33:49 +03:00
handleResize();
if (!data.isOrgSite || !data.org) return;
$globalStore.orgSiteName = data.orgSiteName;
$globalStore.isOrgSite = data.isOrgSite;
currentOrg.set(data.org);
// Setup internal analytics
initOrgAnalytics(data.orgSiteName);
setTheme(data.org?.theme);
}
onMount(() => {
pageSetup();
if (!hasSession() && !isPublicRoute($page.url?.pathname)) {
2025-11-08 05:02:17 +01:00
console.log('No auth token and is not a public route, redirect to login', path);
return goto('/login?redirect=/' + path);
}
2025-11-01 15:49:29 +01:00
const { data: authListener } = supabase.auth.onAuthStateChange((event) => {
console.log(`event`, event);
if (path.includes('reset')) {
console.log('Dont change auth when on reset page');
return;
}
if (data.skipAuth) return;
2023-12-05 08:31:26 +03:00
if (event === 'SIGNED_IN' || event === 'INITIAL_SESSION') {
getProfileDebounced({
2024-12-26 07:23:46 +01:00
path,
queryParam,
isOrgSite: data.isOrgSite,
orgSiteName: data.orgSiteName
});
}
});
2021-07-31 23:06:14 +03:00
return () => {
console.log('unsubscribed');
2023-10-29 12:07:34 +00:00
authListener.subscription.unsubscribe();
2021-07-31 23:06:14 +03:00
};
});
2025-11-01 15:49:29 +01:00
let metaTags = $derived(merge(data.baseMetaTags, $page.data.pageMetaTags));
2020-12-24 20:32:05 +02:00
</script>
2025-11-01 15:49:29 +01:00
<svelte:window onresize={handleResize} />
2025-11-01 16:18:29 +01:00
<ModeWatcher />
2024-08-01 14:04:50 +01:00
<MetaTags {...metaTags} />
2024-04-07 06:08:34 +01:00
<UpgradeModal />
2021-08-28 22:44:06 +03:00
<Snackbar />
2021-05-07 03:43:37 +03:00
2024-08-24 21:40:17 +01:00
{#if data.org?.is_restricted || $currentOrg.is_restricted}
<PageRestricted />
2024-08-24 20:44:16 +01:00
{:else if data.skipAuth}
2023-06-17 19:11:29 +00:00
<PlayQuiz />
2023-08-14 06:22:03 +01:00
{:else if data.isOrgSite && !path}
<OrgLandingPage orgSiteName={data.orgSiteName} org={data.org} />
{:else}
<main class="z-20000 dark:bg-black">
2023-12-09 10:56:46 +03:00
{#if !hideNavByRoute($page.url?.pathname)}
{#if isOrgPage($page.url?.pathname) || $page.url?.pathname.includes('profile') || isCoursesPage(path)}
2023-08-05 04:44:32 +01:00
<OrgNavigation bind:title={$course.title} isCoursePage={isCoursesPage(path)} />
2023-12-09 10:56:46 +03:00
{:else if isLMSPage($page.url?.pathname)}
<LMSNavigation />
{:else}
<LandingNavigation
2023-08-14 06:22:03 +01:00
isOrgSite={data.isOrgSite}
logo={data.isOrgSite ? $currentOrg.avatar_url : undefined}
orgName={data.isOrgSite ? $currentOrg.name : undefined}
disableSignup={false}
/>
{/if}
2024-11-19 19:45:31 +01:00
2025-11-01 15:49:29 +01:00
<!-- <PageLoadProgressBar textColorClass="text-neutral-700" /> -->
{/if}
2021-07-31 23:06:14 +03:00
<div class={path.includes('home') ? '' : 'flex justify-between'}>
2025-11-01 15:49:29 +01:00
{@render children?.()}
</div>
</main>
2021-07-31 23:06:14 +03:00
{/if}
2021-05-07 03:43:37 +03:00
2020-12-24 20:32:05 +02:00
<style>
2020-12-30 22:29:01 +02:00
main {
background-color: white;
2020-12-30 22:29:01 +02:00
box-sizing: border-box;
}
2021-04-03 16:43:02 +03:00
:global(a:hover) {
text-decoration: underline;
}
2021-05-06 08:22:25 +03:00
:global(:root) {
2021-07-28 22:29:23 +03:00
--main-primary-color: rgba(29, 78, 216, 1);
2021-05-06 08:22:25 +03:00
--border-color: #eaecef;
2022-11-28 11:23:46 +01:00
--app-background-color: #fafbfc;
2025-11-01 15:49:29 +01:00
--app-background: radial-gradient(circle at 10% 20%, rgb(239, 246, 249) 0%, rgb(206, 239, 253) 90%);
2023-09-26 11:23:54 +01:00
--dark-app-background: radial-gradient(circle at 10% 20%, rgb(0 0 0) 0%, rgb(27 60 74) 90%);
2022-11-28 11:23:46 +01:00
}
2023-08-18 08:28:18 +01:00
:global(.app-background) {
background: var(--app-background);
2021-05-06 08:22:25 +03:00
}
2023-09-26 11:23:54 +01:00
:global(.dark .app-background) {
background: var(--dark-app-background);
}
2023-04-23 22:28:18 +00:00
:global(.bx--data-table-container) {
width: 100%;
}
2023-08-20 21:28:55 +01:00
:global(.dark svg.dark) {
fill: #fff;
}
:global(.border-c) {
border: 1px solid var(--border-color);
}
:global(.border-bottom-c) {
border-bottom: 1px solid var(--border-color);
}
2023-08-07 09:53:07 +00:00
:global(.bx--search-close > svg) {
fill: black;
}
:global(.dark .bx--search-close:hover > svg) {
fill: #fff;
}
2023-08-11 09:44:50 +01:00
:global(.plyr__controls) {
2023-12-04 19:39:39 +03:00
background:
url(/logo-192.png) 99% 70% no-repeat,
2023-08-11 09:44:50 +01:00
linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.5)) !important;
2023-12-04 19:39:39 +03:00
background-size:
50px auto,
auto !important;
2023-08-11 09:44:50 +01:00
}
:global(.cards-container) {
width: 90%;
margin: 0 auto;
padding: 0;
display: grid;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
column-gap: 12px;
row-gap: 12px;
}
@media screen and (max-width: 768px) {
:global(.cards-container) {
width: 95%;
margin: 0 auto;
padding: 0;
display: grid;
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
column-gap: 12px;
row-gap: 12px;
}
}
2020-12-24 20:32:05 +02:00
</style>