From 9c88ed3cf6dfbab1d32ee08842a5d440696965ed Mon Sep 17 00:00:00 2001 From: igorrCarvalho Date: Sat, 8 Jun 2024 17:24:16 -0300 Subject: [PATCH] Refactor: retrieve shortcuts data directly in the store --- .../pages/ShortcutsPage/EditShortcutButton/index.tsx | 3 +++ .../pages/SettingsPage/pages/ShortcutsPage/index.tsx | 7 ------- src/frontend/src/stores/shortcuts.ts | 12 ++++++++++++ src/frontend/src/types/store/index.ts | 1 + 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/frontend/src/pages/SettingsPage/pages/ShortcutsPage/EditShortcutButton/index.tsx b/src/frontend/src/pages/SettingsPage/pages/ShortcutsPage/EditShortcutButton/index.tsx index 3d01b4ac0..a446336c1 100644 --- a/src/frontend/src/pages/SettingsPage/pages/ShortcutsPage/EditShortcutButton/index.tsx +++ b/src/frontend/src/pages/SettingsPage/pages/ShortcutsPage/EditShortcutButton/index.tsx @@ -31,6 +31,8 @@ export default function EditShortcutButton({ const unavaliableShortcuts = useShortcutsStore( (state) => state.unavailableShortcuts, ); + const a = useShortcutsStore((state) => state.advanced); + console.log(a); const setErrorData = useAlertStore((state) => state.setErrorData); function canEditCombination(newCombination: string): boolean { @@ -69,6 +71,7 @@ export default function EditShortcutButton({ fixCombination[0] = "mod"; } const shortcutName = shortcut[0].split(" ")[0].toLowerCase(); + console.log(shortcutName); setUniqueShortcut(shortcutName, fixCombination.join("").toLowerCase()); console.log(newCombination); setShortcuts(newCombination, unavailable); diff --git a/src/frontend/src/pages/SettingsPage/pages/ShortcutsPage/index.tsx b/src/frontend/src/pages/SettingsPage/pages/ShortcutsPage/index.tsx index 1b68c0517..e79d59c1e 100644 --- a/src/frontend/src/pages/SettingsPage/pages/ShortcutsPage/index.tsx +++ b/src/frontend/src/pages/SettingsPage/pages/ShortcutsPage/index.tsx @@ -45,13 +45,6 @@ export default function ShortcutsPage() { const combinationToEdit = shortcuts.filter((s) => s.name === selectedRows[0]); const [open, setOpen] = useState(false); - useEffect(() => { - if (localStorage.getItem("langflow-shortcuts")) { - const savedShortcuts = localStorage.getItem("langflow-shortcuts"); - const savedUShortcuts = localStorage.getItem("langflow-UShortcuts"); - setShortcuts(JSON.parse(savedShortcuts!), JSON.parse(savedUShortcuts!)); - } - }, []); function handleRestore() { setShortcuts(defaultShortcuts, unavailableShortcutss); diff --git a/src/frontend/src/stores/shortcuts.ts b/src/frontend/src/stores/shortcuts.ts index 2c2391417..37e8ca3ea 100644 --- a/src/frontend/src/stores/shortcuts.ts +++ b/src/frontend/src/stores/shortcuts.ts @@ -34,4 +34,16 @@ export const useShortcutsStore = create((set, get) => ({ [name]: combination, }); }, + getShortcutsFromStorage: () => { + if (localStorage.getItem("langflow-shortcuts")) { + const savedShortcuts = localStorage.getItem("langflow-shortcuts"); + const savedUShortcuts = localStorage.getItem("langflow-UShortcuts"); + get().setShortcuts( + JSON.parse(savedShortcuts!), + JSON.parse(savedUShortcuts!), + ); + } + }, })); + +useShortcutsStore.getState().getShortcutsFromStorage(); diff --git a/src/frontend/src/types/store/index.ts b/src/frontend/src/types/store/index.ts index 5cf866db7..abe3e64be 100644 --- a/src/frontend/src/types/store/index.ts +++ b/src/frontend/src/types/store/index.ts @@ -48,4 +48,5 @@ export type shortcutsStoreType = { newShortcuts: Array<{ name: string; shortcut: string }>, unavailable: string[], ) => void; + getShortcutsFromStorage: () => void; };