From 75f30ffaf5a85ad3580fd8698de8a8f7c63a4297 Mon Sep 17 00:00:00 2001 From: Filip Czaplicki Date: Tue, 13 Feb 2024 21:58:16 +0100 Subject: [PATCH] Enable correctness/useHookAtTopLevel Fixes #205 --- biome.json | 5 ++++- src/components/sidebar/defibrillatorDetails.tsx | 7 ++++--- src/components/sidebar/openingHours.tsx | 13 ++++++++----- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/biome.json b/biome.json index 20474cc..705c3e4 100644 --- a/biome.json +++ b/biome.json @@ -15,7 +15,10 @@ "linter": { "enabled": true, "rules": { - "recommended": true + "recommended": true, + "correctness": { + "useHookAtTopLevel": "error" + } } } } diff --git a/src/components/sidebar/defibrillatorDetails.tsx b/src/components/sidebar/defibrillatorDetails.tsx index 030864e..5e30283 100644 --- a/src/components/sidebar/defibrillatorDetails.tsx +++ b/src/components/sidebar/defibrillatorDetails.tsx @@ -8,7 +8,7 @@ import { mdiPhoneOutline, } from "@mdi/js"; import Icon from "@mdi/react"; -import React, { FC } from "react"; +import React, { FC, useState } from "react"; import { Button, Card, Columns, Image } from "react-bulma-components"; import { useTranslation } from "react-i18next"; import ImageGallery, { ReactImageGalleryItem } from "react-image-gallery"; @@ -36,14 +36,15 @@ const PhotoGallery: FC = ({ data, closeSidebar, }) => { - if (data === null) return null; const { t } = useTranslation(); const { authState: { auth }, setSidebarAction, setModalState, } = useAppContext(); - const [imageError, setImageError] = React.useState(""); + const [imageError, setImageError] = useState(""); + + if (data === null) return null; let images: ReactImageGalleryItem[] = []; // Currently only one photo allowed if (data.photoRelativeUrl !== undefined && data.photoRelativeUrl !== null) { diff --git a/src/components/sidebar/openingHours.tsx b/src/components/sidebar/openingHours.tsx index 685cd12..d2469ad 100644 --- a/src/components/sidebar/openingHours.tsx +++ b/src/components/sidebar/openingHours.tsx @@ -35,12 +35,14 @@ function getOpeningHoursConfig(language: string): argument_hash { }; } -function parseOpeningHours(openingHours: string): string | null { +function parseOpeningHours( + openingHours: string, + language: string, +): string | null { if (!openingHours) return null; try { const oh = new OpeningHours(openingHours, null, 2); - const language = useLanguage(); const config = getOpeningHoursConfig(language); // @ts-ignore return oh.prettifyValue({ conf: config }); @@ -100,18 +102,19 @@ export const OpeningHoursDescription: FC = ({ openingHours, timezoneOffsetUTCMinutes, }) => { + const language = useLanguage(); + const { t } = useTranslation(); + if (!openingHours) { return ; } - const { t } = useTranslation(); - return ( {openingHours === "24/7" ? t("opening_hours.24_7") - : parseOpeningHours(openingHours)} + : parseOpeningHours(openingHours, language)}