@@ -11,7 +11,7 @@ import {
1111import { deleteCookie , getCookie } from "cookies-next" ;
1212import Link from "next/link" ;
1313import { useRouter } from "next/router" ;
14- import { Fragment , useCallback , useEffect , useState } from "react" ;
14+ import { Fragment , useEffect , useState } from "react" ;
1515
1616import { ContextMenu } from "@radix-ui/themes" ;
1717import useTranslation from "next-translate/useTranslation" ;
@@ -33,6 +33,7 @@ export default function NewLayout({ children }: any) {
3333
3434 const [ sidebarOpen , setSidebarOpen ] = useState ( false ) ;
3535 const [ tab , setTab ] = useState ( "unread" ) ;
36+ const [ currentPath , setCurrentPath ] = useState ( ) ;
3637
3738 if ( ! user ) {
3839 location . push ( "/auth/login" ) ;
@@ -120,12 +121,49 @@ export default function NewLayout({ children }: any) {
120121 // location.push(`${locale}/${location.pathname}`);
121122 // }, [user, location]);
122123
123- const handleKeyPress = useCallback ( ( event : any ) => {
124+ // const handleKeyPress = useCallback((event: any, location: any) => {
125+ // console.log(location);
126+ // if (
127+ // document.activeElement!.tagName !== "INPUT" &&
128+ // document.activeElement!.tagName !== "TEXTAREA" &&
129+ // !document.activeElement!.className.includes("ProseMirror")
130+ // ) {
131+ // switch (event.key) {
132+ // case "c":
133+ // location.push("/new");
134+ // break;
135+ // case "h":
136+ // location.push("/");
137+ // break;
138+ // case "n":
139+ // location.push("/notebook");
140+ // break;
141+ // case "t":
142+ // location.push("/tickets");
143+ // break;
144+ // case "a":
145+ // location.push("/admin");
146+ // break;
147+ // case "o":
148+ // location.push("/tickets/open");
149+ // break;
150+ // case "f":
151+ // location.push("/tickets/closed");
152+ // break;
153+ // default:
154+ // break;
155+ // }
156+ // }
157+ // }, []);
158+
159+ function handleKeyPress ( event : any ) {
160+ const pathname = location . pathname ;
161+ console . log ( pathname ) ;
124162 if (
125163 document . activeElement ! . tagName !== "INPUT" &&
126164 document . activeElement ! . tagName !== "TEXTAREA" &&
127165 ! document . activeElement ! . className . includes ( "ProseMirror" ) &&
128- location . pathname !== "/new"
166+ ! pathname . includes ( "/new" )
129167 ) {
130168 switch ( event . key ) {
131169 case "c" :
@@ -149,12 +187,11 @@ export default function NewLayout({ children }: any) {
149187 case "f" :
150188 location . push ( "/tickets/closed" ) ;
151189 break ;
190+ default :
191+ break ;
152192 }
153- } else {
154- console ;
155- return null ;
156193 }
157- } , [ ] ) ;
194+ }
158195
159196 useEffect ( ( ) => {
160197 // attach the event listener
@@ -164,7 +201,7 @@ export default function NewLayout({ children }: any) {
164201 return ( ) => {
165202 document . removeEventListener ( "keydown" , handleKeyPress ) ;
166203 } ;
167- } , [ handleKeyPress ] ) ;
204+ } , [ handleKeyPress , location ] ) ;
168205
169206 return (
170207 ! loading && (
0 commit comments