From c5812cf597462e907030c967b623f1d6002ff037 Mon Sep 17 00:00:00 2001 From: ManInDark <61268856+ManInDark@users.noreply.github.com> Date: Mon, 12 Aug 2024 00:37:38 +0200 Subject: [PATCH] added option to customize year --- src/CalendarApi.tsx | 55 ++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/src/CalendarApi.tsx b/src/CalendarApi.tsx index dfb581e..93f8f89 100644 --- a/src/CalendarApi.tsx +++ b/src/CalendarApi.tsx @@ -2,39 +2,44 @@ import { useEffect, useState } from "react"; type Holiday = { "date": string, "localName": string, "countryCode": string, "fixed": string, "global": string, "types": string[] } -async function getText(): Promise { - const resp = await fetch("https://date.nager.at/api/v3/publicholidays/2024/DE") - const text_resp = await resp.text(); - return JSON.parse(text_resp); +async function getText(satYear: string): Promise { + return JSON.parse(await (await fetch("https://date.nager.at/api/v3/publicholidays/" + satYear + "/DE")).text()); } function ListHolidays() { const [keys, setKeys] = useState([]); + const [year, setYear] = useState("2024"); + const [satYear, setSatYear] = useState("2024"); + useEffect(() => { - getText().then((value) => { + getText(satYear).then((value) => { setKeys(value); }); - }, []) - return - - - - - - - - { keys.map((holiday) => - - - + }, [satYear]) + return <> +
DateName
- {holiday.date} - - {holiday.localName} -
+ + + + - )} - -
DateName
+ + + {keys.map((holiday) => + + + {holiday.date} + + + {holiday.localName} + + + )} + + + { setYear(e.target.value) }} /> + { setSatYear(year) }} /> + } export default ListHolidays; \ No newline at end of file