pstream is dead; long live pstream taciturnaxolotl.github.io/pstream-ng/
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

update time to apply bookmark, watching, and history changes

Pas 93b5971f 9af6e36d

+134 -16
+54
src/stores/bookmarks/BookmarkSyncer.tsx
··· 59 59 clearUpdateQueue(); 60 60 }, [clearUpdateQueue]); 61 61 62 + // Regular interval sync 62 63 useEffect(() => { 63 64 const interval = setInterval(() => { 64 65 (async () => { ··· 76 77 77 78 return () => { 78 79 clearInterval(interval); 80 + }; 81 + }, [removeUpdateItem, url]); 82 + 83 + // Immediate sync when items are added or removed 84 + useEffect(() => { 85 + let syncTimeout: NodeJS.Timeout | null = null; 86 + 87 + const syncImmediately = async () => { 88 + if (!url) return; 89 + const state = useBookmarkStore.getState(); 90 + const user = useAuthStore.getState(); 91 + // Only sync if there are items in the queue 92 + if (state.updateQueue.length > 0) { 93 + await syncBookmarks( 94 + state.updateQueue, 95 + removeUpdateItem, 96 + url, 97 + user.account, 98 + ); 99 + } 100 + }; 101 + 102 + const debouncedSync = () => { 103 + if (syncTimeout) { 104 + clearTimeout(syncTimeout); 105 + } 106 + syncTimeout = setTimeout(syncImmediately, 100); 107 + }; 108 + 109 + // Override the addBookmark function to trigger immediate sync 110 + const originalAddBookmark = useBookmarkStore.getState().addBookmark; 111 + useBookmarkStore.setState({ 112 + addBookmark: (...args) => { 113 + originalAddBookmark(...args); 114 + // Trigger debounced sync after adding bookmark 115 + debouncedSync(); 116 + }, 117 + }); 118 + 119 + // Override removeBookmark to trigger immediate sync 120 + const originalRemoveBookmark = useBookmarkStore.getState().removeBookmark; 121 + useBookmarkStore.setState({ 122 + removeBookmark: (...args) => { 123 + originalRemoveBookmark(...args); 124 + // Trigger debounced sync after removing bookmark 125 + debouncedSync(); 126 + }, 127 + }); 128 + 129 + return () => { 130 + if (syncTimeout) { 131 + clearTimeout(syncTimeout); 132 + } 79 133 }; 80 134 }, [removeUpdateItem, url]); 81 135
+54
src/stores/progress/ProgressSyncer.tsx
··· 59 59 clearUpdateQueue(); 60 60 }, [clearUpdateQueue]); 61 61 62 + // Regular interval sync 62 63 useEffect(() => { 63 64 const interval = setInterval(() => { 64 65 (async () => { ··· 76 77 77 78 return () => { 78 79 clearInterval(interval); 80 + }; 81 + }, [removeUpdateItem, url]); 82 + 83 + // Immediate sync when items are added or removed 84 + useEffect(() => { 85 + let syncTimeout: NodeJS.Timeout | null = null; 86 + 87 + const syncImmediately = async () => { 88 + if (!url) return; 89 + const state = useProgressStore.getState(); 90 + const user = useAuthStore.getState(); 91 + // Only sync if there are items in the queue 92 + if (state.updateQueue.length > 0) { 93 + await syncProgress( 94 + state.updateQueue, 95 + removeUpdateItem, 96 + url, 97 + user.account, 98 + ); 99 + } 100 + }; 101 + 102 + const debouncedSync = () => { 103 + if (syncTimeout) { 104 + clearTimeout(syncTimeout); 105 + } 106 + syncTimeout = setTimeout(syncImmediately, 100); 107 + }; 108 + 109 + // Override the updateItem function to trigger immediate sync 110 + const originalUpdateItem = useProgressStore.getState().updateItem; 111 + useProgressStore.setState({ 112 + updateItem: (...args) => { 113 + originalUpdateItem(...args); 114 + // Trigger debounced sync after updating item 115 + debouncedSync(); 116 + }, 117 + }); 118 + 119 + // Override removeItem to trigger immediate sync 120 + const originalRemoveItem = useProgressStore.getState().removeItem; 121 + useProgressStore.setState({ 122 + removeItem: (...args) => { 123 + originalRemoveItem(...args); 124 + // Trigger debounced sync after removing item 125 + debouncedSync(); 126 + }, 127 + }); 128 + 129 + return () => { 130 + if (syncTimeout) { 131 + clearTimeout(syncTimeout); 132 + } 79 133 }; 80 134 }, [removeUpdateItem, url]); 81 135
+26 -16
src/stores/watchHistory/WatchHistorySyncer.tsx
··· 66 66 clearUpdateQueue(); 67 67 }, [clearUpdateQueue]); 68 68 69 - // Immediate sync when items are added to queue 69 + // Immediate sync when items are added or removed 70 70 useEffect(() => { 71 - let lastQueueLength = 0; 71 + let syncTimeout: NodeJS.Timeout | null = null; 72 72 73 - const checkAndSync = async () => { 74 - const currentQueueLength = 75 - useWatchHistoryStore.getState().updateQueue.length; 76 - // Only sync immediately if queue grew (items were added) 77 - if (currentQueueLength > lastQueueLength && currentQueueLength > 0) { 78 - if (!url) return; 79 - const state = useWatchHistoryStore.getState(); 80 - const user = useAuthStore.getState(); 73 + const syncImmediately = async () => { 74 + if (!url) return; 75 + const state = useWatchHistoryStore.getState(); 76 + const user = useAuthStore.getState(); 77 + // Only sync if there are items in the queue 78 + if (state.updateQueue.length > 0) { 81 79 await syncWatchHistory( 82 80 state.updateQueue, 83 81 removeUpdateItem, ··· 85 83 user.account, 86 84 ); 87 85 } 88 - lastQueueLength = currentQueueLength; 86 + }; 87 + 88 + const debouncedSync = () => { 89 + if (syncTimeout) { 90 + clearTimeout(syncTimeout); 91 + } 92 + syncTimeout = setTimeout(syncImmediately, 100); 89 93 }; 90 94 91 95 // Override the addItem function to trigger immediate sync ··· 93 97 useWatchHistoryStore.setState({ 94 98 addItem: (...args) => { 95 99 originalAddItem(...args); 96 - // Trigger sync after adding item 97 - setTimeout(checkAndSync, 100); 100 + // Trigger debounced sync after adding item 101 + debouncedSync(); 98 102 }, 99 103 }); 100 104 101 - // Also override removeItem 105 + // Override removeItem to trigger immediate sync 102 106 const originalRemoveItem = useWatchHistoryStore.getState().removeItem; 103 107 useWatchHistoryStore.setState({ 104 108 removeItem: (...args) => { 105 109 originalRemoveItem(...args); 106 - // Trigger sync after removing item 107 - setTimeout(checkAndSync, 100); 110 + // Trigger debounced sync after removing item 111 + debouncedSync(); 108 112 }, 109 113 }); 114 + 115 + return () => { 116 + if (syncTimeout) { 117 + clearTimeout(syncTimeout); 118 + } 119 + }; 110 120 }, [removeUpdateItem, url]); 111 121 112 122 // Regular interval sync