Use global ticket detail entrypoint

This commit is contained in:
michael committed 2026-09-01 11:06:36 +02:00
1 parent b67dbad0b1
commit 018c06dc3e
6 files changed
+94 -25

No files matched your search

+18 -9
View File
@@ -100,6 +100,10 @@ function openTicketsStorageKey(userId: string) {
return `tickettracker.openTickets.${userId}`;
}
function pathWithoutSearch(value: string) {
return value.split("?")[0];
}
function readOpenTickets(userId: string): OpenTicketNavItem[] {
try {
const raw = localStorage.getItem(openTicketsStorageKey(userId));
@@ -126,14 +130,16 @@ function readOpenTickets(userId: string): OpenTicketNavItem[] {
}
}
function routeFromPath(pathname: string) {
function routeFromPath(pathWithSearch: string) {
const [pathname, search = ""] = pathWithSearch.split("?");
const searchParams = new URLSearchParams(search);
const ticketMatch = pathname.match(/^\/tickets\/(\d+)$/);
if (ticketMatch) {
return {
page: "ticket" as const,
periodType: "all" as const,
period: "all",
period: searchParams.get("month") ?? "all",
ticketId: ticketMatch[1],
};
}
@@ -141,10 +147,13 @@ function routeFromPath(pathname: string) {
const periodTicketMatch = pathname.match(/^\/analysis\/(month|day)\/([^/]+)\/tickets\/(\d+)$/);
if (periodTicketMatch) {
const sourcePeriodType = periodTicketMatch[1] as PeriodType;
const sourcePeriod = periodTicketMatch[2];
return {
page: "ticket" as const,
periodType: periodTicketMatch[1] as PeriodType,
period: periodTicketMatch[2],
periodType: "all" as const,
period: sourcePeriodType === "day" ? sourcePeriod.slice(0, 7) : sourcePeriod,
ticketId: periodTicketMatch[3],
};
}
@@ -154,7 +163,7 @@ function routeFromPath(pathname: string) {
if (legacyTicketMatch) {
return {
page: "ticket" as const,
periodType: "month" as const,
periodType: "all" as const,
period: legacyTicketMatch[1],
ticketId: legacyTicketMatch[2],
};
@@ -195,7 +204,7 @@ function useAppRouter() {
const [path, setPath] = useState("/timer");
useEffect(() => {
const update = () => setPath(window.location.pathname);
const update = () => setPath(`${window.location.pathname}${window.location.search}`);
update();
window.addEventListener("popstate", update);
return () => window.removeEventListener("popstate", update);
@@ -203,7 +212,7 @@ function useAppRouter() {
function navigate(to: string) {
window.history.pushState({}, "", to);
setPath(window.location.pathname);
setPath(`${window.location.pathname}${window.location.search}`);
}
function navHandler(to: string) {
@@ -811,7 +820,7 @@ export function App() {
setOpenTickets((items) => items.filter((item) => item.key !== ticket.key));
if (path === ticket.path) {
if (pathWithoutSearch(path) === pathWithoutSearch(ticket.path)) {
navigate("/analysis");
}
}
@@ -958,7 +967,7 @@ export function App() {
<SidebarGroupContent>
<SidebarMenu>
{openTickets.map((ticket) => {
const isActive = path === ticket.path;
const isActive = pathWithoutSearch(path) === pathWithoutSearch(ticket.path);
return (
<SidebarMenuItem key={ticket.key}>