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 { WithId } from 'mongodb';
|
||||
import { MonthCardSkeleton } from './MonthCardSkeleton';
|
||||
import { useSearchParams } from 'next/navigation';
|
||||
|
||||
export interface HomePageProps {
|
||||
}
|
||||
@@ -23,6 +24,8 @@ const fetchAvailableYears = async () => {
|
||||
|
||||
export const HomePage:FC<HomePageProps> = () => {
|
||||
|
||||
const searchParams = useSearchParams();
|
||||
|
||||
const [ homePageStatus, setHomePageStatus ] = useState<{
|
||||
status: "loading" | "loaded" | "error",
|
||||
availableYears: number[],
|
||||
@@ -36,7 +39,7 @@ export const HomePage:FC<HomePageProps> = () => {
|
||||
|
||||
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();
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user