Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | 85x 48x 759x 85x 318x 61x 22x 85x 19x 19x 21x 21x 1x 21x 21x | import type { RouteLocationNamedRaw, RouteLocationNormalizedLoaded } from 'vue-router'
import type { FlowMembership } from '@/stores/flows'
/**
* The pages of a flow, under /flows/:flowSlug/... — the active flow of a tab
* is the one in its URL, so two tabs (or devices) can work in two flows at
* the same time. Every other page (messages, profile, notifications...) is
* global and keeps the tab's last flow as context for the sidebar.
*/
export const FLOW_ROUTE_NAMES = [
'home',
'entities',
'entity-items',
'catalog',
'store',
'exports',
'members',
'roles',
'api-keys',
'space-pages',
'space-page-editor'
] as const
export type FlowRouteName = (typeof FLOW_ROUTE_NAMES)[number]
/** Whether `route` is one of a flow's pages */
export function isFlowRoute(route: Pick<RouteLocationNormalizedLoaded, 'params'>): boolean {
return typeof route.params.flowSlug === 'string' && route.params.flowSlug !== ''
}
/**
* A link to a flow's page, e.g. `flowRoute('chess-club', 'entity-items', { entityId })`.
* Always names the flow: a page outside the flow (Notifications...) has no
* `flowSlug` to inherit.
*/
export function flowRoute(
flowSlug: string,
name: FlowRouteName,
params: Record<string, string> = {},
query?: RouteLocationNamedRaw['query']
): RouteLocationNamedRaw {
return { name, params: { ...params, flowSlug }, ...(query ? { query } : {}) }
}
/**
* The flow pages a user with no flow yet can still open, outside any flow
* (UC-CATALOG-006.1, store.req.md): the Catalog, its public entities and the Store.
*/
const FLOWLESS_ROUTE_NAMES: Partial<Record<FlowRouteName, string>> = {
catalog: 'flowless-catalog',
'entity-items': 'flowless-entity-items',
store: 'flowless-store'
}
/** The flowless twin of a flow page, if it has one */
export function flowlessRouteOf(name: FlowRouteName): string | null {
return FLOWLESS_ROUTE_NAMES[name] ?? null
}
/** The flow page a flowless one stands for, if `name` is a flowless page */
export function flowRouteOfFlowless(name: unknown): FlowRouteName | null {
const entry = Object.entries(FLOWLESS_ROUTE_NAMES).find(([, flowless]) => flowless === name)
return entry ? (entry[0] as FlowRouteName) : null
}
const LAST_FLOW_KEY = 'lastFlowId'
/** Remembers the flow this browser last worked in: the default of new tabs */
export function rememberLastFlow(flowId: string) {
try {
localStorage.setItem(LAST_FLOW_KEY, flowId)
} catch {
// Storage unavailable (private mode...): new tabs fall back to another default
}
}
function readLastFlow(): string | null {
try {
return localStorage.getItem(LAST_FLOW_KEY)
} catch {
return null
}
}
/**
* The flow a tab opens when its URL names none ("/", a global page): the
* last one used in this browser, else one the user owns, else the first.
*/
export function defaultFlow(flows: FlowMembership[]): FlowMembership | null {
const lastFlowId = readLastFlow()
return (
flows.find((flow) => flow.flowId === lastFlowId) ??
flows.find((flow) => flow.isOwner) ??
flows[0] ??
null
)
}
|