-
Notifications
You must be signed in to change notification settings - Fork 69
fix: add circular dependency detection for tasks #323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5dc08d8
599bf2f
fd64fa6
1d6edbe
68e8a74
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -229,6 +229,16 @@ export const Tasks = ( | |
| return () => clearInterval(interval); | ||
| }, []); | ||
|
|
||
| // Listen for sync events from WebSocket handler | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. similarly, please remove trivial comments |
||
| useEffect(() => { | ||
| const handleSyncTasks = () => { | ||
| syncTasksWithTwAndDb(); | ||
| }; | ||
|
|
||
| window.addEventListener('syncTasks', handleSyncTasks); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this UseEffect and event listener architecture, and make use of other Sync based Effects available |
||
| return () => window.removeEventListener('syncTasks', handleSyncTasks); | ||
| }, [syncTasksWithTwAndDb]); | ||
|
|
||
| useEffect(() => { | ||
| const fetchTasksForEmail = async () => { | ||
| try { | ||
|
|
@@ -397,7 +407,7 @@ export const Tasks = ( | |
| annotations, | ||
| }); | ||
|
|
||
| console.log('Task edited successfully!'); | ||
| // Don't show success message here - wait for WebSocket confirmation | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please remove this and other such copilot based comments, they add to the bloat |
||
| setIsAddTaskOpen(false); | ||
| } catch (error) { | ||
| console.error('Failed to edit task:', error); | ||
|
|
@@ -682,28 +692,31 @@ export const Tasks = ( | |
| ); | ||
| }; | ||
|
|
||
| const handleDependsSaveClick = (task: Task, depends: string[]) => { | ||
| task.depends = depends; | ||
|
|
||
| const handleDependsSaveClick = async (task: Task, depends: string[]) => { | ||
| setUnsyncedTaskUuids((prev) => new Set([...prev, task.uuid])); | ||
|
|
||
| handleEditTaskOnBackend( | ||
| props.email, | ||
| props.encryptionSecret, | ||
| props.UUID, | ||
| task.description, | ||
| task.tags, | ||
| task.uuid.toString(), | ||
| task.project, | ||
| task.start, | ||
| task.entry || '', | ||
| task.wait || '', | ||
| task.end || '', | ||
| task.depends, | ||
| task.due || '', | ||
| task.recur || '', | ||
| task.annotations || [] | ||
| ); | ||
| try { | ||
| console.log('Calling backend...'); | ||
| await handleEditTaskOnBackend( | ||
| props.email, | ||
| props.encryptionSecret, | ||
| props.UUID, | ||
| task.description, | ||
| task.tags, | ||
| task.uuid.toString(), | ||
| task.project, | ||
| task.start, | ||
| task.entry || '', | ||
| task.wait || '', | ||
| task.end || '', | ||
| depends, | ||
| task.due || '', | ||
| task.recur || '', | ||
| task.annotations || [] | ||
| ); | ||
| } catch (error) { | ||
| console.error('Failed to update dependencies:', error); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe just add a new toast here instead of changing it in HomePage |
||
| } | ||
| }; | ||
|
|
||
| const handleRecurSaveClick = (task: Task, recur: string) => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,8 +78,12 @@ export const HomePage: React.FC = () => { | |
| try { | ||
| const data = JSON.parse(event.data); | ||
| if (data.status === 'success') { | ||
| // Skip refresh for Edit Task to prevent dialog blinking | ||
| if (data.job !== 'Edit Task') { | ||
| // Use syncTasksWithTwAndDb to update both backend and IndexedDB | ||
| // This ensures the Tasks component sees the updated data | ||
| if (data.job === 'Edit Task') { | ||
| // For Edit Task, we need to trigger a sync to update the UI | ||
| window.dispatchEvent(new CustomEvent('syncTasks')); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this really required? Can we skip this? |
||
| } else { | ||
| getTasks(userInfo.email, userInfo.encryption_secret, userInfo.uuid); | ||
| } | ||
|
|
||
|
|
@@ -128,7 +132,15 @@ export const HomePage: React.FC = () => { | |
| } | ||
| } else if (data.status == 'failure') { | ||
| console.log(`Failed to ${data.job || 'perform action'}`); | ||
| toast.error(`Failed to ${data.job || 'perform action'}`, { | ||
|
|
||
| // Show specific message for Edit Task failures | ||
| let errorMessage = `Failed to ${data.job || 'perform action'}`; | ||
| if (data.job === 'Edit Task') { | ||
| errorMessage = | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this might not be the case everytime for this Jobs failure, and can be misleading.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can revert this for now, and leave this as it is. will add a separate toast flow later |
||
| 'Failed to add dependency: Circular dependency detected'; | ||
| } | ||
|
|
||
| toast.error(errorMessage, { | ||
| position: 'bottom-left', | ||
| autoClose: 3000, | ||
| hideProgressBar: false, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This n^2 loop needs to be optimized