| 1 | "use client"; |
| 2 | |
| 3 | import { Button } from "@/components/ui/button"; |
| 4 | import { |
| 5 | Dialog, |
| 6 | DialogContent, |
| 7 | DialogDescription, |
| 8 | DialogHeader, |
| 9 | DialogTitle, |
| 10 | } from "@/components/ui/dialog"; |
| 11 | import { |
| 12 | DropdownMenu, |
| 13 | DropdownMenuContent, |
| 14 | DropdownMenuItem, |
| 15 | DropdownMenuSeparator, |
| 16 | DropdownMenuTrigger, |
| 17 | } from "@/components/ui/dropdown-menu"; |
| 18 | import { useIsMobile } from "@/hooks/use-mobile"; |
| 19 | import { ExternalLink, Keyboard } from "lucide-react"; |
| 20 | import { useState } from "react"; |
| 21 | |
| 22 | interface HelpMenuProps { |
| 23 | hideKeyboardShortcutsOnMobile?: boolean; |
| 24 | } |
| 25 | |
| 26 | export function HelpMenu({ |
| 27 | hideKeyboardShortcutsOnMobile = false, |
| 28 | }: HelpMenuProps = {}) { |
| 29 | const [keyboardShortcutsOpen, setKeyboardShortcutsOpen] = useState(false); |
| 30 | const isMobile = useIsMobile(); |
| 31 | const shouldShowKeyboardShortcuts = |
| 32 | !hideKeyboardShortcutsOnMobile || !isMobile; |
| 33 | |
| 34 | return ( |
| 35 | <> |
| 36 | <DropdownMenu> |
| 37 | <DropdownMenuTrigger asChild> |
| 38 | <Button |
| 39 | variant="outline" |
| 40 | size="icon" |
| 41 | className="size-9 rounded-full bg-transparent text-sm" |
| 42 | > |
| 43 | ?<span className="sr-only">Open help menu</span> |
| 44 | </Button> |
| 45 | </DropdownMenuTrigger> |
| 46 | <DropdownMenuContent align="end" className="w-56"> |
| 47 | {shouldShowKeyboardShortcuts ? ( |
| 48 | <DropdownMenuItem onClick={() => setKeyboardShortcutsOpen(true)}> |
| 49 | <Keyboard className="mr-3 h-5 w-5" /> |
| 50 | <span>Keyboard shortcuts</span> |
| 51 | </DropdownMenuItem> |
| 52 | ) : null} |
| 53 | |
| 54 | <DropdownMenuItem asChild> |
| 55 | <a |
| 56 | href="https://www.allweone.com/" |
| 57 | target="_blank" |
| 58 | rel="noopener noreferrer" |
| 59 | className="flex items-center" |
| 60 | > |
| 61 | <ExternalLink className="mr-3 h-5 w-5" /> |
| 62 | <span>Visit allweone.com</span> |
| 63 | </a> |
| 64 | </DropdownMenuItem> |
| 65 | |
| 66 | <DropdownMenuSeparator /> |
| 67 | |
| 68 | <div className="px-2 py-2 text-xs text-muted-foreground"> |
| 69 | ALLWEONE Presentation |
| 70 | </div> |
| 71 | </DropdownMenuContent> |
| 72 | </DropdownMenu> |
| 73 | |
| 74 | {shouldShowKeyboardShortcuts ? ( |
| 75 | <Dialog |
| 76 | open={keyboardShortcutsOpen} |
| 77 | onOpenChange={setKeyboardShortcutsOpen} |
| 78 | > |
| 79 | <DialogContent className="max-w-md"> |
| 80 | <DialogHeader> |
| 81 | <DialogTitle>Keyboard shortcuts</DialogTitle> |
| 82 | <DialogDescription> |
| 83 | Quick access to common actions |
| 84 | </DialogDescription> |
| 85 | </DialogHeader> |
| 86 | <div className="space-y-4 py-4"> |
| 87 | <div className="flex items-center justify-between"> |
| 88 | <span className="text-sm">Open help menu</span> |
| 89 | <kbd className="rounded bg-muted px-2 py-1.5 text-xs font-semibold"> |
| 90 | ? |
| 91 | </kbd> |
| 92 | </div> |
| 93 | <div className="flex items-center justify-between"> |
| 94 | <span className="text-sm">Search</span> |
| 95 | <kbd className="rounded bg-muted px-2 py-1.5 text-xs font-semibold"> |
| 96 | Ctrl + K |
| 97 | </kbd> |
| 98 | </div> |
| 99 | <div className="flex items-center justify-between"> |
| 100 | <span className="text-sm">Save</span> |
| 101 | <kbd className="rounded bg-muted px-2 py-1.5 text-xs font-semibold"> |
| 102 | Ctrl + S |
| 103 | </kbd> |
| 104 | </div> |
| 105 | </div> |
| 106 | </DialogContent> |
| 107 | </Dialog> |
| 108 | ) : null} |
| 109 | </> |
| 110 | ); |
| 111 | } |
| 112 |