Преглед изворни кода

fix: move addNotification before useEffect to fix closure issue

Timothy Pomeroy пре 1 месец
родитељ
комит
e50a37dfc2

+ 3 - 2
apps/service/src/handbrake.service.ts

@@ -76,14 +76,15 @@ export class HandbrakeService {
    */
   private ensureOutputDirectory(outputPath: string): string {
     const isAbsolute = path.isAbsolute(outputPath);
-    const parts = outputPath.split(path.sep).filter(part => part); // Filter out empty strings
+    const parts = outputPath.split(path.sep).filter((part) => part); // Filter out empty strings
     let currentPath = isAbsolute ? '/' : '';
 
     // Build path incrementally, checking for case-insensitive matches
     for (let i = 0; i < parts.length; i++) {
       const part = parts[i];
 
-      const proposedPath = currentPath === '/' ? `/${part}` : path.join(currentPath, part);
+      const proposedPath =
+        currentPath === '/' ? `/${part}` : path.join(currentPath, part);
 
       // Check if directory exists (exact case)
       if (existsSync(proposedPath)) {

+ 13 - 13
apps/web/src/app/components/NotificationContext.tsx

@@ -36,6 +36,18 @@ const NotificationContext = createContext<NotificationContextType | undefined>(
 export function NotificationProvider({ children }: { children: ReactNode }) {
   const [notifications, setNotifications] = useState<Notification[]>([]);
 
+  const addNotification = (
+    notification: Omit<Notification, "id" | "timestamp" | "read">
+  ) => {
+    const newNotification: Notification = {
+      ...notification,
+      id: Date.now().toString() + Math.random().toString(36).substr(2, 9),
+      timestamp: new Date(),
+      read: false
+    };
+    setNotifications((prev) => [newNotification, ...prev]);
+  };
+
   // Listen for WebSocket events and add notifications
   useEffect(() => {
     const handleFileUpdate = (event: CustomEvent) => {
@@ -85,19 +97,7 @@ export function NotificationProvider({ children }: { children: ReactNode }) {
         handleTaskUpdate as EventListener
       );
     };
-  }, []);
-
-  const addNotification = (
-    notification: Omit<Notification, "id" | "timestamp" | "read">
-  ) => {
-    const newNotification: Notification = {
-      ...notification,
-      id: Date.now().toString() + Math.random().toString(36).substr(2, 9),
-      timestamp: new Date(),
-      read: false
-    };
-    setNotifications((prev) => [newNotification, ...prev]);
-  };
+  }, [addNotification]);
 
   const markAsRead = (id: string) => {
     setNotifications((prev) =>