feat: centralize baseURL and app experience for cloud and self hosted
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { writable } from 'svelte/store';
|
||||
import { derived, writable } from 'svelte/store';
|
||||
import { PUBLIC_IS_SELFHOSTED } from '$env/static/public';
|
||||
import { currentOrgPath } from './org';
|
||||
|
||||
export const globalStore = writable<{
|
||||
isDark: boolean;
|
||||
@@ -11,3 +13,20 @@ export const globalStore = writable<{
|
||||
orgSiteName: '',
|
||||
isStudent: undefined
|
||||
});
|
||||
|
||||
/**
|
||||
* Single source of truth: is this a student experience?
|
||||
* Cloud: orgSite is always student. Self-hosted: check role.
|
||||
*/
|
||||
export const isStudentExperience = derived(globalStore, ($gs) => {
|
||||
const isCloud = PUBLIC_IS_SELFHOSTED !== 'true';
|
||||
if (isCloud) return $gs.isOrgSite;
|
||||
return $gs.isStudent ?? false;
|
||||
});
|
||||
|
||||
/**
|
||||
* The root path for navigation: '/lms' for students, '/org/{siteName}' for admin/teacher
|
||||
*/
|
||||
export const basePath = derived([isStudentExperience, currentOrgPath], ([$isStudent, $orgPath]) =>
|
||||
$isStudent ? '/lms' : $orgPath
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user