mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-29 05:31:51 +02:00
Clean up model fetching and loading states
This commit is contained in:
@@ -1,31 +1,31 @@
|
||||
import { useParams } from '@tanstack/react-router';
|
||||
import type { Workspace } from '@yaakapp-internal/models';
|
||||
import { atom, useAtomValue } from 'jotai/index';
|
||||
import { useEffect } from 'react';
|
||||
import { jotaiStore } from '../lib/jotai';
|
||||
import { workspacesAtom } from './useWorkspaces';
|
||||
import {useParams} from '@tanstack/react-router';
|
||||
import type {Workspace} from '@yaakapp-internal/models';
|
||||
import {atom, useAtomValue} from 'jotai/index';
|
||||
import {useEffect} from 'react';
|
||||
import {jotaiStore} from '../lib/jotai';
|
||||
import {workspacesAtom} from './useWorkspaces';
|
||||
|
||||
export const activeWorkspaceIdAtom = atom<string>();
|
||||
|
||||
export const activeWorkspaceAtom = atom<Workspace | null>((get) => {
|
||||
const activeWorkspaceId = get(activeWorkspaceIdAtom);
|
||||
const workspaces = get(workspacesAtom);
|
||||
return workspaces.find((w) => w.id === activeWorkspaceId) ?? null;
|
||||
const activeWorkspaceId = get(activeWorkspaceIdAtom);
|
||||
const workspaces = get(workspacesAtom);
|
||||
return workspaces.find((w) => w.id === activeWorkspaceId) ?? null;
|
||||
});
|
||||
|
||||
export function useActiveWorkspace(): Workspace | null {
|
||||
return useAtomValue(activeWorkspaceAtom);
|
||||
return useAtomValue(activeWorkspaceAtom);
|
||||
}
|
||||
|
||||
export function getActiveWorkspaceId() {
|
||||
return jotaiStore.get(activeWorkspaceIdAtom) ?? null;
|
||||
return jotaiStore.get(activeWorkspaceIdAtom) ?? null;
|
||||
}
|
||||
|
||||
export function getActiveWorkspace() {
|
||||
return jotaiStore.get(activeWorkspaceAtom) ?? null;
|
||||
return jotaiStore.get(activeWorkspaceAtom) ?? null;
|
||||
}
|
||||
|
||||
export function useSubscribeActiveWorkspaceId() {
|
||||
const { workspaceId } = useParams({ strict: false });
|
||||
useEffect(() => jotaiStore.set(activeWorkspaceIdAtom, workspaceId), [workspaceId]);
|
||||
const {workspaceId} = useParams({strict: false});
|
||||
useEffect(() => jotaiStore.set(activeWorkspaceIdAtom, workspaceId), [workspaceId]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user