Skip to content

fix: correctly revert task status on network error in toggleTaskStatus#699

Open
akhilmodi29 wants to merge 1 commit into
Charushi06:mainfrom
akhilmodi29:fix/studyplan-toggle-task-status-revert
Open

fix: correctly revert task status on network error in toggleTaskStatus#699
akhilmodi29 wants to merge 1 commit into
Charushi06:mainfrom
akhilmodi29:fix/studyplan-toggle-task-status-revert

Conversation

@akhilmodi29
Copy link
Copy Markdown

Fixes #698

Problem
In store.js toggleTaskStatus(), the catch block had wrong
revert logic:

task.status = newStatus === 'Done' ? 'Not Started' : 'Done';

This sets the status to the NEW status instead of the
ORIGINAL status on network failure. So if the API call
fails, the task status is not correctly reverted back
to what it was before the toggle.

Fix
Store the original status before toggling:
const originalStatus = task.status;

Then revert to it on network error:
task.status = originalStatus;

Testing

  • Toggle task to Done → API succeeds → stays Done ✅
  • Toggle task to Done → API fails → reverts to Not Started ✅
  • Toggle task to Not Started → API fails → reverts to Done ✅

@akhilmodi29
Copy link
Copy Markdown
Author

@Charushi06 Please review this PR and add the required labels including gssoc:approved. This fixes the wrong revert logic in toggleTaskStatus on network error.

Labels suggested:

  • level:intermediate
  • type:bug
  • quality:clean

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] store.js - toggleTaskStatus reverts to wrong status on network error

1 participant