fix: make getting started clone destination explicit

This commit is contained in:
lucaronin
2026-04-15 14:55:56 +02:00
parent e142b4c8f9
commit 7eaf57d040
12 changed files with 370 additions and 213 deletions

View File

@@ -0,0 +1,37 @@
import { useCallback } from 'react'
import { invoke } from '@tauri-apps/api/core'
import { isTauri, mockInvoke } from '../mock-tauri'
import { pickFolder } from '../utils/vault-dialog'
import {
buildGettingStartedVaultPath,
formatGettingStartedCloneError,
labelFromPath,
} from '../utils/gettingStartedVault'
interface UseGettingStartedCloneOptions {
onError: (message: string) => void
onSuccess: (path: string, label: string) => void
}
function tauriCall<T>(command: string, args: Record<string, unknown>): Promise<T> {
return isTauri() ? invoke<T>(command, args) : mockInvoke<T>(command, args)
}
export function useGettingStartedClone({
onError,
onSuccess,
}: UseGettingStartedCloneOptions) {
return useCallback(async () => {
const parentPath = await pickFolder('Choose a parent folder for the Getting Started vault')
if (!parentPath) return
const targetPath = buildGettingStartedVaultPath(parentPath)
try {
const vaultPath = await tauriCall<string>('create_getting_started_vault', { targetPath })
onSuccess(vaultPath, labelFromPath(vaultPath))
} catch (err) {
onError(formatGettingStartedCloneError(err))
}
}, [onError, onSuccess])
}