Skip to content

Commit

Permalink
Fix: iCal integration use event data hash instead of uid (gethomepage…
Browse files Browse the repository at this point in the history
  • Loading branch information
shamoon authored Jan 26, 2024
1 parent a6e4786 commit 99e1e3d
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/widgets/calendar/integrations/ical.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 99e1e3d

Please sign in to comment.