feat(ui): add origin-style admin shell scaffold
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import { GlobalStateStore } from '@warkypublic/svelix';
|
||||
|
||||
const normalizeApiURL = (url: string): string => url.replace(/\/+$/, '');
|
||||
|
||||
const resolveApiURL = (envURL?: string): string => {
|
||||
const viteEnvURL =
|
||||
envURL?.trim() ||
|
||||
import.meta.env.VITE_API_URL?.trim() ||
|
||||
import.meta.env.VITE_API_BASE_URL?.trim() ||
|
||||
import.meta.env.VITE_URL?.trim();
|
||||
|
||||
if (viteEnvURL) return normalizeApiURL(viteEnvURL);
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
return `${window.location.protocol}//${window.location.host}/api`;
|
||||
}
|
||||
|
||||
const stateURL = GlobalStateStore.getState().session.apiURL?.trim();
|
||||
if (stateURL) return normalizeApiURL(stateURL);
|
||||
|
||||
return '';
|
||||
};
|
||||
|
||||
export { GlobalStateStore };
|
||||
|
||||
export function ensureApiURL(envURL?: string): string {
|
||||
const resolved = resolveApiURL(envURL);
|
||||
if (!resolved) return '';
|
||||
|
||||
const state = GlobalStateStore.getState();
|
||||
if (state.session.apiURL !== resolved) {
|
||||
state.setApiURL(resolved);
|
||||
}
|
||||
|
||||
return resolved;
|
||||
}
|
||||
|
||||
export function setCurrentPath(pathname: string): void {
|
||||
const state = GlobalStateStore.getState();
|
||||
const current = state.navigation.currentPage ?? {};
|
||||
|
||||
state.setCurrentPage({
|
||||
...current,
|
||||
path: pathname
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user