@@ -15,17 +15,20 @@ import {
1515export default function DropdownMenuDemo ( { children } : { children : React . ReactNode } ) {
1616 const [ loading , setLoading ] = useState ( false ) ;
1717
18- // ---- detect platform เพื่อโชว์ปุ่มให้ตรง OS ----
18+ // ---- Detect platform เพื่อโชว์ปุ่มให้ตรง OS ----
1919 const isMac = typeof navigator !== "undefined"
2020 ? / M a c | i P h o n e | i P a d | i P o d / . test ( navigator . platform || "" ) ||
2121 / M a c O S / . test ( navigator . userAgent || "" )
2222 : false ;
23- const shortcutLabel = isMac ? "⌘B" : "Ctrl+B" ;
2423
25- function handleAccount ( ) {
24+ const shortcutSettings = isMac ? "⌘E" : "Ctrl+E" ;
25+ const shortcutHelp = isMac ? "⌘H" : "Ctrl+H" ;
26+ const shortcutLogout = isMac ? "⇧⌘Q" : "Ctrl+Shift+Q" ;
27+
28+ function handleSettings ( ) {
2629 window . location . href = "/settings" ;
2730 }
28- function handleSetting ( ) { }
31+
2932 async function handleLogout ( ) {
3033 if ( loading ) return ;
3134 setLoading ( true ) ;
@@ -39,7 +42,8 @@ export default function DropdownMenuDemo({ children }: { children: React.ReactNo
3942 }
4043 }
4144
42- // ---- คีย์ลัด: ⌘B (Mac) / Ctrl+B (Win/Linux) ----
45+ // ---- คีย์ลัด: ⌘B (Mac) / Ctrl+B → เปิด Settings ----
46+ // ---- คีย์ลัด: ⇧⌘Q (Mac) / Ctrl+Shift+Q → Logout ----
4347 useEffect ( ( ) => {
4448 const isEditable = ( el : EventTarget | null ) => {
4549 if ( ! ( el instanceof HTMLElement ) ) return false ;
@@ -53,41 +57,49 @@ export default function DropdownMenuDemo({ children }: { children: React.ReactNo
5357 } ;
5458
5559 const onKeyDown = ( e : KeyboardEvent ) => {
56- // ข้ามถ้ากำลังพิมพ์ในช่องข้อความ
5760 if ( isEditable ( e . target ) ) return ;
5861
5962 const key = e . key . toLowerCase ( ) ;
6063 const metaOrCtrl = isMac ? e . metaKey : e . ctrlKey ;
6164
62- if ( metaOrCtrl && key === "b" ) {
65+ // เปิดหน้า Settings (Settings)
66+ if ( metaOrCtrl && ! e . shiftKey && key === "e" ) {
67+ e . preventDefault ( ) ;
68+ handleSettings ( ) ;
69+ }
70+
71+ // Logout
72+ if ( metaOrCtrl && e . shiftKey && key === "q" ) {
6373 e . preventDefault ( ) ;
64- handleAccount ( ) ;
74+ handleLogout ( ) ;
6575 }
6676 } ;
6777
6878 window . addEventListener ( "keydown" , onKeyDown ) ;
6979 return ( ) => window . removeEventListener ( "keydown" , onKeyDown ) ;
70- } , [ isMac ] ) ;
80+ } , [ isMac , loading ] ) ;
7181
7282 return (
7383 < DropdownMenu >
7484 < DropdownMenuTrigger asChild > { children } </ DropdownMenuTrigger >
7585 < DropdownMenuContent className = "w-56" align = "end" sideOffset = { 8 } >
76- < DropdownMenuLabel > My Account </ DropdownMenuLabel >
86+ < DropdownMenuLabel > Menu </ DropdownMenuLabel >
7787 < DropdownMenuGroup >
78- < DropdownMenuItem onClick = { handleAccount } >
79- Account
80- < DropdownMenuShortcut > { shortcutLabel } </ DropdownMenuShortcut >
81- </ DropdownMenuItem >
82- < DropdownMenuItem onClick = { handleSetting } disabled >
88+ < DropdownMenuItem onClick = { handleSettings } >
8389 Settings
84- { /* <DropdownMenuShortcut>{isMac ? "⌘S" : "Ctrl+S"}</DropdownMenuShortcut> */ }
90+ < DropdownMenuShortcut > { shortcutSettings } </ DropdownMenuShortcut >
91+ </ DropdownMenuItem >
92+ </ DropdownMenuGroup >
93+ < DropdownMenuGroup >
94+ < DropdownMenuItem disabled >
95+ Help
96+ < DropdownMenuShortcut > { shortcutHelp } </ DropdownMenuShortcut >
8597 </ DropdownMenuItem >
8698 </ DropdownMenuGroup >
8799 < DropdownMenuSeparator />
88100 < DropdownMenuItem onClick = { handleLogout } >
89101 Log out
90- { /* <DropdownMenuShortcut>{isMac ? "⇧⌘Q" : "Ctrl+Shift+Q" }</DropdownMenuShortcut> */ }
102+ < DropdownMenuShortcut > { shortcutLogout } </ DropdownMenuShortcut >
91103 </ DropdownMenuItem >
92104 </ DropdownMenuContent >
93105 </ DropdownMenu >
0 commit comments