Skip to content

Commit 4090144

Browse files
committed
prevent layout keyboard shortcuts on ticket create
1 parent 88891e5 commit 4090144

File tree

3 files changed

+47
-10
lines changed

3 files changed

+47
-10
lines changed

apps/client/layouts/newLayout.tsx

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
import { deleteCookie, getCookie } from "cookies-next";
1212
import Link from "next/link";
1313
import { useRouter } from "next/router";
14-
import { Fragment, useCallback, useEffect, useState } from "react";
14+
import { Fragment, useEffect, useState } from "react";
1515

1616
import { ContextMenu } from "@radix-ui/themes";
1717
import 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 && (

apps/client/pages/tickets/closed.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export default function Tickets() {
7171

7272
return (
7373
<Link href={`/ticket/${ticket.id}`}>
74-
<div className="flex flex-row w-full bg-white border-b-[1px] p-3 justify-between px-6 hover:bg-gray-100">
74+
<div className="flex flex-row w-full bg-white border-b-[1px] p-2 justify-between px-6 hover:bg-gray-100">
7575
<div>
7676
<span className="text-xs font-semibold">
7777
{ticket.title}

apps/client/pages/tickets/open.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export default function Tickets() {
7070

7171
return (
7272
<Link href={`/ticket/${ticket.id}`}>
73-
<div className="flex flex-row w-full bg-white border-b-[1px] p-3 justify-between px-6 hover:bg-gray-100">
73+
<div className="flex flex-row w-full bg-white border-b-[1px] p-2 justify-between px-6 hover:bg-gray-100">
7474
<div>
7575
<span className="text-xs font-semibold">
7676
{ticket.title}

0 commit comments

Comments
 (0)