From bfc32779a62de3d182042b273f6bdab3a55a95cb Mon Sep 17 00:00:00 2001 From: Andreas Oldeskog <142856+aolde@users.noreply.github.com> Date: Sat, 27 May 2023 10:09:16 +0200 Subject: [PATCH] Update holidays --- public/index.html | 4 + scripts/holidays.ts | 80 ++++---- src/App.tsx | 393 +++++++++++++++++++-------------------- src/services/holidays.ts | 2 +- 4 files changed, 235 insertions(+), 244 deletions(-) diff --git a/public/index.html b/public/index.html index 734a51c..9bfd737 100644 --- a/public/index.html +++ b/public/index.html @@ -54,6 +54,10 @@ font-family: "Fjalla One", sans-serif; } + diff --git a/scripts/holidays.ts b/scripts/holidays.ts index 05993b1..acce3a0 100644 --- a/scripts/holidays.ts +++ b/scripts/holidays.ts @@ -11,54 +11,54 @@ import path from "path"; */ async function init() { - const response = await axios.get( - "https://sholiday.faboul.se/dagar/v2.1/2022" - ); - const holidays = response.data.dagar - .filter( - (day) => - (day["dag i vecka"] !== "6" && - day["dag i vecka"] !== "7" && - day["röd dag"] === "Ja") || - day.helgdag === "Midsommarafton" || - day.helgdag === "Nyårsafton" || - day.helgdag === "Julafton" - ) - .map((day) => ({ - date: day.datum, - holiday: day.helgdag, - })); + const response = await axios.get( + "https://sholiday.faboul.se/dagar/v2.1/2023" + ); + const holidays = response.data.dagar + .filter( + (day) => + (day["dag i vecka"] !== "6" && + day["dag i vecka"] !== "7" && + day["röd dag"] === "Ja") || + day.helgdag === "Midsommarafton" || + day.helgdag === "Nyårsafton" || + day.helgdag === "Julafton" + ) + .map((day) => ({ + date: day.datum, + holiday: day.helgdag, + })); - const holidaysPath = path.resolve(__dirname, "../src/services/holidays.ts"); - const holidaysContent = `const holidays = ${JSON.stringify(holidays)}; + const holidaysPath = path.resolve(__dirname, "../src/services/holidays.ts"); + const holidaysContent = `const holidays = ${JSON.stringify(holidays)}; export default holidays;`; - fs.writeFileSync(holidaysPath, holidaysContent); + fs.writeFileSync(holidaysPath, holidaysContent); } init() - .then(() => console.log("done")) - .catch((err) => console.error("failed.", err)); + .then(() => console.log("done")) + .catch((err) => console.error("failed.", err)); export interface Dagar { - datum: string; - veckodag: string; - "arbetsfri dag": string; - "röd dag": string; - vecka: string; - "dag i vecka": string; - helgdag: string; - namnsdag: string[]; - flaggdag: string; - helgdagsafton: string; - "dag före arbetsfri helgdag": string; - klämdag: string; + datum: string; + veckodag: string; + "arbetsfri dag": string; + "röd dag": string; + vecka: string; + "dag i vecka": string; + helgdag: string; + namnsdag: string[]; + flaggdag: string; + helgdagsafton: string; + "dag före arbetsfri helgdag": string; + klämdag: string; } export interface Response { - cachetid: string; - version: string; - uri: string; - startdatum: string; - slutdatum: string; - dagar: Dagar[]; + cachetid: string; + version: string; + uri: string; + startdatum: string; + slutdatum: string; + dagar: Dagar[]; } diff --git a/src/App.tsx b/src/App.tsx index cb89334..052fba9 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,9 +1,9 @@ import "./App.css"; import { - formatTime, - getHoliday, - isWeekendTraffic, - relativeTime, + formatTime, + getHoliday, + isWeekendTraffic, + relativeTime, } from "./services/timetable"; import useForceUpdate from "./utils/hooks/useForceUpdate"; import useInterval from "./utils/hooks/useInterval"; @@ -17,211 +17,198 @@ import { Settings } from "./components/Settings"; import Sheet from "react-modal-sheet"; export type SettingsType = { - lumabrygganMinutes: number; - barnängenMinutes: number; - henriksdalMinutes: number; - displayTimeType: ("departure-time" | "leave-home-time") | (string & {}); + lumabrygganMinutes: number; + barnängenMinutes: number; + henriksdalMinutes: number; + displayTimeType: ("departure-time" | "leave-home-time") | (string & {}); }; function App() { - const now = dayjs(); - const departureTimes = useDepartureTimes(now); - const weekendTraffic = isWeekendTraffic(now); - const holiday = getHoliday(now); - const forceUpdate = useForceUpdate(); - const [settings, setSettings] = useLocalStorage("settings", { - lumabrygganMinutes: 0, - barnängenMinutes: 0, - henriksdalMinutes: 0, - displayTimeType: "departure-time", - }); - const [settingsOpen, setSettingsOpen] = useState(false); - - useInterval(() => { - forceUpdate(); - }, 1000); - - const departureHeader = ( - stopName: string, - nextDeparture1: dayjs.Dayjs, - nextDeparture2: dayjs.Dayjs, - walkTimeMinutes: number - ) => { - let nowDate = now, - warningTime = walkTimeMinutes; - - if (settings.displayTimeType === "leave-home-time") { - nowDate = nowDate.subtract(-1 * walkTimeMinutes, "minute"); - warningTime = 2; - } - - const minsUntilDeparture1 = nextDeparture1.diff(nowDate, "minute"); - const minsUntilDeparture2 = nextDeparture2.diff(nowDate, "minute"); - - let tooLateDeparture1 = minsUntilDeparture1 <= warningTime; - let tooLateDeparture2 = minsUntilDeparture2 <= warningTime; - - return ( -

- {stopName} - - - - {formatTime(nextDeparture1)} - - - - {tooLateDeparture1 ? ( - Sen - ) : null} - {relativeTime(nextDeparture1, nowDate)} - - - - - {formatTime(nextDeparture2)} - - - - {tooLateDeparture2 ? ( - Sen - ) : null} - {relativeTime(nextDeparture2, nowDate)} - - -

- ); - }; + const now = dayjs(); + const departureTimes = useDepartureTimes(now); + const weekendTraffic = isWeekendTraffic(now); + const holiday = getHoliday(now); + const forceUpdate = useForceUpdate(); + const [settings, setSettings] = useLocalStorage("settings", { + lumabrygganMinutes: 0, + barnängenMinutes: 0, + henriksdalMinutes: 0, + displayTimeType: "departure-time", + }); + const [settingsOpen, setSettingsOpen] = useState(false); + + useInterval(() => { + forceUpdate(); + }, 1000); + + const departureHeader = ( + stopName: string, + nextDeparture1: dayjs.Dayjs, + nextDeparture2: dayjs.Dayjs, + walkTimeMinutes: number + ) => { + let nowDate = now, + warningTime = walkTimeMinutes; + + if (settings.displayTimeType === "leave-home-time") { + nowDate = nowDate.subtract(-1 * walkTimeMinutes, "minute"); + warningTime = 2; + } + + const minsUntilDeparture1 = nextDeparture1.diff(nowDate, "minute"); + const minsUntilDeparture2 = nextDeparture2.diff(nowDate, "minute"); + + let tooLateDeparture1 = minsUntilDeparture1 <= warningTime; + let tooLateDeparture2 = minsUntilDeparture2 <= warningTime; return ( -
-
- Sjöstadsbåten - Sjöstadsbåten -
- -
-

Nästa avgång

- -
- - - - - - - - - - - -
- - - -

- - {weekendTraffic - ? holiday - ? `Visar helgtidtabell (${holiday.holiday})` - : "Visar helgtidtabell" - : "Visar vardagstidtabell"} -
- Gäller t.o.m. 24 juni 2022 -
- - - Github - - -
-

-
- - setSettingsOpen(false)} - snapPoints={[600, 430, 0]} - initialSnap={1} - > - {/* @ts-expect-error */} - - {/* @ts-expect-error */} - - {/* @ts-expect-error */} - - { - setSettings(settings); - setSettingsOpen(false); - }} - settings={settings} - /> - - - - {/* @ts-expect-error */} - - -
+

+ {stopName} + + + {formatTime(nextDeparture1)} + + + {tooLateDeparture1 ? ( + Sen + ) : null} + {relativeTime(nextDeparture1, nowDate)} + + + + {formatTime(nextDeparture2)} + + + {tooLateDeparture2 ? ( + Sen + ) : null} + {relativeTime(nextDeparture2, nowDate)} + + +

); + }; + + return ( +
+
+ Sjöstadsbåten + Sjöstadsbåten +
+ +
+

Nästa avgång

+ +
+ + + + + + + + + + + +
+ + + +

+ + {weekendTraffic + ? holiday + ? `Visar helgtidtabell (${holiday.holiday})` + : "Visar helgtidtabell" + : "Visar vardagstidtabell"} +
+ + + + Github + + +
+

+
+ + setSettingsOpen(false)} + snapPoints={[600, 430, 0]} + initialSnap={1} + > + {/* @ts-expect-error */} + + {/* @ts-expect-error */} + + {/* @ts-expect-error */} + + { + setSettings(settings); + setSettingsOpen(false); + }} + settings={settings} + /> + + + + {/* @ts-expect-error */} + + +
+ ); } export default App; diff --git a/src/services/holidays.ts b/src/services/holidays.ts index 0979dc8..6c1243c 100644 --- a/src/services/holidays.ts +++ b/src/services/holidays.ts @@ -1,2 +1,2 @@ -const holidays = [{"date":"2022-01-06","holiday":"Trettondedag jul"},{"date":"2022-04-15","holiday":"Långfredagen"},{"date":"2022-04-18","holiday":"Annandag påsk"},{"date":"2022-05-26","holiday":"Kristi himmelsfärdsdag"},{"date":"2022-06-24","holiday":"Midsommarafton"},{"date":"2022-12-24","holiday":"Julafton"},{"date":"2022-12-26","holiday":"Annandag jul"},{"date":"2022-12-31","holiday":"Nyårsafton"}]; +const holidays = [{"date":"2023-01-06","holiday":"Trettondedag jul"},{"date":"2023-04-07","holiday":"Långfredagen"},{"date":"2023-04-10","holiday":"Annandag påsk"},{"date":"2023-05-01","holiday":"Första Maj"},{"date":"2023-05-18","holiday":"Kristi himmelsfärdsdag"},{"date":"2023-06-06","holiday":"Sveriges nationaldag"},{"date":"2023-06-23","holiday":"Midsommarafton"},{"date":"2023-12-24","holiday":"Julafton"},{"date":"2023-12-25","holiday":"Juldagen"},{"date":"2023-12-26","holiday":"Annandag jul"},{"date":"2023-12-31","holiday":"Nyårsafton"}]; export default holidays; \ No newline at end of file