diff --git a/src/components/gui/tabs/table-data-tab.tsx b/src/components/gui/tabs/table-data-tab.tsx index 1569f8c..9ab0a70 100644 --- a/src/components/gui/tabs/table-data-tab.tsx +++ b/src/components/gui/tabs/table-data-tab.tsx @@ -6,7 +6,6 @@ import { LucideArrowRight, LucideDelete, LucideFilter, - LucideLoader, LucidePlus, LucideRefreshCcw, LucideSaveAll, @@ -38,6 +37,9 @@ import ResultStats from "../result-stat"; import isEmptyResultStats from "@/components/lib/empty-stats"; import useTableResultColumnFilter from "../table-result/filter-column"; import { AlertDialogTitle } from "@radix-ui/react-alert-dialog"; +import { useCurrentTab } from "../windows-tab"; +import { KEY_BINDING } from "@/lib/key-matcher"; +import { Toolbar, ToolbarButton } from "../toolbar"; interface TableDataContentProps { tableName: string; @@ -169,6 +171,28 @@ export default function TableDataWindow({ } }, [data]); + const { isActiveTab } = useCurrentTab(); + + useEffect(() => { + if (isActiveTab) { + const handleGlobalKeyBinding = (e: KeyboardEvent) => { + if (KEY_BINDING.commit.match(e)) { + onCommit(); + e.preventDefault(); + e.stopPropagation(); + } else if (KEY_BINDING.discard.match(e)) { + onDiscard(); + e.preventDefault(); + e.stopPropagation(); + } + }; + + document.addEventListener("keydown", handleGlobalKeyBinding); + return () => + document.removeEventListener("keydown", handleGlobalKeyBinding); + } + }, [isActiveTab, onCommit, onDiscard]); + return (
{executeError && ( @@ -185,37 +209,24 @@ export default function TableDataWindow({ )}
-
- + badge={changeNumber ? changeNumber.toString() : ""} + /> - + />
@@ -337,7 +348,7 @@ export default function TableDataWindow({ }} /> -
+
diff --git a/src/components/gui/toolbar.tsx b/src/components/gui/toolbar.tsx new file mode 100644 index 0000000..0c01049 --- /dev/null +++ b/src/components/gui/toolbar.tsx @@ -0,0 +1,58 @@ +import { PropsWithChildren, ReactElement } from "react"; +import { Button } from "../ui/button"; +import { LucideLoader } from "lucide-react"; +import { Tooltip, TooltipContent, TooltipTrigger } from "../ui/tooltip"; + +export function Toolbar({ children }: PropsWithChildren) { + return
{children}
; +} + +export function ToolbarButton({ + disabled, + loading, + icon, + onClick, + badge, + text, + tooltip, + destructive, +}: { + icon?: ReactElement; + disabled?: boolean; + loading?: boolean; + badge?: string; + text: string; + onClick?: () => void; + tooltip?: ReactElement | string; + destructive?: boolean; +}) { + const buttonContent = ( + + ); + + if (tooltip) { + return ( + + {buttonContent} + {tooltip} + + ); + } + + return buttonContent; +} diff --git a/src/components/gui/windows-tab.tsx b/src/components/gui/windows-tab.tsx index 8dfe558..d27586a 100644 --- a/src/components/gui/windows-tab.tsx +++ b/src/components/gui/windows-tab.tsx @@ -53,10 +53,18 @@ const WindowTabsContext = createContext<{ }, }); +const CurrentWindowTab = createContext<{ isActiveTab: boolean }>({ + isActiveTab: false, +}); + export function useTabsContext() { return useContext(WindowTabsContext); } +export function useCurrentTab() { + return useContext(CurrentWindowTab); +} + export default function WindowTabs({ menu, tabs, @@ -200,15 +208,19 @@ export default function WindowTabs({
{tabs.map((tab, tabIndex) => ( -
- {tab.component} -
+
+ {tab.component} +
+ ))}
diff --git a/src/lib/key-matcher.ts b/src/lib/key-matcher.ts index bebdf8a..c511f2e 100644 --- a/src/lib/key-matcher.ts +++ b/src/lib/key-matcher.ts @@ -77,4 +77,6 @@ export const KEY_BINDING = { copy: new KeyMatcher({ ctrl: true, key: "c" }), paste: new KeyMatcher({ ctrl: true, key: "v" }), format: new KeyMatcher({ ctrl: true, shift: true, key: "i" }), + commit: new KeyMatcher({ ctrl: true, key: "s" }), + discard: new KeyMatcher({ ctrl: true, shift: true, key: "Delete" }), };