Translate no events, fix location of no events error
This commit is contained in:
parent
cdf83cb035
commit
10e6187775
@ -765,6 +765,7 @@
|
|||||||
"inCinemas": "In cinemas",
|
"inCinemas": "In cinemas",
|
||||||
"physicalRelease": "Physical release",
|
"physicalRelease": "Physical release",
|
||||||
"digitalRelease": "Digital release",
|
"digitalRelease": "Digital release",
|
||||||
"noEventsToday": "No events for today!"
|
"noEventsToday": "No events for today!",
|
||||||
|
"noEventsFound": "No events found"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,25 +1,27 @@
|
|||||||
import { DateTime } from "luxon";
|
import { DateTime } from "luxon";
|
||||||
import { parseString } from "cal-parser";
|
import { parseString } from "cal-parser";
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
|
import { useTranslation } from "next-i18next";
|
||||||
|
|
||||||
import useWidgetAPI from "../../../utils/proxy/use-widget-api";
|
import useWidgetAPI from "../../../utils/proxy/use-widget-api";
|
||||||
import Error from "../../../components/services/widget/error";
|
import Error from "../../../components/services/widget/error";
|
||||||
|
|
||||||
export default function Integration({ config, params, setEvents, hideErrors }) {
|
export default function Integration({ config, params, setEvents, hideErrors }) {
|
||||||
|
const { t } = useTranslation();
|
||||||
const { data: icalData, error: icalError } = useWidgetAPI(config, config.name, {
|
const { data: icalData, error: icalError } = useWidgetAPI(config, config.name, {
|
||||||
refreshInterval: 300000, // 5 minutes
|
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(() => {
|
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) {
|
if (icalError || !parsedIcal) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -49,7 +51,7 @@ export default function Integration({ config, params, setEvents, hideErrors }) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
setEvents((prevEvents) => ({ ...prevEvents, ...eventsToAdd }));
|
setEvents((prevEvents) => ({ ...prevEvents, ...eventsToAdd }));
|
||||||
}, [parsedIcal, icalError, config, params, setEvents]);
|
}, [icalData, icalError, config, params, setEvents, t]);
|
||||||
|
|
||||||
const error = icalError ?? icalData?.error;
|
const error = icalError ?? icalData?.error;
|
||||||
return error && !hideErrors && <Error error={{ message: `${config.type}: ${error.message ?? error}` }} />;
|
return error && !hideErrors && <Error error={{ message: `${config.type}: ${error.message ?? error}` }} />;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user