first commit
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import type { PageId, PageParams } from "../contracts/page";
|
||||
import type { CurrentUserView } from "../contracts/workspace";
|
||||
import { canAccessRoute, defaultPageForUser, resolveRouteHash } from "../routes/routes";
|
||||
import { firstPartyRoutes } from "../routes/routes";
|
||||
|
||||
const routeIds: PageId[] = firstPartyRoutes.map((route) => route.id);
|
||||
|
||||
export function isPageId(value: string): value is PageId {
|
||||
return routeIds.includes(value as PageId);
|
||||
}
|
||||
|
||||
export interface NavigationState {
|
||||
pageId: PageId;
|
||||
params: PageParams;
|
||||
}
|
||||
|
||||
export function initialNavigationState(user: CurrentUserView, hash = typeof window === "undefined" ? "" : window.location.hash): NavigationState {
|
||||
const resolved = resolveRouteHash(hash, user);
|
||||
if (!canAccessRoute(user, resolved.route.id)) {
|
||||
return { pageId: defaultPageForUser(user), params: {} };
|
||||
}
|
||||
return { pageId: resolved.route.id, params: resolved.params };
|
||||
}
|
||||
Reference in New Issue
Block a user