21 lines
634 B
JavaScript
21 lines
634 B
JavaScript
(() => {
|
|
const logoutLink = document.querySelector('a[href="/logout"]');
|
|
if (!logoutLink) return;
|
|
|
|
const socket = window.io && window.io();
|
|
if (!socket) return;
|
|
|
|
logoutLink.addEventListener("click", (event) => {
|
|
event.preventDefault();
|
|
socket.disconnect();
|
|
window.location.assign(logoutLink.href);
|
|
});
|
|
|
|
const listMatch = window.location.pathname.match(/^\/lists\/(\d+)$/);
|
|
if (listMatch) socket.emit("list:join", listMatch[1]);
|
|
|
|
socket.on("list:updated", ({ listId }) => {
|
|
if (window.location.pathname === `/lists/${listId}`) window.location.reload();
|
|
});
|
|
})();
|