Skip to content

Commit c75d425

Browse files
authored
Reactive Search Params (#1564)
1 parent 4559bb7 commit c75d425

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

.changeset/purple-buckets-fly.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"backend": patch
3+
"bot": patch
4+
---
5+
6+
Reactive search params for event page

packages/frontend/src/main.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ ReactDOM.createRoot(document.getElementById("root")!).render(
3838
);
3939

4040
const tauriInit = async () => {
41-
if (!import.meta.env.VITE_TAURI) return;
41+
if (!(window as unknown as any).__TAURI_INTERNALS__) return;
4242
const { attachConsole } = await import("@tauri-apps/plugin-log");
4343

4444
await attachConsole();

packages/frontend/src/pages/_authenticated/events.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@ import {
1818
Typography,
1919
} from "@mui/material";
2020
import { DatePicker } from "@mui/x-date-pickers";
21-
import { createFileRoute } from "@tanstack/react-router";
21+
import { createFileRoute, useLocation, useSearch } from "@tanstack/react-router";
2222
import { EventTypeSchema } from "backend/schema";
2323
import { DateTime } from "luxon";
24+
import { useMemo } from "react";
2425
import { z } from "zod";
2526

26-
const defaultTo = DateTime.now().plus({ month: 1 }).startOf("day").toISO();
27-
const defaultFrom = DateTime.now().startOf("day").toISO();
27+
const defaultToLuxon = DateTime.now().plus({ month: 1 }).startOf("day")
28+
const defaultFromLuxon = DateTime.now().startOf("day")
29+
30+
const defaultTo = defaultToLuxon.toISO();
31+
const defaultFrom = defaultFromLuxon.toISO();
2832

2933
const eventsSearchSchema = z.object({
3034
fromDate: z.string().datetime().default(defaultFrom).optional().catch(defaultFrom),
@@ -46,6 +50,7 @@ export const Route = createFileRoute("/_authenticated/events")({
4650
context: { queryUtils },
4751
deps: { fromDate, toDate, type },
4852
}) => {
53+
console.log("Loading events", fromDate, toDate, type);
4954
const authStatus = await queryUtils.auth.status.ensureData();
5055

5156
const eventsList = await queryUtils.events.getEvents.prefetchInfinite({
@@ -64,12 +69,12 @@ export const Route = createFileRoute("/_authenticated/events")({
6469

6570
function Component() {
6671
const { authStatus, eventsList } = Route.useLoaderData();
67-
const { fromDate, toDate, type } = Route.useSearch();
72+
const { fromDate, toDate, type } = useLocation({ select: (s) => s.search})
6873
const navigate = Route.useNavigate();
6974

7075
const authStatusQuery = trpc.auth.status.useQuery(undefined, {
7176
initialData: authStatus,
72-
});
77+
});
7378

7479
const infiniteEventsQuery = trpc.events.getEvents.useInfiniteQuery(
7580
{
@@ -106,9 +111,6 @@ function Component() {
106111
});
107112
};
108113

109-
const startDateTime = fromDate ? DateTime.fromISO(fromDate) : undefined;
110-
const endDateTime = toDate ? DateTime.fromISO(toDate) : undefined;
111-
112114
return (
113115
<>
114116
<DefaultAppBar title="Events" />
@@ -167,12 +169,12 @@ function Component() {
167169
</Box>
168170
<Box sx={{ display: "flex", justifyContent: "space-between" }}>
169171
<DatePicker
170-
value={startDateTime}
172+
value={DateTime.fromISO(fromDate ?? defaultFrom)}
171173
label="From"
172174
onChange={handleStartChange}
173175
/>
174176
<DatePicker
175-
value={endDateTime}
177+
value={DateTime.fromISO(toDate ?? defaultTo)}
176178
label="To"
177179
onChange={handleEndChange}
178180
/>

0 commit comments

Comments
 (0)