feat: widgets and ai chat
This commit is contained in:
@@ -2,16 +2,10 @@
|
||||
import { page } from '$app/state';
|
||||
|
||||
import { UpgradeModal, PageLoadProgress, PageRestricted } from '$features/ui';
|
||||
import { user } from '$lib/utils/store/user';
|
||||
import { setTheme } from '$lib/utils/functions/theme';
|
||||
import { setupCloudAnalytics } from '$lib/utils/functions/appSetup';
|
||||
import { globalStore } from '$lib/utils/store/app';
|
||||
import { currentOrg } from '$lib/utils/store/org';
|
||||
import { appInitApi } from '$features/app/init.svelte';
|
||||
import { onMount } from 'svelte';
|
||||
import { authClient } from '$lib/utils/services/auth/client';
|
||||
import { CommandPalette, KeyboardShortcutListener } from '$features/search';
|
||||
import { isPublicRoute } from '$lib/utils/functions/routes/isPublicRoute';
|
||||
import { env } from '$env/dynamic/public';
|
||||
import { currentOrg } from '$lib/utils/store/org';
|
||||
import { authClient } from '$lib/utils/services/auth/client';
|
||||
|
||||
interface Props {
|
||||
children?: import('svelte').Snippet;
|
||||
@@ -28,79 +22,28 @@
|
||||
|
||||
let path = $derived(page.url.pathname);
|
||||
|
||||
function intialAppSetup() {
|
||||
setupCloudAnalytics();
|
||||
|
||||
if (data?.locals?.user) {
|
||||
user.set({
|
||||
...$user,
|
||||
isLoggedIn: true,
|
||||
currentSession: data.locals.user
|
||||
});
|
||||
}
|
||||
|
||||
if (!data.isOrgSite || !data.org) return;
|
||||
|
||||
$globalStore.orgSiteName = data.orgSiteName || '';
|
||||
$globalStore.isOrgSite = data.isOrgSite;
|
||||
|
||||
currentOrg.set(data.org);
|
||||
|
||||
const theme = data.org?.theme;
|
||||
setTheme(theme || 'blue');
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
const loadingIndicator = document.getElementById('app-loading-indicator');
|
||||
if (loadingIndicator) {
|
||||
loadingIndicator.style.display = 'none';
|
||||
}
|
||||
|
||||
intialAppSetup();
|
||||
|
||||
if (data.skipAuth) return;
|
||||
});
|
||||
|
||||
const session = authClient.useSession();
|
||||
const isSessionReady = $derived(!$session.isPending && !$session.isRefetching && $session.data);
|
||||
|
||||
$effect(() => {
|
||||
if ($session.isPending || $session.isRefetching || !!$session.data) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.skipAuth) return;
|
||||
|
||||
if (isPublicRoute(path) && (path !== '/' || data.isOrgSite)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$session.data && !path.startsWith('/login')) {
|
||||
console.log('session data is not available, go to login');
|
||||
window.location.href = '/login';
|
||||
}
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
if (!data?.locals?.fromSessions && isSessionReady) {
|
||||
authClient.getSession().then(() => {
|
||||
console.log('triggered new session');
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
console.log('env public server url', env.PUBLIC_SERVER_URL);
|
||||
console.log('env public is selfhosted', env.PUBLIC_IS_SELFHOSTED);
|
||||
if (isSessionReady && !appInitApi.isInitializedAndReady && !appInitApi.loading) {
|
||||
appInitApi.setupApp($session.data as App.Locals, {
|
||||
isOrgSite: data.isOrgSite,
|
||||
orgSiteName: data.orgSiteName
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
<UpgradeModal />
|
||||
<CommandPalette />
|
||||
<KeyboardShortcutListener />
|
||||
|
||||
{#if data.org?.isRestricted || $currentOrg.isRestricted}
|
||||
<PageRestricted />
|
||||
|
||||
Reference in New Issue
Block a user