@@ -18,13 +18,17 @@ import {
18
18
Typography ,
19
19
} from "@mui/material" ;
20
20
import { DatePicker } from "@mui/x-date-pickers" ;
21
- import { createFileRoute } from "@tanstack/react-router" ;
21
+ import { createFileRoute , useLocation , useSearch } from "@tanstack/react-router" ;
22
22
import { EventTypeSchema } from "backend/schema" ;
23
23
import { DateTime } from "luxon" ;
24
+ import { useMemo } from "react" ;
24
25
import { z } from "zod" ;
25
26
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 ( ) ;
28
32
29
33
const eventsSearchSchema = z . object ( {
30
34
fromDate : z . string ( ) . datetime ( ) . default ( defaultFrom ) . optional ( ) . catch ( defaultFrom ) ,
@@ -46,6 +50,7 @@ export const Route = createFileRoute("/_authenticated/events")({
46
50
context : { queryUtils } ,
47
51
deps : { fromDate, toDate, type } ,
48
52
} ) => {
53
+ console . log ( "Loading events" , fromDate , toDate , type ) ;
49
54
const authStatus = await queryUtils . auth . status . ensureData ( ) ;
50
55
51
56
const eventsList = await queryUtils . events . getEvents . prefetchInfinite ( {
@@ -64,12 +69,12 @@ export const Route = createFileRoute("/_authenticated/events")({
64
69
65
70
function Component ( ) {
66
71
const { authStatus, eventsList } = Route . useLoaderData ( ) ;
67
- const { fromDate, toDate, type } = Route . useSearch ( ) ;
72
+ const { fromDate, toDate, type } = useLocation ( { select : ( s ) => s . search } )
68
73
const navigate = Route . useNavigate ( ) ;
69
74
70
75
const authStatusQuery = trpc . auth . status . useQuery ( undefined , {
71
76
initialData : authStatus ,
72
- } ) ;
77
+ } ) ;
73
78
74
79
const infiniteEventsQuery = trpc . events . getEvents . useInfiniteQuery (
75
80
{
@@ -106,9 +111,6 @@ function Component() {
106
111
} ) ;
107
112
} ;
108
113
109
- const startDateTime = fromDate ? DateTime . fromISO ( fromDate ) : undefined ;
110
- const endDateTime = toDate ? DateTime . fromISO ( toDate ) : undefined ;
111
-
112
114
return (
113
115
< >
114
116
< DefaultAppBar title = "Events" />
@@ -167,12 +169,12 @@ function Component() {
167
169
</ Box >
168
170
< Box sx = { { display : "flex" , justifyContent : "space-between" } } >
169
171
< DatePicker
170
- value = { startDateTime }
172
+ value = { DateTime . fromISO ( fromDate ?? defaultFrom ) }
171
173
label = "From"
172
174
onChange = { handleStartChange }
173
175
/>
174
176
< DatePicker
175
- value = { endDateTime }
177
+ value = { DateTime . fromISO ( toDate ?? defaultTo ) }
176
178
label = "To"
177
179
onChange = { handleEndChange }
178
180
/>
0 commit comments