mirror of
https://github.com/ManInDark/ReactHolidays.git
synced 2026-01-21 06:34:29 +01:00
added option to customize year
This commit is contained in:
@@ -2,20 +2,22 @@ import { useEffect, useState } from "react";
|
|||||||
|
|
||||||
type Holiday = { "date": string, "localName": string, "countryCode": string, "fixed": string, "global": string, "types": string[] }
|
type Holiday = { "date": string, "localName": string, "countryCode": string, "fixed": string, "global": string, "types": string[] }
|
||||||
|
|
||||||
async function getText(): Promise<Holiday[]> {
|
async function getText(satYear: string): Promise<Holiday[]> {
|
||||||
const resp = await fetch("https://date.nager.at/api/v3/publicholidays/2024/DE")
|
return JSON.parse(await (await fetch("https://date.nager.at/api/v3/publicholidays/" + satYear + "/DE")).text());
|
||||||
const text_resp = await resp.text();
|
|
||||||
return JSON.parse(text_resp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function ListHolidays() {
|
function ListHolidays() {
|
||||||
const [keys, setKeys] = useState<Holiday[]>([]);
|
const [keys, setKeys] = useState<Holiday[]>([]);
|
||||||
|
const [year, setYear] = useState<string>("2024");
|
||||||
|
const [satYear, setSatYear] = useState<string>("2024");
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getText().then((value) => {
|
getText(satYear).then((value) => {
|
||||||
setKeys(value);
|
setKeys(value);
|
||||||
});
|
});
|
||||||
}, [])
|
}, [satYear])
|
||||||
return <table>
|
return <>
|
||||||
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Date</th>
|
<th>Date</th>
|
||||||
@@ -23,7 +25,7 @@ function ListHolidays() {
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{ keys.map((holiday) =>
|
{keys.map((holiday) =>
|
||||||
<tr key={holiday.date + "-" + holiday.localName}>
|
<tr key={holiday.date + "-" + holiday.localName}>
|
||||||
<td>
|
<td>
|
||||||
{holiday.date}
|
{holiday.date}
|
||||||
@@ -35,6 +37,9 @@ function ListHolidays() {
|
|||||||
)}
|
)}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
<input type="text" value={year} onChange={(e) => { setYear(e.target.value) }} />
|
||||||
|
<input type="submit" onClick={() => { setSatYear(year) }} />
|
||||||
|
</>
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ListHolidays;
|
export default ListHolidays;
|
||||||
Reference in New Issue
Block a user