diff --git a/app/ui/MonthLocationList.tsx b/app/ui/MonthLocationList.tsx index 06d945f..eb484a1 100644 --- a/app/ui/MonthLocationList.tsx +++ b/app/ui/MonthLocationList.tsx @@ -7,7 +7,7 @@ import { MonthCard } from "./MonthCard"; import Pagination from "./Pagination"; import { LocationCard } from "./LocationCard"; import { BillingLocation, YearMonth } from "../lib/db-types"; -import { useParams, useRouter } from "next/navigation"; +import { useParams, useRouter, useSearchParams } from "next/navigation"; const getNextYearMonth = (yearMonth:YearMonth) => { const {year, month} = yearMonth; @@ -34,7 +34,13 @@ export const MonthLocationList:React.FC = ({ }) => { const router = useRouter(); - const params = useParams(); + const search = useSearchParams(); + + const initialMonth = search.get('month') + + const [expandedMonth, setExpandedMonth] = React.useState( + initialMonth ? parseInt(initialMonth as string) : -1 // no month is expanded + ); if(!availableYears || !months) { const currentYearMonth:YearMonth = { @@ -50,12 +56,6 @@ export const MonthLocationList:React.FC = ({ ) }; - const { month: initialMonth } = params; - - const [expandedMonth, setExpandedMonth] = React.useState( - initialMonth ? parseInt(initialMonth as string) : new Date().getMonth() + 1 - ); - const monthsArray = Object.entries(months); // when the month is toggled, update the URL