mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-27 20:01:10 +01: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]);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { CookieJar } from '@yaakapp-internal/models';
|
||||
import { atom, useAtomValue } from 'jotai';
|
||||
import { jotaiStore } from '../lib/jotai';
|
||||
|
||||
export const cookieJarsAtom = atom<CookieJar[] | undefined>();
|
||||
|
||||
@@ -10,3 +11,7 @@ export const sortedCookieJars = atom((get) => {
|
||||
export function useCookieJars() {
|
||||
return useAtomValue(sortedCookieJars);
|
||||
}
|
||||
|
||||
export function getCookieJar(id: string | null) {
|
||||
return jotaiStore.get(cookieJarsAtom)?.find((e) => e.id === id) ?? null;
|
||||
}
|
||||
|
||||
@@ -3,15 +3,15 @@ import { InlineCode } from '../components/core/InlineCode';
|
||||
import { trackEvent } from '../lib/analytics';
|
||||
import { showConfirm } from '../lib/confirm';
|
||||
import { fallbackRequestName } from '../lib/fallbackRequestName';
|
||||
import { getGrpcRequest } from '../lib/store';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import { getGrpcRequest } from './useGrpcRequests';
|
||||
|
||||
export function useDeleteAnyGrpcRequest() {
|
||||
return useFastMutation<GrpcRequest | null, string, string>({
|
||||
mutationKey: ['delete_any_grpc_request'],
|
||||
mutationFn: async (id) => {
|
||||
const request = await getGrpcRequest(id);
|
||||
const request = getGrpcRequest(id);
|
||||
if (request == null) return null;
|
||||
|
||||
const confirmed = await showConfirm({
|
||||
|
||||
@@ -3,15 +3,15 @@ import { InlineCode } from '../components/core/InlineCode';
|
||||
import { trackEvent } from '../lib/analytics';
|
||||
import { showConfirm } from '../lib/confirm';
|
||||
import { fallbackRequestName } from '../lib/fallbackRequestName';
|
||||
import { getHttpRequest } from '../lib/store';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import { getHttpRequest } from './useHttpRequests';
|
||||
|
||||
export function useDeleteAnyHttpRequest() {
|
||||
return useFastMutation<HttpRequest | null, string, string>({
|
||||
mutationKey: ['delete_any_http_request'],
|
||||
mutationFn: async (id) => {
|
||||
const request = await getHttpRequest(id);
|
||||
const request = getHttpRequest(id);
|
||||
if (request == null) return null;
|
||||
|
||||
const confirmed = await showConfirm({
|
||||
|
||||
@@ -3,10 +3,9 @@ import { useSetAtom } from 'jotai';
|
||||
import { InlineCode } from '../components/core/InlineCode';
|
||||
import { trackEvent } from '../lib/analytics';
|
||||
import { showConfirm } from '../lib/confirm';
|
||||
import { getFolder } from '../lib/store';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import { foldersAtom } from './useFolders';
|
||||
import {foldersAtom, getFolder} from './useFolders';
|
||||
import { removeModelById } from './useSyncModelStores';
|
||||
|
||||
export function useDeleteFolder(id: string | null) {
|
||||
@@ -15,7 +14,7 @@ export function useDeleteFolder(id: string | null) {
|
||||
return useFastMutation<Folder | null, string>({
|
||||
mutationKey: ['delete_folder', id],
|
||||
mutationFn: async () => {
|
||||
const folder = await getFolder(id);
|
||||
const folder = getFolder(id);
|
||||
const confirmed = await showConfirm({
|
||||
id: 'delete-folder',
|
||||
title: 'Delete Folder',
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { Environment } from '@yaakapp-internal/models';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { atom } from 'jotai/index';
|
||||
import { jotaiStore } from '../lib/jotai';
|
||||
|
||||
export const environmentsAtom = atom<Environment[]>([]);
|
||||
|
||||
@@ -23,3 +24,7 @@ export const environmentsBreakdownAtom = atom<{
|
||||
export function useEnvironments() {
|
||||
return useAtomValue(environmentsBreakdownAtom);
|
||||
}
|
||||
|
||||
export function getEnvironment(id: string | null) {
|
||||
return jotaiStore.get(environmentsAtom).find((e) => e.id === id) ?? null;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
import type { Folder } from '@yaakapp-internal/models';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { atom } from 'jotai/index';
|
||||
import { jotaiStore } from '../lib/jotai';
|
||||
|
||||
export const foldersAtom = atom<Folder[]>([]);
|
||||
|
||||
export function useFolders() {
|
||||
return useAtomValue(foldersAtom);
|
||||
}
|
||||
|
||||
export function getFolder(id: string | null) {
|
||||
return jotaiStore.get(foldersAtom).find((v) => v.id === id) ?? null;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ import { emit } from '@tauri-apps/api/event';
|
||||
import type { GrpcConnection, GrpcRequest } from '@yaakapp-internal/models';
|
||||
import { trackEvent } from '../lib/analytics';
|
||||
import { minPromiseMillis } from '../lib/minPromiseMillis';
|
||||
import { isResponseLoading } from '../lib/model_util';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
import { useActiveEnvironment } from './useActiveEnvironment';
|
||||
import { useDebouncedValue } from './useDebouncedValue';
|
||||
@@ -64,7 +63,7 @@ export function useGrpc(
|
||||
reflect,
|
||||
cancel,
|
||||
commit,
|
||||
isStreaming: isResponseLoading(conn),
|
||||
isStreaming: conn != null && conn.state !== 'closed',
|
||||
send,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
import type { GrpcRequest } from '@yaakapp-internal/models';
|
||||
import { atom, useAtomValue } from 'jotai';
|
||||
import { jotaiStore } from '../lib/jotai';
|
||||
|
||||
export const grpcRequestsAtom = atom<GrpcRequest[]>([]);
|
||||
|
||||
export function useGrpcRequests() {
|
||||
return useAtomValue(grpcRequestsAtom);
|
||||
}
|
||||
|
||||
export function getGrpcRequest(id: string) {
|
||||
return jotaiStore.get(grpcRequestsAtom).find((r) => r.id === id) ?? null;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
import type { HttpRequest } from '@yaakapp-internal/models';
|
||||
import { atom, useAtomValue } from 'jotai';
|
||||
import type {HttpRequest} from '@yaakapp-internal/models';
|
||||
import {atom, useAtomValue} from 'jotai';
|
||||
import {jotaiStore} from "../lib/jotai";
|
||||
|
||||
export const httpRequestsAtom = atom<HttpRequest[]>([]);
|
||||
|
||||
export function useHttpRequests() {
|
||||
return useAtomValue(httpRequestsAtom);
|
||||
return useAtomValue(httpRequestsAtom);
|
||||
}
|
||||
|
||||
export function getHttpRequest(id: string) {
|
||||
return jotaiStore.get(httpRequestsAtom).find(r => r.id === id) ?? null;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import type { HttpUrlParameter } from '@yaakapp-internal/models';
|
||||
import { generateId } from '../lib/generateId';
|
||||
import { pluralize } from '../lib/pluralize';
|
||||
import { getHttpRequest } from '../lib/store';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import { useRequestEditor } from './useRequestEditor';
|
||||
import { showToast } from '../lib/toast';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import { getHttpRequest } from './useHttpRequests';
|
||||
import { useRequestEditor } from './useRequestEditor';
|
||||
import { useUpdateAnyHttpRequest } from './useUpdateAnyHttpRequest';
|
||||
|
||||
export function useImportQuerystring(requestId: string) {
|
||||
@@ -19,7 +19,7 @@ export function useImportQuerystring(requestId: string) {
|
||||
const querystring = split[1] ?? '';
|
||||
if (!querystring) return;
|
||||
|
||||
const request = await getHttpRequest(requestId);
|
||||
const request = getHttpRequest(requestId);
|
||||
if (request == null) return;
|
||||
|
||||
const parsedParams = Array.from(new URLSearchParams(querystring).entries());
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
import { isResponseLoading } from '../lib/model_util';
|
||||
import { useLatestHttpResponse } from './useLatestHttpResponse';
|
||||
|
||||
export function useIsResponseLoading(requestId: string | null): boolean {
|
||||
const response = useLatestHttpResponse(requestId);
|
||||
if (response === null) return false;
|
||||
return isResponseLoading(response);
|
||||
}
|
||||
@@ -2,7 +2,6 @@ import {useMutation} from "@tanstack/react-query";
|
||||
import type { Plugin } from '@yaakapp-internal/models';
|
||||
import { atom, useAtomValue, useSetAtom } from 'jotai';
|
||||
import { minPromiseMillis } from '../lib/minPromiseMillis';
|
||||
import { listPlugins } from '../lib/store';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
|
||||
const plugins = await listPlugins();
|
||||
@@ -36,3 +35,8 @@ export function useRefreshPlugins() {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async function listPlugins(): Promise<Plugin[]> {
|
||||
const plugins: Plugin[] = (await invokeCmd('cmd_list_plugins')) ?? [];
|
||||
return plugins;
|
||||
}
|
||||
|
||||
@@ -4,10 +4,10 @@ import mime from 'mime';
|
||||
import slugify from 'slugify';
|
||||
import { InlineCode } from '../components/core/InlineCode';
|
||||
import { getContentTypeHeader } from '../lib/model_util';
|
||||
import { getHttpRequest } from '../lib/store';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import { showToast } from '../lib/toast';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import { getHttpRequest } from './useHttpRequests';
|
||||
|
||||
export function useSaveResponse(response: HttpResponse) {
|
||||
return useFastMutation({
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import type { HttpResponse } from '@yaakapp-internal/models';
|
||||
import { trackEvent } from '../lib/analytics';
|
||||
import { getHttpRequest } from '../lib/store';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
import { getActiveCookieJar } from './useActiveCookieJar';
|
||||
import { getActiveEnvironment } from './useActiveEnvironment';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import { getHttpRequest } from './useHttpRequests';
|
||||
|
||||
export function useSendAnyHttpRequest() {
|
||||
return useFastMutation<HttpResponse | null, string, string | null>({
|
||||
mutationKey: ['send_any_request'],
|
||||
mutationFn: async (id) => {
|
||||
const request = await getHttpRequest(id);
|
||||
const request = getHttpRequest(id ?? 'n/a');
|
||||
if (request == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
import type { Settings } from '@yaakapp-internal/models';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { atom } from 'jotai/index';
|
||||
import { getSettings } from '../lib/store';
|
||||
import {jotaiStore} from "../lib/jotai";
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
|
||||
const settings = await getSettings();
|
||||
const settings = await invokeCmd<Settings>('cmd_get_settings');
|
||||
export const settingsAtom = atom<Settings>(settings);
|
||||
|
||||
export function useSettings() {
|
||||
return useAtomValue(settingsAtom);
|
||||
}
|
||||
|
||||
export function getSettings() {
|
||||
return jotaiStore.get(settingsAtom);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { useEffect } from 'react';
|
||||
import { jotaiStore } from '../lib/jotai';
|
||||
import { getWorkspaceMeta } from '../lib/store';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
import { activeWorkspaceIdAtom, getActiveWorkspaceId } from './useActiveWorkspace';
|
||||
import { cookieJarsAtom } from './useCookieJars';
|
||||
@@ -42,5 +41,5 @@ async function sync() {
|
||||
jotaiStore.set(environmentsAtom, await invokeCmd('cmd_list_environments', args));
|
||||
|
||||
// Single models
|
||||
jotaiStore.set(workspaceMetaAtom, await getWorkspaceMeta(workspaceId));
|
||||
jotaiStore.set(workspaceMetaAtom, await invokeCmd('cmd_get_workspace_meta', { workspaceId }));
|
||||
}
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import type { Folder } from '@yaakapp-internal/models';
|
||||
import {useSetAtom} from "jotai/index";
|
||||
import { getFolder } from '../lib/store';
|
||||
import { useSetAtom } from 'jotai/index';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
import {foldersAtom} from "./useFolders";
|
||||
import {updateModelList} from "./useSyncModelStores";
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import { foldersAtom, getFolder } from './useFolders';
|
||||
import { updateModelList } from './useSyncModelStores';
|
||||
|
||||
export function useUpdateAnyFolder() {
|
||||
const setFolders = useSetAtom(foldersAtom);
|
||||
return useFastMutation<Folder, unknown, { id: string; update: (r: Folder) => Folder }>({
|
||||
mutationKey: ['update_any_folder'],
|
||||
mutationFn: async ({ id, update }) => {
|
||||
const folder = await getFolder(id);
|
||||
const folder = getFolder(id);
|
||||
if (folder === null) {
|
||||
throw new Error("Can't update a null folder");
|
||||
}
|
||||
@@ -20,6 +19,6 @@ export function useUpdateAnyFolder() {
|
||||
},
|
||||
onSuccess: async (folder) => {
|
||||
setFolders(updateModelList(folder));
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import type { GrpcRequest } from '@yaakapp-internal/models';
|
||||
import { useSetAtom } from 'jotai/index';
|
||||
import { getGrpcRequest } from '../lib/store';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
import { grpcRequestsAtom } from './useGrpcRequests';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import { getGrpcRequest, grpcRequestsAtom } from './useGrpcRequests';
|
||||
import { updateModelList } from './useSyncModelStores';
|
||||
|
||||
export function useUpdateAnyGrpcRequest() {
|
||||
@@ -15,7 +14,7 @@ export function useUpdateAnyGrpcRequest() {
|
||||
>({
|
||||
mutationKey: ['update_any_grpc_request'],
|
||||
mutationFn: async ({ id, update }) => {
|
||||
const request = await getGrpcRequest(id);
|
||||
const request = getGrpcRequest(id);
|
||||
if (request === null) {
|
||||
throw new Error("Can't update a null request");
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import type { HttpRequest } from '@yaakapp-internal/models';
|
||||
import {useSetAtom} from "jotai/index";
|
||||
import { getHttpRequest } from '../lib/store';
|
||||
import { useSetAtom } from 'jotai/index';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
import {httpRequestsAtom} from "./useHttpRequests";
|
||||
import {updateModelList} from "./useSyncModelStores";
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import { getHttpRequest, httpRequestsAtom } from './useHttpRequests';
|
||||
import { updateModelList } from './useSyncModelStores';
|
||||
|
||||
export function useUpdateAnyHttpRequest() {
|
||||
const setHttpRequests = useSetAtom(httpRequestsAtom);
|
||||
@@ -15,7 +14,7 @@ export function useUpdateAnyHttpRequest() {
|
||||
>({
|
||||
mutationKey: ['update_any_http_request'],
|
||||
mutationFn: async ({ id, update }) => {
|
||||
const request = await getHttpRequest(id);
|
||||
const request = getHttpRequest(id);
|
||||
if (request === null) {
|
||||
throw new Error("Can't update a null request");
|
||||
}
|
||||
@@ -26,6 +25,6 @@ export function useUpdateAnyHttpRequest() {
|
||||
},
|
||||
onSuccess: async (request) => {
|
||||
setHttpRequests(updateModelList(request));
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import type { CookieJar } from '@yaakapp-internal/models';
|
||||
import { useSetAtom } from 'jotai/index';
|
||||
import { getCookieJar } from '../lib/store';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
import { cookieJarsAtom } from './useCookieJars';
|
||||
import { cookieJarsAtom, getCookieJar } from './useCookieJars';
|
||||
import { updateModelList } from './useSyncModelStores';
|
||||
|
||||
export function useUpdateCookieJar(id: string | null) {
|
||||
@@ -11,7 +10,7 @@ export function useUpdateCookieJar(id: string | null) {
|
||||
return useFastMutation<CookieJar, unknown, Partial<CookieJar> | ((j: CookieJar) => CookieJar)>({
|
||||
mutationKey: ['update_cookie_jar', id],
|
||||
mutationFn: async (v) => {
|
||||
const cookieJar = await getCookieJar(id);
|
||||
const cookieJar = getCookieJar(id);
|
||||
if (cookieJar == null) {
|
||||
throw new Error("Can't update a null workspace");
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import type { Environment } from '@yaakapp-internal/models';
|
||||
import { useSetAtom } from 'jotai/index';
|
||||
import { getEnvironment } from '../lib/store';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
import { environmentsAtom } from './useEnvironments';
|
||||
import {updateModelList} from "./useSyncModelStores";
|
||||
import { environmentsAtom, getEnvironment } from './useEnvironments';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import { updateModelList } from './useSyncModelStores';
|
||||
|
||||
export function useUpdateEnvironment(id: string | null) {
|
||||
const setEnvironments = useSetAtom(environmentsAtom);
|
||||
@@ -15,7 +14,7 @@ export function useUpdateEnvironment(id: string | null) {
|
||||
>({
|
||||
mutationKey: ['update_environment', id],
|
||||
mutationFn: async (v) => {
|
||||
const environment = await getEnvironment(id);
|
||||
const environment = getEnvironment(id);
|
||||
if (environment == null) {
|
||||
throw new Error("Can't update a null environment");
|
||||
}
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import type { Settings } from '@yaakapp-internal/models';
|
||||
import { useSetAtom } from 'jotai';
|
||||
import { getSettings } from '../lib/store';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
import { settingsAtom } from './useSettings';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import { getSettings, settingsAtom } from './useSettings';
|
||||
|
||||
export function useUpdateSettings() {
|
||||
const setSettings = useSetAtom(settingsAtom);
|
||||
return useFastMutation<Settings, unknown, Partial<Settings>>({
|
||||
mutationKey: ['update_settings'],
|
||||
mutationFn: async (patch) => {
|
||||
const settings = await getSettings();
|
||||
const settings = getSettings();
|
||||
const newSettings: Settings = { ...settings, ...patch };
|
||||
return invokeCmd<Settings>('cmd_update_settings', { settings: newSettings });
|
||||
},
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
import type { WorkspaceMeta } from '@yaakapp-internal/models';
|
||||
import { atom, useAtomValue } from 'jotai';
|
||||
import { jotaiStore } from '../lib/jotai';
|
||||
|
||||
export const workspaceMetaAtom = atom<WorkspaceMeta | null>(null);
|
||||
|
||||
export function useWorkspaceMeta() {
|
||||
return useAtomValue(workspaceMetaAtom);
|
||||
}
|
||||
|
||||
export function getWorkspaceMeta() {
|
||||
return jotaiStore.get(workspaceMetaAtom);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import type { Workspace } from '@yaakapp-internal/models';
|
||||
import { atom, useAtomValue } from 'jotai';
|
||||
import { listWorkspaces } from '../lib/store';
|
||||
import { jotaiStore } from '../lib/jotai';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
|
||||
const workspaces = await listWorkspaces();
|
||||
export const workspacesAtom = atom<Workspace[]>(workspaces);
|
||||
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)),
|
||||
@@ -12,3 +14,7 @@ export const sortedWorkspacesAtom = atom((get) =>
|
||||
export function useWorkspaces() {
|
||||
return useAtomValue(sortedWorkspacesAtom);
|
||||
}
|
||||
|
||||
export function getWorkspace(id: string | null) {
|
||||
return jotaiStore.get(workspacesAtom).find((v) => v.id === id) ?? null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user