From 6f6b5c67f18a18fd16dc0cabfaf27ef1a88dbbce Mon Sep 17 00:00:00 2001 From: ameer2468 <33054370+ameer2468@users.noreply.github.com> Date: Mon, 18 Sep 2023 23:19:03 +0300 Subject: [PATCH] [ENG-815] Shortcuts page (#1357) shortcuts page --- interface/app/$libraryId/settings/Sidebar.tsx | 6 +- .../settings/client/keybindings.tsx | 188 +++++++++++++++++- 2 files changed, 187 insertions(+), 7 deletions(-) diff --git a/interface/app/$libraryId/settings/Sidebar.tsx b/interface/app/$libraryId/settings/Sidebar.tsx index 261a27a56..b6e814584 100644 --- a/interface/app/$libraryId/settings/Sidebar.tsx +++ b/interface/app/$libraryId/settings/Sidebar.tsx @@ -15,8 +15,8 @@ import { } from '@phosphor-icons/react'; import { useFeatureFlag } from '@sd/client'; import { tw } from '@sd/ui'; - import { useOperatingSystem } from '~/hooks/useOperatingSystem'; + import Icon from '../Layout/Sidebar/Icon'; import SidebarLink from '../Layout/Sidebar/Link'; import { NavigationButtons } from '../TopBar/NavigationButtons'; @@ -39,7 +39,7 @@ export default () => {
)} -
+
Client @@ -62,7 +62,7 @@ export default () => { Backups - + Keybinds diff --git a/interface/app/$libraryId/settings/client/keybindings.tsx b/interface/app/$libraryId/settings/client/keybindings.tsx index f24d673e4..2eca0c5b5 100644 --- a/interface/app/$libraryId/settings/client/keybindings.tsx +++ b/interface/app/$libraryId/settings/client/keybindings.tsx @@ -1,19 +1,99 @@ +import { + createColumnHelper, + flexRender, + getCoreRowModel, + useReactTable +} from '@tanstack/react-table'; +import clsx from 'clsx'; import { useState } from 'react'; -import { Switch } from '@sd/ui'; +import { Divider, ModifierKeys, Switch } from '@sd/ui'; +import { useOperatingSystem } from '~/hooks'; +import { keybindForOs } from '~/util/keybinds'; +import { OperatingSystem } from '~/util/Platform'; import { Heading } from '../Layout'; import Setting from '../Setting'; +type Shortcut = { + action: string; + description?: string; + key: [ModifierKeys[], string[]][]; +}; + +const shortcutCategories: Record = { + Pages: [ + { + description: 'Different pages in the app', + action: 'Navigate to Settings page', + key: [ + [[], ['G']], + [[], ['S']] + ] + } + ], + Dialogs: [ + { + description: 'To perform actions and operations', + action: 'Toggle Job Manager', + key: [[[ModifierKeys.Control], ['J']]] + } + ], + Explorer: [ + { + description: 'Where you explore your folders and files', + action: 'Navigate explorer items', + key: [ + [[], ['ArrowUp']], + [[], ['ArrowDown']], + [[], ['ArrowRight']], + [[], ['ArrowLeft']] + ] + }, + { + action: 'Navigate forward in folder history', + key: [[[ModifierKeys.Control], ['ArrowRight']]] + }, + { + action: 'Navigate backward in folder history', + key: [[[ModifierKeys.Control], ['ArrowLeft']]] + }, + { + action: 'Switch explorer layout', + key: [[[ModifierKeys.Control], ['v']]] + }, + { + action: 'Open selected item', + key: [[[ModifierKeys.Control], ['ArrowUp']]] + }, + { + action: 'Show inspector', + key: [[[ModifierKeys.Control], ['i']]] + }, + { + action: 'Rename file or folder', + key: [[[], ['Enter']]] + }, + { + action: 'Select first item in explorer', + key: [[[], ['ArrowDown']]] + }, + { + action: 'Open Quick Preview on selected item', + key: [[[], [' ']]] + } + ] +}; + export const Component = () => { const [syncWithLibrary, setSyncWithLibrary] = useState(true); + return ( <> - {/* I don't care what you think the "right" way to write "keybinds" is, I simply refuse to refer to it as "keybindings" */} - + {' '} { className="m-2 ml-4" /> + + {Object.entries(shortcutCategories).map(([category, shortcuts]) => { + return ( +
+

{category}

+
+ {shortcutCategories[category]?.map((category) => { + return ( +

+ {category.description} +

+ ); + })} +
+ +
+ ); + })} ); }; + +function KeybindTable({ data }: { data: Shortcut[] }) { + const os = useOperatingSystem(); + const table = useReactTable({ + data, + columns: createKeybindColumns(os), + getCoreRowModel: getCoreRowModel() + }); + + return ( + + + {table.getHeaderGroups().map((headerGroup) => ( + + {headerGroup.headers.map((header) => ( + + ))} + + ))} + + + {table.getRowModel().rows.map((row) => ( + + {row.getVisibleCells().map((cell) => ( + + ))} + + ))} + +
+ {flexRender(header.column.columnDef.header, header.getContext())} +
+ {flexRender(cell.column.columnDef.cell, cell.getContext())} +
+ ); +} + +function createKeybindColumns(os: OperatingSystem) { + const keybind = keybindForOs(os); + const columnHelper = createColumnHelper(); + const columns = [ + columnHelper.accessor('action', { + header: 'Description', + cell: (info) =>

{info.getValue()}

+ }), + columnHelper.accessor('key', { + header: () =>

Key

, + size: 200, + cell: (info) => { + const shortcuts = info + .getValue() + .map(([modifiers, keys]) => keybind(modifiers, keys)); + return shortcuts.map((shortcut, i) => ( +
+ {shortcut.split('').map((key) => { + const controlSymbolCheck = + key === '⌘' ? (os === 'macOS' ? '⌘' : 'Ctrl') : key; + return ( + + {controlSymbolCheck} + + ); + })} +
+ )); + } + }) + ]; + return columns; +}