Refactor: retrieve shortcuts data directly in the store
This commit is contained in:
parent
f2a8e0fda8
commit
9c88ed3cf6
4 changed files with 16 additions and 7 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -34,4 +34,16 @@ export const useShortcutsStore = create<shortcutsStoreType>((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();
|
||||
|
|
|
|||
|
|
@ -48,4 +48,5 @@ export type shortcutsStoreType = {
|
|||
newShortcuts: Array<{ name: string; shortcut: string }>,
|
||||
unavailable: string[],
|
||||
) => void;
|
||||
getShortcutsFromStorage: () => void;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue