2023-10-29 12:07:34 +00:00
|
|
|
<script lang="ts">
|
2025-11-24 01:00:50 +01:00
|
|
|
import { page } from '$app/state';
|
2026-04-27 11:40:38 +01:00
|
|
|
import { onMount } from 'svelte';
|
2024-12-28 23:11:55 +01:00
|
|
|
|
2025-12-22 02:36:48 +01:00
|
|
|
import { Snackbar } from '$features/ui';
|
2026-04-27 11:40:38 +01:00
|
|
|
import { appInitApi } from '$features/app/init.svelte';
|
2026-07-12 22:46:44 +01:00
|
|
|
import PendingInviteModal from '$features/lms/components/pending-invite-modal.svelte';
|
2026-07-11 09:17:45 +01:00
|
|
|
import { resolveAppOrgParams } from '$features/app/resolve-app-org-params';
|
2026-04-27 11:40:38 +01:00
|
|
|
import { setupCloudAnalytics } from '$lib/utils/functions/appSetup';
|
|
|
|
|
import { globalStore } from '$lib/utils/store/app';
|
2026-05-18 03:47:22 +01:00
|
|
|
import { currentOrg, mergeAccountOrgFromServer } from '$lib/utils/store/org';
|
2026-07-11 09:17:45 +01:00
|
|
|
import { get } from 'svelte/store';
|
2026-04-27 11:40:38 +01:00
|
|
|
import { user } from '$lib/utils/store/user';
|
|
|
|
|
import { setTheme } from '$lib/utils/functions/theme';
|
|
|
|
|
import { authClient } from '$lib/utils/services/auth/client';
|
2024-12-26 07:23:46 +01:00
|
|
|
import merge from 'lodash/merge';
|
|
|
|
|
import { MetaTags } from 'svelte-meta-tags';
|
2026-07-12 17:52:23 +01:00
|
|
|
import AppModeWatcher from '$features/app/app-mode-watcher.svelte';
|
2026-07-08 03:28:38 +01:00
|
|
|
import OrgSiteFavicon from '$features/app/org-site-favicon.svelte';
|
2025-11-01 16:18:29 +01:00
|
|
|
|
|
|
|
|
import '../app.css';
|
2021-07-12 05:55:57 +03:00
|
|
|
|
2026-06-29 12:48:51 +01:00
|
|
|
import { setUploadLimitsContext } from '$lib/utils/config/upload-limits-context';
|
|
|
|
|
|
2025-11-01 15:49:29 +01:00
|
|
|
let { data, children } = $props();
|
2023-08-14 06:22:03 +01:00
|
|
|
|
2026-06-29 12:48:51 +01:00
|
|
|
setUploadLimitsContext(data.uploadLimits);
|
|
|
|
|
|
2025-11-24 01:00:50 +01:00
|
|
|
const metaTags = $derived(merge(data.baseMetaTags, page.data.pageMetaTags));
|
2026-04-27 11:40:38 +01:00
|
|
|
|
|
|
|
|
onMount(() => {
|
2026-05-20 16:01:07 +01:00
|
|
|
console.log('Layout', data);
|
|
|
|
|
|
2026-05-21 15:08:40 +01:00
|
|
|
const sessionUser = data?.locals?.user;
|
|
|
|
|
setupCloudAnalytics(
|
|
|
|
|
sessionUser ? { id: sessionUser.id, email: sessionUser.email, name: sessionUser.name } : undefined
|
|
|
|
|
);
|
2026-04-27 11:40:38 +01:00
|
|
|
|
|
|
|
|
if (data?.locals?.user) {
|
|
|
|
|
user.set({
|
|
|
|
|
...$user,
|
|
|
|
|
isLoggedIn: true,
|
|
|
|
|
currentSession: data.locals.user
|
|
|
|
|
});
|
|
|
|
|
}
|
2026-07-11 09:17:45 +01:00
|
|
|
});
|
2026-04-27 11:40:38 +01:00
|
|
|
|
2026-07-11 09:17:45 +01:00
|
|
|
$effect(() => {
|
|
|
|
|
if (!data.isOrgSite || !data.org) {
|
|
|
|
|
$globalStore.isOrgSite = false;
|
|
|
|
|
$globalStore.orgSiteName = '';
|
|
|
|
|
return;
|
2026-04-27 11:40:38 +01:00
|
|
|
}
|
2026-07-11 09:17:45 +01:00
|
|
|
|
|
|
|
|
$globalStore.orgSiteName = data.orgSiteName || '';
|
|
|
|
|
$globalStore.isOrgSite = true;
|
|
|
|
|
|
|
|
|
|
const existingOrg = get(currentOrg);
|
|
|
|
|
const shouldSetPublicOrg =
|
|
|
|
|
!existingOrg.id || existingOrg.siteName !== data.org.siteName || existingOrg.roleId === 0;
|
|
|
|
|
|
|
|
|
|
if (shouldSetPublicOrg) {
|
|
|
|
|
currentOrg.set(mergeAccountOrgFromServer(data.org));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setTheme(data.org.theme || 'blue');
|
2026-04-27 11:40:38 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const session = authClient.useSession();
|
|
|
|
|
const isSessionReady = $derived(!$session.isPending && !$session.isRefetching && $session.data);
|
2026-07-11 09:17:45 +01:00
|
|
|
const appOrgParams = $derived(resolveAppOrgParams(data, page.url.pathname, page.params.slug));
|
2026-04-27 11:40:38 +01:00
|
|
|
|
2026-07-11 09:17:45 +01:00
|
|
|
/*
|
|
|
|
|
Auth + org context for the whole dashboard.
|
|
|
|
|
|
|
|
|
|
setupApp runs once per session to load /account. After that, org context can
|
|
|
|
|
still change when a logged-in user navigates to a different tenant subdomain
|
|
|
|
|
or opens another /org/[slug] on the app host — without another setupApp run.
|
|
|
|
|
syncOrgContext re-pins currentOrg from the URL + cached account data.
|
|
|
|
|
*/
|
2026-04-27 11:40:38 +01:00
|
|
|
$effect(() => {
|
2026-07-11 09:17:45 +01:00
|
|
|
if (!isSessionReady || appInitApi.loading) {
|
|
|
|
|
return;
|
2026-04-27 11:40:38 +01:00
|
|
|
}
|
2026-07-11 09:17:45 +01:00
|
|
|
|
|
|
|
|
if (!appInitApi.isInitializedAndReady) {
|
|
|
|
|
appInitApi.setupApp($session.data as App.Locals, appOrgParams);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void appInitApi.syncOrgContext(appOrgParams);
|
2026-04-27 11:40:38 +01:00
|
|
|
});
|
2025-11-24 01:00:50 +01:00
|
|
|
</script>
|
2022-12-30 13:08:54 +01:00
|
|
|
|
2026-07-08 03:28:38 +01:00
|
|
|
{#if data.isOrgSite}
|
|
|
|
|
<OrgSiteFavicon org={data.org} />
|
|
|
|
|
{/if}
|
|
|
|
|
|
|
|
|
|
<svelte:head>
|
|
|
|
|
{#if !data.isOrgSite}
|
|
|
|
|
<link rel="icon" type="image/png" href="/favicon.ico" />
|
|
|
|
|
<link rel="icon" type="image/png" sizes="32x32" href="/logo-32.png" />
|
|
|
|
|
{/if}
|
|
|
|
|
</svelte:head>
|
|
|
|
|
|
2026-03-09 11:18:22 +01:00
|
|
|
<div>
|
2026-07-12 17:52:23 +01:00
|
|
|
<AppModeWatcher />
|
2025-11-01 16:18:29 +01:00
|
|
|
|
2026-03-09 11:18:22 +01:00
|
|
|
<MetaTags {...metaTags} />
|
2024-08-01 14:04:50 +01:00
|
|
|
|
2026-03-09 11:18:22 +01:00
|
|
|
<Snackbar />
|
2021-05-07 03:43:37 +03:00
|
|
|
|
2026-07-12 22:46:44 +01:00
|
|
|
{#if appInitApi.pendingOrgInvite}
|
|
|
|
|
<PendingInviteModal
|
|
|
|
|
bind:open={appInitApi.showPendingInviteModal}
|
|
|
|
|
invite={appInitApi.pendingOrgInvite}
|
|
|
|
|
onAccepted={(redirectTo) => appInitApi.handlePendingInviteAccepted(redirectTo)}
|
|
|
|
|
/>
|
|
|
|
|
{/if}
|
|
|
|
|
|
2026-04-12 08:58:41 +01:00
|
|
|
{@render children?.()}
|
2026-03-09 11:18:22 +01:00
|
|
|
</div>
|
2021-05-07 03:43:37 +03:00
|
|
|
|
2020-12-24 20:32:05 +02:00
|
|
|
<style>
|
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;
|
2023-09-26 11:23:54 +01:00
|
|
|
}
|
2023-04-23 22:28:18 +00:00
|
|
|
|
2023-08-20 21:28:55 +01:00
|
|
|
:global(.dark svg.dark) {
|
2023-05-05 20:19:45 +00:00
|
|
|
fill: #fff;
|
|
|
|
|
}
|
2023-05-11 15:15:18 +00:00
|
|
|
|
|
|
|
|
: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
|
|
|
|
2023-08-24 07:32:19 +00: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;
|
|
|
|
|
}
|
2023-09-12 11:31:20 +00:00
|
|
|
|
2023-09-08 09:17:05 +00:00
|
|
|
@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>
|