From c767c1c3a631d923b00e1e0ae288b18244a0bb90 Mon Sep 17 00:00:00 2001 From: Frank Noirot Date: Tue, 19 Sep 2023 18:07:54 -0400 Subject: [PATCH] Replace `setCode` with `deferredSetCode` in App (#649) * Replace `setCode` with `deferredSetCode` in App * Remove unused OpenFileButton component --- src/App.tsx | 10 ++++---- src/components/OpenFileButton.tsx | 42 ------------------------------- 2 files changed, 5 insertions(+), 47 deletions(-) delete mode 100644 src/components/OpenFileButton.tsx diff --git a/src/App.tsx b/src/App.tsx index 9376d1f43..4ba4ffead 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -38,7 +38,7 @@ export function App() { const streamRef = useRef(null) useHotKeyListener() const { - setCode, + deferredSetCode, engineCommandManager, buttonDownInStream, openPanes, @@ -51,7 +51,7 @@ export function App() { } = useStore((s) => ({ guiMode: s.guiMode, setGuiMode: s.setGuiMode, - setCode: s.setCode, + deferredSetCode: s.deferredSetCode, engineCommandManager: s.engineCommandManager, buttonDownInStream: s.buttonDownInStream, openPanes: s.openPanes, @@ -142,15 +142,15 @@ export function App() { // on mount, and overwrite any locally-stored code useEffect(() => { if (isTauri() && loadedCode !== null) { - setCode(loadedCode) + deferredSetCode(loadedCode) } return () => { // Clear code on unmount if in desktop app if (isTauri()) { - setCode('') + deferredSetCode('') } } - }, [loadedCode, setCode]) + }, [loadedCode, deferredSetCode]) useSetupEngineManager(streamRef, token) useEngineConnectionSubscriptions() diff --git a/src/components/OpenFileButton.tsx b/src/components/OpenFileButton.tsx deleted file mode 100644 index 137d51182..000000000 --- a/src/components/OpenFileButton.tsx +++ /dev/null @@ -1,42 +0,0 @@ -import { invoke } from '@tauri-apps/api/tauri' -import { open } from '@tauri-apps/api/dialog' -import { useStore } from '../useStore' - -export const OpenFileButton = () => { - const { setCode } = useStore((s) => ({ - setCode: s.setCode, - })) - const handleClick = async () => { - const selected = await open({ - multiple: false, - directory: false, - filters: [ - { - name: 'CAD', - extensions: ['toml'], - }, - ], - }) - if (Array.isArray(selected)) { - // User selected multiple files - // We should not get here, since multiple is false. - } else if (selected === null) { - // User cancelled the selection - // Do nothing. - } else { - // User selected a single file - // We want to invoke our command to read the file. - const json: string = await invoke('read_toml', { path: selected }) - const packageDetails = JSON.parse(json).package - if (packageDetails.main) { - const absPath = [ - ...selected.split('/').slice(0, -1), - packageDetails.main, - ].join('/') - const file: string = await invoke('read_txt_file', { path: absPath }) - setCode(file) - } - } - } - return -}