2026-04-12 18:07:33 +01:00
|
|
|
import { currentOrg, currentOrgPath } from './org';
|
2026-03-11 11:21:41 +01:00
|
|
|
import { derived, writable } from 'svelte/store';
|
2026-03-12 06:15:39 +01:00
|
|
|
|
2026-03-11 11:21:41 +01:00
|
|
|
import { PUBLIC_IS_SELFHOSTED } from '$env/static/public';
|
2026-04-12 18:07:33 +01:00
|
|
|
import { ROLE } from '@cio/utils/constants';
|
2024-02-01 20:18:03 +01:00
|
|
|
|
|
|
|
|
export const globalStore = writable<{
|
|
|
|
|
isDark: boolean;
|
|
|
|
|
isOrgSite: boolean;
|
|
|
|
|
orgSiteName: string;
|
|
|
|
|
}>({
|
|
|
|
|
isDark: false,
|
|
|
|
|
isOrgSite: false,
|
2026-04-12 18:07:33 +01:00
|
|
|
orgSiteName: ''
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const isOrgStudent = derived(currentOrg, ($currentOrg) => {
|
|
|
|
|
if ($currentOrg.roleId === 0) return null;
|
|
|
|
|
|
|
|
|
|
return $currentOrg.roleId === ROLE.STUDENT;
|
2024-02-01 20:18:03 +01:00
|
|
|
});
|
2026-03-11 11:21:41 +01:00
|
|
|
|
|
|
|
|
/**
|
2026-04-12 18:07:33 +01:00
|
|
|
* Cloud: orgSite is always student (a teacher on an org subdomain sees the student view).
|
|
|
|
|
* Self-hosted: derived from isOrgStudent (role-based).
|
2026-03-11 11:21:41 +01:00
|
|
|
*/
|
2026-04-12 18:07:33 +01:00
|
|
|
export const isStudentExperience = derived([globalStore, isOrgStudent], ([$gs, $isStudent]) => {
|
2026-03-11 11:21:41 +01:00
|
|
|
const isCloud = PUBLIC_IS_SELFHOSTED !== 'true';
|
|
|
|
|
if (isCloud) return $gs.isOrgSite;
|
2026-04-12 18:07:33 +01:00
|
|
|
|
|
|
|
|
return $isStudent ?? false;
|
2026-03-11 11:21:41 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The root path for navigation: '/lms' for students, '/org/{siteName}' for admin/teacher
|
|
|
|
|
*/
|
|
|
|
|
export const basePath = derived([isStudentExperience, currentOrgPath], ([$isStudent, $orgPath]) =>
|
|
|
|
|
$isStudent ? '/lms' : $orgPath
|
|
|
|
|
);
|