mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-15 21:53:36 +01:00
21 lines
627 B
TypeScript
21 lines
627 B
TypeScript
import type { Workspace } from '@yaakapp-internal/models';
|
|
import { atom, useAtomValue } from 'jotai';
|
|
import { jotaiStore } from '../lib/jotai';
|
|
import { invokeCmd } from '../lib/tauri';
|
|
|
|
export const workspacesAtom = atom<Workspace[]>(
|
|
await invokeCmd<Workspace[]>('cmd_list_workspaces'),
|
|
);
|
|
|
|
export const sortedWorkspacesAtom = atom((get) =>
|
|
get(workspacesAtom).sort((a, b) => a.name.localeCompare(b.name)),
|
|
);
|
|
|
|
export function useWorkspaces() {
|
|
return useAtomValue(sortedWorkspacesAtom);
|
|
}
|
|
|
|
export function getWorkspace(id: string | null) {
|
|
return jotaiStore.get(workspacesAtom).find((v) => v.id === id) ?? null;
|
|
}
|