BugFix: HomePage did not parse URL correctly
This commit is contained in:
@@ -5,6 +5,7 @@ import { FC, useEffect, useState } from 'react';
|
|||||||
import { MonthLocationList } from '@/app/ui/MonthLocationList';
|
import { MonthLocationList } from '@/app/ui/MonthLocationList';
|
||||||
import { WithId } from 'mongodb';
|
import { WithId } from 'mongodb';
|
||||||
import { MonthCardSkeleton } from './MonthCardSkeleton';
|
import { MonthCardSkeleton } from './MonthCardSkeleton';
|
||||||
|
import { useSearchParams } from 'next/navigation';
|
||||||
|
|
||||||
export interface HomePageProps {
|
export interface HomePageProps {
|
||||||
}
|
}
|
||||||
@@ -23,6 +24,8 @@ const fetchAvailableYears = async () => {
|
|||||||
|
|
||||||
export const HomePage:FC<HomePageProps> = () => {
|
export const HomePage:FC<HomePageProps> = () => {
|
||||||
|
|
||||||
|
const searchParams = useSearchParams();
|
||||||
|
|
||||||
const [ homePageStatus, setHomePageStatus ] = useState<{
|
const [ homePageStatus, setHomePageStatus ] = useState<{
|
||||||
status: "loading" | "loaded" | "error",
|
status: "loading" | "loaded" | "error",
|
||||||
availableYears: number[],
|
availableYears: number[],
|
||||||
@@ -36,7 +39,7 @@ export const HomePage:FC<HomePageProps> = () => {
|
|||||||
|
|
||||||
const {availableYears, locations, status, error} = homePageStatus;
|
const {availableYears, locations, status, error} = homePageStatus;
|
||||||
|
|
||||||
const year = new URLSearchParams(window.location.search).get('year');
|
const year = searchParams.get('year');
|
||||||
const currentYear = year ? parseInt(year, 10) : new Date().getFullYear();
|
const currentYear = year ? parseInt(year, 10) : new Date().getFullYear();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user