mirror of
https://github.com/lobehub/lobehub.git
synced 2026-09-20 04:56:13 +08:00
ccb33fa48c
Backend-only slice of the workspace feature (server routers/services, database models with workspaceId threading, openapi middleware, business/server stubs, const/types). Excludes all UI (features/routes/store/hooks). Deploys dark behind the workspace feature flag. Includes open-source stub fixes: workspaceCreds router stub, ChargeParams workspaceId, usage.ts null-coalesce, DBMessageItem.workspaceId. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
// Stub for `@/store/workspace`. The real workspace store lives in the cloud
|
|
// repo; submodule-only tests don't have it on disk, so vite import-analysis
|
|
// fails without this alias.
|
|
//
|
|
// Returns a "no active workspace" state, which makes WorkspaceLink /
|
|
// useWorkspaceAwareNavigate behave like plain react-router. Tests that need
|
|
// an active workspace can spy on these selectors with `vi.spyOn`.
|
|
|
|
export const workspaceSelectors = {
|
|
activeWorkspace: () => null,
|
|
activeWorkspaceId: () => null,
|
|
hasActiveWorkspace: () => false,
|
|
isContextReady: () => true,
|
|
isLoading: () => false,
|
|
isMember: () => false,
|
|
isOwner: () => false,
|
|
isSwitchingWorkspace: () => false,
|
|
isViewer: () => false,
|
|
members: () => [],
|
|
myRole: () => null,
|
|
primaryOwnerId: () => null,
|
|
workspaces: () => [],
|
|
};
|
|
|
|
const noopState = {
|
|
activeWorkspaceId: null,
|
|
isSwitchingWorkspace: false,
|
|
isWorkspaceLoading: false,
|
|
members: [],
|
|
myRole: null,
|
|
workspaces: [],
|
|
};
|
|
|
|
type Selector<T> = (state: typeof noopState) => T;
|
|
|
|
export function useWorkspaceStore<T>(selector?: Selector<T>): T | typeof noopState {
|
|
return selector ? selector(noopState) : noopState;
|
|
}
|
|
|
|
useWorkspaceStore.getState = () => noopState;
|
|
useWorkspaceStore.setState = () => undefined;
|
|
useWorkspaceStore.subscribe = () => () => undefined;
|