-
-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from maidh91/refactor-commands-tauri
Refactor: Move all @tauri-apps calls to src/commands
- Loading branch information
Showing
9 changed files
with
107 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Notes | ||
|
||
- This `src/commands` directory contains all actions to communicate with Tauri via `@tauti-apps` | ||
library, e.g. invoke, listen, open | ||
|
||
- All other directories under `src` are native React code only |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { open } from '@tauri-apps/api/dialog'; | ||
|
||
// openCsvFile | ||
export const openCsvFileDialog = async (): Promise<null | string | string[]> => { | ||
try { | ||
return open({ filters: [{ name: 'CSV', extensions: ['csv'] }] }); | ||
} catch (error) { | ||
console.error('Error open csv file', error); | ||
throw error; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { listen, EventCallback, UnlistenFn } from '@tauri-apps/api/event'; | ||
|
||
// listenImportFileDropHover | ||
export const listenImportFileDropHover = async <T>(handler: EventCallback<T>): Promise<UnlistenFn> => { | ||
try { | ||
return listen<T>('tauri://file-drop-hover', handler); | ||
} catch (error) { | ||
console.error('Error listen tauri://file-drop-hover:', error); | ||
throw error; | ||
} | ||
}; | ||
|
||
// listenImportFileDrop | ||
export const listenImportFileDrop = async <T>(handler: EventCallback<T>): Promise<UnlistenFn> => { | ||
try { | ||
return listen<T>('tauri://file-drop', handler); | ||
} catch (error) { | ||
console.error('Error listen tauri://file-drop:', error); | ||
throw error; | ||
} | ||
}; | ||
|
||
// listenImportFileDropCancelled | ||
export const listenImportFileDropCancelled = async <T>(handler: EventCallback<T>): Promise<UnlistenFn> => { | ||
try { | ||
return listen<T>('tauri://file-drop-cancelled', handler); | ||
} catch (error) { | ||
console.error('Error listen tauri://file-drop-cancelled:', error); | ||
throw error; | ||
} | ||
}; | ||
|
||
export type { UnlistenFn }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { listen, EventCallback, UnlistenFn } from '@tauri-apps/api/event'; | ||
|
||
// listenQuotesSyncStart | ||
export const listenQuotesSyncStart = async <T>(handler: EventCallback<T>): Promise<UnlistenFn> => { | ||
try { | ||
return listen<T>('QUOTES_SYNC_START', handler); | ||
} catch (error) { | ||
console.error('Error listen QUOTES_SYNC_START:', error); | ||
throw error; | ||
} | ||
}; | ||
|
||
// listenQuotesSyncComplete | ||
export const listenQuotesSyncComplete = async <T>(handler: EventCallback<T>): Promise<UnlistenFn> => { | ||
try { | ||
return listen<T>('QUOTES_SYNC_COMPLETE', handler); | ||
} catch (error) { | ||
console.error('Error listen QUOTES_SYNC_COMPLETE:', error); | ||
throw error; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { invoke } from '@tauri-apps/api'; | ||
import { Settings } from '@/lib/types'; | ||
|
||
// getSettings | ||
export const getSettings = async (): Promise<Settings> => { | ||
try { | ||
const settings = await invoke('get_settings'); | ||
return settings as Settings; | ||
} catch (error) { | ||
console.error('Error fetching settings:', error); | ||
return {} as Settings; | ||
} | ||
}; | ||
|
||
// saveSettings | ||
export const saveSettings = async (settings: Settings): Promise<Settings> => { | ||
try { | ||
const updatedSettings = await invoke('update_settings', { settings }); | ||
return updatedSettings as Settings; | ||
} catch (error) { | ||
console.error('Error updating settings:', error); | ||
throw error; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,10 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { Settings } from './types'; | ||
import { invoke } from '@tauri-apps/api'; | ||
import { getSettings } from '@/commands/setting'; | ||
|
||
export function useSettings() { | ||
return useQuery<Settings, Error>({ | ||
queryKey: ['settings'], | ||
queryFn: getSettings, | ||
}); | ||
} | ||
|
||
export const getSettings = async (): Promise<Settings> => { | ||
try { | ||
const settings = await invoke('get_settings'); | ||
return settings as Settings; | ||
} catch (error) { | ||
console.error('Error fetching settings:', error); | ||
return {} as Settings; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters