Ability to open workspace from directory, WorkspaceMeta, and many sync improvements

This commit is contained in:
Gregory Schier
2025-01-08 14:57:13 -08:00
parent 37671a50f2
commit cbc443075a
71 changed files with 1012 additions and 1844 deletions

View File

@@ -16,6 +16,15 @@ export function showAlert({ id, title, body, size = 'sm' }: AlertArgs) {
title,
hideX: true,
size,
disableBackdropClose: true, // Prevent accidental dismisses
render: ({ hide }) => Alert({ onHide: hide, body }),
});
}
export function showSimpleAlert(title: string, message: string) {
showAlert({
id: 'simple-alert',
body: message,
title: title,
});
}

View File

@@ -1,51 +0,0 @@
import type { Folder, Workspace } from '@yaakapp-internal/models';
import { getActiveWorkspaceId } from '../hooks/useActiveWorkspace';
import { createFastMutation } from '../hooks/useFastMutation';
import { trackEvent } from './analytics';
import { showPrompt } from './prompt';
import { router } from './router';
import { invokeCmd } from './tauri';
export const createWorkspace = createFastMutation<Workspace, void, Partial<Workspace>>({
mutationKey: ['create_workspace'],
mutationFn: (patch) => invokeCmd<Workspace>('cmd_update_workspace', { workspace: patch }),
onSuccess: async (workspace) => {
await router.navigate({
to: '/workspaces/$workspaceId',
params: { workspaceId: workspace.id },
});
},
onSettled: () => trackEvent('workspace', 'create'),
});
export const createFolder = createFastMutation<
Folder | null,
void,
Partial<Pick<Folder, 'name' | 'sortPriority' | 'folderId'>>
>({
mutationKey: ['create_folder'],
mutationFn: async (patch) => {
const workspaceId = getActiveWorkspaceId();
if (workspaceId == null) {
throw new Error("Cannot create folder when there's no active workspace");
}
if (!patch.name) {
const name = await showPrompt({
id: 'new-folder',
label: 'Name',
defaultValue: 'Folder',
title: 'New Folder',
confirmText: 'Create',
placeholder: 'Name',
});
if (name == null) return null;
patch.name = name;
}
patch.sortPriority = patch.sortPriority || -Date.now();
return invokeCmd<Folder>('cmd_update_folder', { folder: { workspaceId, ...patch } });
},
onSettled: () => trackEvent('folder', 'create'),
});

View File

@@ -3,13 +3,10 @@ import { Confirm } from '../components/core/Confirm';
import type { DialogProps } from '../components/core/Dialog';
import { showDialog } from './dialog';
interface ConfirmArgs {
type ConfirmArgs = {
id: string;
title: DialogProps['title'];
description?: DialogProps['description'];
variant?: ConfirmProps['variant'];
confirmText?: ConfirmProps['confirmText'];
}
} & Pick<DialogProps, 'title' | 'description'> &
Pick<ConfirmProps, 'variant' | 'confirmText'>;
export async function showConfirm({ id, title, description, variant, confirmText }: ConfirmArgs) {
return new Promise((onResult: ConfirmProps['onResult']) => {
@@ -19,6 +16,7 @@ export async function showConfirm({ id, title, description, variant, confirmText
description,
hideX: true,
size: 'sm',
disableBackdropClose: true, // Prevent accidental dismisses
render: ({ hide }) => Confirm({ onHide: hide, variant, onResult, confirmText }),
});
});

View File

@@ -14,6 +14,7 @@ export async function showPrompt({ id, title, description, ...props }: PromptArg
description,
hideX: true,
size: 'sm',
disableBackdropClose: true, // Prevent accidental dismisses
onClose: () => {
// Click backdrop, close, or escape
resolve(null);

View File

@@ -37,6 +37,7 @@ type TauriCmd =
| 'cmd_get_key_value'
| 'cmd_get_settings'
| 'cmd_get_workspace'
| 'cmd_get_workspace_meta'
| 'cmd_grpc_go'
| 'cmd_grpc_reflect'
| 'cmd_http_request_actions'
@@ -75,6 +76,7 @@ type TauriCmd =
| 'cmd_update_http_request'
| 'cmd_update_settings'
| 'cmd_update_workspace'
| 'cmd_update_workspace_meta'
| 'cmd_write_file_dev';
export async function invokeCmd<T>(cmd: TauriCmd, args?: InvokeArgs): Promise<T> {