BugFix: month list did not expand appropriate month based od search params
This commit is contained in:
@@ -7,7 +7,7 @@ import { MonthCard } from "./MonthCard";
|
|||||||
import Pagination from "./Pagination";
|
import Pagination from "./Pagination";
|
||||||
import { LocationCard } from "./LocationCard";
|
import { LocationCard } from "./LocationCard";
|
||||||
import { BillingLocation, YearMonth } from "../lib/db-types";
|
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 getNextYearMonth = (yearMonth:YearMonth) => {
|
||||||
const {year, month} = yearMonth;
|
const {year, month} = yearMonth;
|
||||||
@@ -34,7 +34,13 @@ export const MonthLocationList:React.FC<MonthLocationListProps > = ({
|
|||||||
}) => {
|
}) => {
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const params = useParams();
|
const search = useSearchParams();
|
||||||
|
|
||||||
|
const initialMonth = search.get('month')
|
||||||
|
|
||||||
|
const [expandedMonth, setExpandedMonth] = React.useState<number>(
|
||||||
|
initialMonth ? parseInt(initialMonth as string) : -1 // no month is expanded
|
||||||
|
);
|
||||||
|
|
||||||
if(!availableYears || !months) {
|
if(!availableYears || !months) {
|
||||||
const currentYearMonth:YearMonth = {
|
const currentYearMonth:YearMonth = {
|
||||||
@@ -50,12 +56,6 @@ export const MonthLocationList:React.FC<MonthLocationListProps > = ({
|
|||||||
</>)
|
</>)
|
||||||
};
|
};
|
||||||
|
|
||||||
const { month: initialMonth } = params;
|
|
||||||
|
|
||||||
const [expandedMonth, setExpandedMonth] = React.useState<number>(
|
|
||||||
initialMonth ? parseInt(initialMonth as string) : new Date().getMonth() + 1
|
|
||||||
);
|
|
||||||
|
|
||||||
const monthsArray = Object.entries(months);
|
const monthsArray = Object.entries(months);
|
||||||
|
|
||||||
// when the month is toggled, update the URL
|
// when the month is toggled, update the URL
|
||||||
|
|||||||
Reference in New Issue
Block a user