diff --git a/app/api/listings/[id]/availability/route.ts b/app/api/listings/[id]/availability/route.ts index 90a6539..366b696 100644 --- a/app/api/listings/[id]/availability/route.ts +++ b/app/api/listings/[id]/availability/route.ts @@ -5,12 +5,12 @@ import { expandBlockedDates, getCalendarRanges } from '../../../../../lib/calend export async function GET(_: Request, { params }: { params: { id: string } }) { const monthParam = Number(new URL(_.url).searchParams.get('month') ?? new Date().getUTCMonth()); const yearParam = Number(new URL(_.url).searchParams.get('year') ?? new Date().getUTCFullYear()); - const monthsParam = Math.min(Number(new URL(_.url).searchParams.get('months') ?? 2), 12); + const monthsParam = Math.min(Number(new URL(_.url).searchParams.get('months') ?? 1), 12); const forceRefresh = new URL(_.url).searchParams.get('refresh') === '1'; const month = Number.isFinite(monthParam) ? monthParam : new Date().getUTCMonth(); const year = Number.isFinite(yearParam) ? yearParam : new Date().getUTCFullYear(); - const months = Number.isFinite(monthsParam) && monthsParam > 0 ? monthsParam : 2; + const months = Number.isFinite(monthsParam) && monthsParam > 0 ? monthsParam : 1; const listing = await prisma.listing.findUnique({ where: { id: params.id }, select: { calendarUrls: true } }); if (!listing) { diff --git a/app/components/AvailabilityCalendar.tsx b/app/components/AvailabilityCalendar.tsx index 9a151c4..856eecf 100644 --- a/app/components/AvailabilityCalendar.tsx +++ b/app/components/AvailabilityCalendar.tsx @@ -41,16 +41,17 @@ function buildMonths(monthCount: number, blocked: Set, startYear: number type AvailabilityResponse = { blockedDates: string[] }; -export default function AvailabilityCalendar({ listingId, hasCalendar, months = 2 }: { listingId: string; hasCalendar: boolean; months?: number }) { - const { t } = useI18n(); +export default function AvailabilityCalendar({ listingId, hasCalendar }: { listingId: string; hasCalendar: boolean }) { + const { t, locale } = useI18n(); const today = useMemo(() => new Date(), []); const [month, setMonth] = useState(today.getUTCMonth()); const [year, setYear] = useState(today.getUTCFullYear()); const [blockedDates, setBlockedDates] = useState([]); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); + const monthCount = 1; const blockedSet = useMemo(() => new Set(blockedDates), [blockedDates]); - const monthViews = useMemo(() => buildMonths(months, blockedSet, year, month), [months, blockedSet, year, month]); + const monthViews = useMemo(() => buildMonths(monthCount, blockedSet, year, month), [monthCount, blockedSet, year, month]); useEffect(() => { if (!hasCalendar) return; @@ -60,7 +61,7 @@ export default function AvailabilityCalendar({ listingId, hasCalendar, months = const params = new URLSearchParams({ month: String(month), year: String(year), - months: String(months), + months: String(monthCount), refresh: '1', }); fetch(`/api/listings/${listingId}/availability?${params.toString()}`, { cache: 'no-store', signal: controller.signal }) @@ -79,7 +80,7 @@ export default function AvailabilityCalendar({ listingId, hasCalendar, months = .finally(() => setLoading(false)); return () => controller.abort(); - }, [listingId, hasCalendar, month, year, months]); + }, [listingId, hasCalendar, month, year, monthCount]); function shiftMonth(delta: number) { const next = new Date(Date.UTC(year, month, 1)); @@ -92,9 +93,9 @@ export default function AvailabilityCalendar({ listingId, hasCalendar, months = () => Array.from({ length: 12 }, (_, m) => ({ value: m, - label: new Date(Date.UTC(2020, m, 1)).toLocaleString(undefined, { month: 'long' }), + label: new Date(Date.UTC(2020, m, 1)).toLocaleString(locale, { month: 'long' }), })), - [], + [locale], ); const yearOptions = useMemo(() => { const current = today.getUTCFullYear(); @@ -106,71 +107,70 @@ export default function AvailabilityCalendar({ listingId, hasCalendar, months =
{t('availabilityTitle')} - {t('availabilityLegendBooked')}
+ {t('availabilityLegendBooked')} - -
{error ?
{error}
: null} -
- {monthViews.map((month) => ( -
-
{month.label}
-
- {['S', 'M', 'T', 'W', 'T', 'F', 'S'].map((d) => ( -
- {d} -
+ {monthViews.map((monthView) => ( +
+
+ +
- ))} -
+
+ {['S', 'M', 'T', 'W', 'T', 'F', 'S'].map((d) => ( +
+ {d} +
+ ))} + {monthView.days.map((day, idx) => ( +
+ {day.label} +
+ ))} +
+
+ ))}
); }