Timothy J. Baek 1 年之前
父節點
當前提交
f6e839611b
共有 1 個文件被更改,包括 12 次插入4 次删除
  1. 12 4
      src/lib/components/layout/Sidebar.svelte

+ 12 - 4
src/lib/components/layout/Sidebar.svelte

@@ -62,14 +62,22 @@
 			}
 		}
 
-		document.addEventListener('touchstart', (e) => {
+		const onTouchStart = (e) => {
 			touchstartX = e.changedTouches[0].screenX;
-		});
+		};
 
-		document.addEventListener('touchend', (e) => {
+		const onTouchEnd = (e) => {
 			touchendX = e.changedTouches[0].screenX;
 			checkDirection();
-		});
+		};
+
+		document.addEventListener('touchstart', onTouchStart);
+		document.addEventListener('touchend', onTouchEnd);
+
+		return () => {
+			document.removeEventListener('touchstart', onTouchStart);
+			document.removeEventListener('touchend', onTouchEnd);
+		};
 	});
 
 	// Helper function to fetch and add chat content to each chat