mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-18 23:44:12 +01:00
Move error alert to hook
This commit is contained in:
@@ -3,6 +3,7 @@ import { invoke } from '@tauri-apps/api';
|
||||
import type { SaveDialogOptions } from '@tauri-apps/api/dialog';
|
||||
import { save } from '@tauri-apps/api/dialog';
|
||||
import { useActiveWorkspaceId } from './useActiveWorkspaceId';
|
||||
import { useAlert } from './useAlert';
|
||||
|
||||
const saveArgs: SaveDialogOptions = {
|
||||
title: 'Export Data',
|
||||
@@ -11,8 +12,12 @@ const saveArgs: SaveDialogOptions = {
|
||||
|
||||
export function useExportData() {
|
||||
const workspaceId = useActiveWorkspaceId();
|
||||
const alert = useAlert();
|
||||
|
||||
return useMutation({
|
||||
onError: (err: string) => {
|
||||
alert({ title: 'Export Failed', body: err });
|
||||
},
|
||||
mutationFn: async () => {
|
||||
const exportPath = await save(saveArgs);
|
||||
if (exportPath == null) {
|
||||
|
||||
@@ -7,6 +7,7 @@ import { VStack } from '../components/core/Stacks';
|
||||
import { useDialog } from '../components/DialogContext';
|
||||
import type { Environment, Folder, HttpRequest, Workspace } from '../lib/models';
|
||||
import { count } from '../lib/pluralize';
|
||||
import { useAlert } from './useAlert';
|
||||
import { useAppRoutes } from './useAppRoutes';
|
||||
|
||||
const openArgs: OpenDialogOptions = {
|
||||
@@ -17,8 +18,12 @@ const openArgs: OpenDialogOptions = {
|
||||
export function useImportData() {
|
||||
const routes = useAppRoutes();
|
||||
const dialog = useDialog();
|
||||
const alert = useAlert();
|
||||
|
||||
return useMutation({
|
||||
onError: (err: string) => {
|
||||
alert({ title: 'Import Failed', body: err });
|
||||
},
|
||||
mutationFn: async () => {
|
||||
const selected = await open(openArgs);
|
||||
if (selected == null || selected.length === 0) {
|
||||
|
||||
Reference in New Issue
Block a user