feat(web): add dashboard SPA routing
This commit is contained in:
@@ -11,6 +11,33 @@ export const loginStatePart: plugins.smartstate.StatePart<unknown, ILoginState>
|
||||
'persistent'
|
||||
);
|
||||
|
||||
export interface IUiState {
|
||||
activeView: string;
|
||||
activeSubview: string | null;
|
||||
}
|
||||
|
||||
const getInitialView = (): string => {
|
||||
const path = typeof window !== 'undefined' ? window.location.pathname : '/';
|
||||
const validViews = ['overview', 'platform', 'runtime', 'registry', 'secrets', 'domains', 'storage', 'logs'];
|
||||
const segments = path.split('/').filter(Boolean);
|
||||
const view = segments[0];
|
||||
return validViews.includes(view) ? view : 'overview';
|
||||
};
|
||||
|
||||
const getInitialSubview = (): string | null => {
|
||||
const path = typeof window !== 'undefined' ? window.location.pathname : '/';
|
||||
const segments = path.split('/').filter(Boolean);
|
||||
return segments[1] ?? null;
|
||||
};
|
||||
|
||||
export const uiStatePart = await appstate.getStatePart<IUiState>(
|
||||
'ui',
|
||||
{
|
||||
activeView: getInitialView(),
|
||||
activeSubview: getInitialSubview(),
|
||||
},
|
||||
);
|
||||
|
||||
export const loginAction = loginStatePart.createAction<{ username: string; password: string }>(
|
||||
async (statePartArg, payloadArg) => {
|
||||
const currentState = statePartArg.getState() || { identity: null };
|
||||
|
||||
Reference in New Issue
Block a user