[#451] added websocket connexion (#453)

* [#451] added websocket connexion

* [#451] added tests

* [#451] add missing cleanup for web socket causing memory leaks
This commit is contained in:
Camille Moussu
2026-01-14 15:17:29 +01:00
committed by GitHub
parent 8b3afc1737
commit 2fa8a7f16a
18 changed files with 1204 additions and 4 deletions
+13
View File
@@ -0,0 +1,13 @@
export function setSelectedCalendars(calendars: string[]) {
try {
localStorage.setItem("selectedCalendars", JSON.stringify(calendars));
window.dispatchEvent(
new CustomEvent("selectedCalendarsChanged", {
detail: calendars,
})
);
} catch (error) {
console.error("Failed to save selected calendars:", error);
}
}
+43
View File
@@ -0,0 +1,43 @@
import { useEffect, useState } from "react";
export function useSelectedCalendars(): string[] {
const [calendars, setCalendars] = useState<string[]>(() => {
try {
return JSON.parse(localStorage.getItem("selectedCalendars") ?? "[]");
} catch {
return [];
}
});
useEffect(() => {
const onStorage = (e: StorageEvent) => {
if (e.key === "selectedCalendars") {
try {
setCalendars(JSON.parse(e.newValue ?? "[]"));
} catch {
setCalendars([]);
}
}
};
const onLocalChange = (e: CustomEvent<string[]>) => {
setCalendars(e.detail);
};
window.addEventListener("storage", onStorage);
window.addEventListener(
"selectedCalendarsChanged",
onLocalChange as EventListener
);
return () => {
window.removeEventListener("storage", onStorage);
window.removeEventListener(
"selectedCalendarsChanged",
onLocalChange as EventListener
);
};
}, []);
return calendars;
}