diff --git a/apps/mail/app/(routes)/mail/layout.tsx b/apps/mail/app/(routes)/mail/layout.tsx index c760cfb13..128548df7 100644 --- a/apps/mail/app/(routes)/mail/layout.tsx +++ b/apps/mail/app/(routes)/mail/layout.tsx @@ -1,13 +1,12 @@ -import { AppSidebar } from '@/components/ui/app-sidebar'; -import { GlobalHotkeys } from '@/lib/hotkeys/global-hotkeys'; import { HotkeyProviderWrapper } from '@/components/providers/hotkey-provider-wrapper'; +import { GlobalHotkeys } from '@/lib/hotkeys/global-hotkeys'; +import { AppSidebar } from '@/components/ui/app-sidebar'; export default function MailLayout({ children }: { children: React.ReactNode }) { return ( - -
{children}
+
{children}
); } diff --git a/apps/mail/config/shortcuts.ts b/apps/mail/config/shortcuts.ts index 3b26ce7c3..09e947774 100644 --- a/apps/mail/config/shortcuts.ts +++ b/apps/mail/config/shortcuts.ts @@ -10,25 +10,146 @@ export type Shortcut = { }; export const keyboardShortcuts: Shortcut[] = [ - { keys: ["c"], action: "newEmail", type: "single", description: "Compose new email", scope: "global" }, - { keys: ["mod", "Enter"], action: "sendEmail", type: "combination", description: "Send email", scope: "compose" }, - { keys: ["r"], action: "reply", type: "single", description: "Reply to email", scope: "thread-display" }, - { keys: ["a"], action: "replyAll", type: "single", description: "Reply all", scope: "thread-display" }, - { keys: ["f"], action: "forward", type: "single", description: "Forward email", scope: "thread-display" }, - { keys: ["g", "d"], action: "goToDrafts", type: "combination", description: "Go to drafts", scope: "global" }, - { keys: ["g", "i"], action: "inbox", type: "combination", description: "Go to inbox", scope: "global" }, - { keys: ["g", "t"], action: "sentMail", type: "combination", description: "Go to sent mail", scope: "global" }, - { keys: ["#"], action: "delete", type: "single", description: "Delete email", scope: "mail-list" }, - { keys: ["/"], action: "search", type: "single", description: "Search", scope: "global" }, - { keys: ["u"], action: "markAsUnread", type: "single", description: "Mark as unread", scope: "mail-list" }, - { keys: ["m"], action: "muteThread", type: "single", description: "Mute thread", scope: "mail-list" }, - { keys: ["mod", "p"], action: "printEmail", type: "combination", description: "Print email", scope: "thread-display" }, - { keys: ["e"], action: "archiveEmail", type: "single", description: "Archive email", scope: "mail-list" }, - { keys: ["!"], action: "markAsSpam", type: "single", description: "Mark as spam", scope: "mail-list" }, - { keys: ["v"], action: "moveToFolder", type: "single", description: "Move to folder", scope: "mail-list" }, - { keys: ["z"], action: "undoLastAction", type: "single", description: "Undo last action", scope: "global" }, - { keys: ["i"], action: "viewEmailDetails", type: "single", description: "View email details", scope: "thread-display" }, - { keys: ["o"], action: "expandEmailView", type: "single", description: "Expand email view", scope: "mail-list" }, - { keys: ["?"], action: "helpWithShortcuts", type: "single", description: "Show keyboard shortcuts", scope: "global" }, - { keys: ["mod", "a"], action: "selectAll", type: "combination", description: "Select all emails", scope: "mail-list", preventDefault: true }, + { + keys: ['c'], + action: 'newEmail', + type: 'single', + description: 'Compose new email', + scope: 'global', + }, + { + keys: ['mod', 'Enter'], + action: 'sendEmail', + type: 'combination', + description: 'Send email', + scope: 'compose', + }, + { + keys: ['r'], + action: 'reply', + type: 'single', + description: 'Reply to email', + scope: 'thread-display', + }, + { + keys: ['a'], + action: 'replyAll', + type: 'single', + description: 'Reply all', + scope: 'thread-display', + }, + { + keys: ['f'], + action: 'forward', + type: 'single', + description: 'Forward email', + scope: 'thread-display', + }, + { + keys: ['g', 'd'], + action: 'goToDrafts', + type: 'combination', + description: 'Go to drafts', + scope: 'global', + }, + { + keys: ['g', 'i'], + action: 'inbox', + type: 'combination', + description: 'Go to inbox', + scope: 'global', + }, + { + keys: ['g', 't'], + action: 'sentMail', + type: 'combination', + description: 'Go to sent mail', + scope: 'global', + }, + { + keys: ['#'], + action: 'delete', + type: 'single', + description: 'Delete email', + scope: 'mail-list', + }, + { keys: ['/'], action: 'search', type: 'single', description: 'Search', scope: 'global' }, + { + keys: ['u'], + action: 'markAsUnread', + type: 'single', + description: 'Mark as unread', + scope: 'mail-list', + }, + { + keys: ['m'], + action: 'muteThread', + type: 'single', + description: 'Mute thread', + scope: 'mail-list', + }, + { + keys: ['mod', 'p'], + action: 'printEmail', + type: 'combination', + description: 'Print email', + scope: 'thread-display', + }, + { + keys: ['e'], + action: 'archiveEmail', + type: 'single', + description: 'Archive email', + scope: 'mail-list', + }, + { + keys: ['!'], + action: 'markAsSpam', + type: 'single', + description: 'Mark as spam', + scope: 'mail-list', + }, + { + keys: ['v'], + action: 'moveToFolder', + type: 'single', + description: 'Move to folder', + scope: 'mail-list', + }, + { + keys: ['z'], + action: 'undoLastAction', + type: 'single', + description: 'Undo last action', + scope: 'global', + }, + { + keys: ['i'], + action: 'viewEmailDetails', + type: 'single', + description: 'View email details', + scope: 'thread-display', + }, + { + keys: ['o'], + action: 'expandEmailView', + type: 'single', + description: 'Expand email view', + scope: 'mail-list', + }, + { + keys: ['?'], + action: 'helpWithShortcuts', + type: 'single', + description: 'Show keyboard shortcuts', + scope: 'global', + }, + { + keys: ['mod', 'a'], + action: 'selectAll', + type: 'combination', + description: 'Select all emails', + scope: 'mail-list', + preventDefault: true, + }, ]; diff --git a/apps/mail/lib/hotkeys/global-hotkeys.tsx b/apps/mail/lib/hotkeys/global-hotkeys.tsx index a5bb9f15b..d08edec14 100644 --- a/apps/mail/lib/hotkeys/global-hotkeys.tsx +++ b/apps/mail/lib/hotkeys/global-hotkeys.tsx @@ -3,20 +3,24 @@ import { keyboardShortcuts } from '@/config/shortcuts'; import { useShortcuts } from './use-hotkey-utils'; import { useRouter } from 'next/navigation'; +import { useQueryState } from 'nuqs'; export function GlobalHotkeys() { + const [composeOpen, setComposeOpen] = useQueryState('isComposeOpen'); const router = useRouter(); const scope = 'global'; + console.log('i am loaded'); + const handlers = { goToDrafts: () => router.push('/mail/draft'), inbox: () => router.push('/mail/inbox'), sentMail: () => router.push('/mail/sent'), search: () => { - // TODO: Implement search - kinda tricky :/ - console.log('search'); + console.log('well well well'); + document.getElementsByName('q')[0]?.focus(); }, - newEmail: () => router.push('isComposeOpen=true'), + newEmail: () => setComposeOpen('true'), }; const globalShortcuts = keyboardShortcuts.filter((shortcut) => shortcut.scope === scope);