From 5cebb4e61ab1e92e11eb7c23001df06f62dd751e Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Thu, 9 Nov 2023 17:03:29 -0800 Subject: [PATCH] Better Yaak export --- src-tauri/Cargo.toml | 1 + src-tauri/tauri.conf.json | 3 ++- .../components/WorkspaceActionsDropdown.tsx | 12 ++++++------ src-web/hooks/useExportData.tsx | 18 ++++++------------ 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 8daa2923..39daea15 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -41,6 +41,7 @@ tauri = { version = "1.3", features = [ "updater", "window-start-dragging", "dialog-open", + "dialog-save", ] } tauri-plugin-window-state = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" } tauri-plugin-log = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" } diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 45b52982..6ba2bf2b 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -56,7 +56,8 @@ }, "dialog": { "all": false, - "open": true + "open": true, + "save": true } }, "bundle": { diff --git a/src-web/components/WorkspaceActionsDropdown.tsx b/src-web/components/WorkspaceActionsDropdown.tsx index 1140605f..fd3cb266 100644 --- a/src-web/components/WorkspaceActionsDropdown.tsx +++ b/src-web/components/WorkspaceActionsDropdown.tsx @@ -151,18 +151,18 @@ export const WorkspaceActionsDropdown = memo(function WorkspaceActionsDropdown({ onSelect: toggleAppearance, leftSlot: , }, - { - key: 'export-data', - label: 'Export Data', - leftSlot: , - onSelect: () => exportData.mutate(), - }, { key: 'import-data', label: 'Import Data', leftSlot: , onSelect: () => importData.mutate(), }, + { + key: 'export-data', + label: 'Export Data', + leftSlot: , + onSelect: () => exportData.mutate(), + }, ]; }, [ activeWorkspace?.name, diff --git a/src-web/hooks/useExportData.tsx b/src-web/hooks/useExportData.tsx index 94be52b8..8ab49494 100644 --- a/src-web/hooks/useExportData.tsx +++ b/src-web/hooks/useExportData.tsx @@ -1,13 +1,12 @@ import { useMutation } from '@tanstack/react-query'; import { invoke } from '@tauri-apps/api'; -import type { OpenDialogOptions } from '@tauri-apps/api/dialog'; -import { open } from '@tauri-apps/api/dialog'; +import type { SaveDialogOptions } from '@tauri-apps/api/dialog'; +import { save } from '@tauri-apps/api/dialog'; import { useActiveWorkspaceId } from './useActiveWorkspaceId'; -const openArgs: OpenDialogOptions = { - directory: true, - multiple: false, - title: 'Select Export Folder', +const saveArgs: SaveDialogOptions = { + title: 'Export Data', + defaultPath: 'yaak-export.json', }; export function useExportData() { @@ -15,12 +14,7 @@ export function useExportData() { return useMutation({ mutationFn: async () => { - const selected = await open(openArgs); - if (selected == null) { - return; - } - - const rootDir = Array.isArray(selected) ? selected[0] : selected; + const rootDir = await save(saveArgs); if (rootDir == null) { return; }