diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 3a3f88f1..cc78e7c6 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -765,6 +765,7 @@ "inCinemas": "In cinemas", "physicalRelease": "Physical release", "digitalRelease": "Digital release", - "noEventsToday": "No events for today!" + "noEventsToday": "No events for today!", + "noEventsFound": "No events found" } } diff --git a/src/widgets/calendar/integrations/ical.jsx b/src/widgets/calendar/integrations/ical.jsx index e0d09690..b3f1f781 100644 --- a/src/widgets/calendar/integrations/ical.jsx +++ b/src/widgets/calendar/integrations/ical.jsx @@ -1,25 +1,27 @@ import { DateTime } from "luxon"; import { parseString } from "cal-parser"; import { useEffect } from "react"; +import { useTranslation } from "next-i18next"; import useWidgetAPI from "../../../utils/proxy/use-widget-api"; import Error from "../../../components/services/widget/error"; export default function Integration({ config, params, setEvents, hideErrors }) { + const { t } = useTranslation(); const { data: icalData, error: icalError } = useWidgetAPI(config, config.name, { refreshInterval: 300000, // 5 minutes }); - let parsedIcal; - - if (!icalError && icalData && !icalData.error) { - parsedIcal = parseString(icalData.data); - if (parsedIcal.events.length === 0) { - icalData.error = { message: "No events found" }; - } - } - useEffect(() => { + let parsedIcal; + + if (!icalError && icalData && !icalData.error) { + parsedIcal = parseString(icalData.data); + if (parsedIcal.events.length === 0) { + icalData.error = { message: `'${config.name}': ${t("calendar.noEventsFound")}` }; + } + } + if (icalError || !parsedIcal) { return; } @@ -49,7 +51,7 @@ export default function Integration({ config, params, setEvents, hideErrors }) { }); setEvents((prevEvents) => ({ ...prevEvents, ...eventsToAdd })); - }, [parsedIcal, icalError, config, params, setEvents]); + }, [icalData, icalError, config, params, setEvents, t]); const error = icalError ?? icalData?.error; return error && !hideErrors && ;