From 99e1e3de3becbf937aa712a0dbff5d1dc162c95c Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Fri, 26 Jan 2024 01:14:43 -0800 Subject: [PATCH] Fix: iCal integration use event data hash instead of uid (#2758) --- src/widgets/calendar/integrations/ical.jsx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/widgets/calendar/integrations/ical.jsx b/src/widgets/calendar/integrations/ical.jsx index ab3d06f2a..ec6427916 100644 --- a/src/widgets/calendar/integrations/ical.jsx +++ b/src/widgets/calendar/integrations/ical.jsx @@ -7,6 +7,17 @@ import { RRule } from "rrule"; import useWidgetAPI from "../../../utils/proxy/use-widget-api"; import Error from "../../../components/services/widget/error"; +// https://gist.github.com/jlevy/c246006675becc446360a798e2b2d781 +function simpleHash(str) { + /* eslint-disable no-plusplus, no-bitwise */ + let hash = 0; + for (let i = 0; i < str.length; i++) { + hash = ((hash << 5) - hash + str.charCodeAt(i)) | 0; + } + return (hash >>> 0).toString(36); + /* eslint-disable no-plusplus, no-bitwise */ +} + export default function Integration({ config, params, setEvents, hideErrors, timezone }) { const { t } = useTranslation(); const { data: icalData, error: icalError } = useWidgetAPI(config, config.name, { @@ -47,7 +58,10 @@ export default function Integration({ config, params, setEvents, hideErrors, tim const eventDate = timezone ? DateTime.fromJSDate(date, { zone: timezone }) : DateTime.fromJSDate(date); for (let j = 0; j < days; j += 1) { - eventsToAdd[`${event?.uid?.value}${i}${j}${type}`] = { + // See https://github.com/gethomepage/homepage/issues/2753 uid is not stable + // assumption is that the event is the same if the start, end and title are all the same + const hash = simpleHash(`${event?.dtstart?.value}${event?.dtend?.value}${title}${i}${j}${type}}`); + eventsToAdd[hash] = { title, date: eventDate.plus({ days: j }), color: config?.color ?? "zinc",