Bug: Sync TasksButton allows multiple clicks, causing overlapping async requests to fail
The Sync tasks button present in the header calls the async syncTasksWithTwAndDb function on click. But as there is no loading state or any other measures implemented.
The button can be clicked multiple times stacking all the function calls even when the previous function is still not completed its function. this causes all the requests to fail together in case of an error, which should not happen ideally.
Attaching a video for reference:
Screencast from 2025-01-06 21-33-32.webm
As shown in the video, all the requests fail together after a while and too many error toasts are shown together. This can be solved by converting this component:
<div
onClick={() => syncTasksWithTwAndDb(props)}
className={`w-[110px] border ${buttonVariants({
variant: "ghost",
})}`}>
Sync Tasks
</div>
to a button and adding the disabled props to it while the function has not finished running. Probably Showing a loading spinner kind of thing would make the UX better. I would like to solve this issue @its-me-abhishek Please assign me.
- This is related to the job queue that i have been working on since a long time. I will be pushing the job queue updates by today probably. You can pull that and fix the frontend.
- But your logic seems to be a bit flawed.
- There are 3 sync buttons in the website: at tasks, in navdesktop and navmobile.
<Button variant="outline" onClick={() => syncTasksWithTwAndDb(props)}>Sync</Button>can be used to replace the current navdesktop and mobile ones, and the task one remains the same
- Now, what we will have to do is something like ->
- the Sync text converts to a loading spinner in the button itself, and the API calls are disabled until we have got a response.
- Side Note: We will have to fix this in the Taskwarrior app as well.
- you can use this for the spinner
perhaps try not to use any other library other than shadcn so that the website doesnot become cluttered EDIT: I have pushed the Job queue
This is related to the job queue that i have been working on since a long time. I will be pushing the job queue updates by today probably. You can pull that and fix the frontend.
But your logic seems to be a bit flawed.
There are 3 sync buttons in the website: at tasks, in navdesktop and navmobile.
<Button variant="outline" onClick={() => syncTasksWithTwAndDb(props)}>Sync</Button>can be used to replace the current navdesktop and mobile ones, and the task one remains the sameNow, what we will have to do is something like ->
- the Sync text converts to a loading spinner in the button itself, and the API calls are disabled until we have got a response.
- Side Note: We will have to fix this in the Taskwarrior app as well.
- you can use this for the spinner
perhaps try not to use any other library other than shadcn so that the website doesnot become cluttered EDIT: I have pushed the Job queue
Sure @its-me-abhishek i have pulled all the recent changes. Will work towards the implementation of the loader as suggested and make a PR.
Does this seem about right...? edited total of 3 files to update the navbar in desktop, side menu in smaller screens and the sync button in the Tasks section. Implemented a simple loading logic as suggested. the modified button code looks like this:
<Button
variant={"ghost"}
className="w-[110px] border"
onClick={async() => {
setIsLoading(true)
await syncTasksWithTwAndDb(props)
setIsLoading(false)
}}
disabled={isLoading}
>
{
isLoading ?
<>
<Loader2 className="mr-2 size-5 animate-spin" />
Syncing
</>
: "Sync Tasks"
}
</Button>
a simple loading state is implemented using useState hook : const [isLoading, setIsLoading] = useState(false);
Screencast from 2025-01-07 13-58-38.webm
Screencast from 2025-01-07 14-01-43.webm
Screencast from 2025-01-07 14-02-13.webm
If this is alright I will go ahead with the PR. Thanks.
LGTM! please create a PR. Also please include the video where the server is up and working
Also, in the last video, when sync is pressed on Tasks panel, you can still press sync in the navbar, thus it is a loophole. please fix it. might be fixed using state uplifting
Also, in the last video, when sync is pressed on Tasks panel, you can still press sync in the navbar, thus it is a loophole. please fix it. might be fixed using state uplifting
Oh... didn't take that into consideration will take the isloading state to the top level component and use that to manage the loading state of all three sync buttons. taking the state up to the frontend/src/components/HomePage.tsx component should do the work. thanks for the suggestion. would also see to it that the syncing success is also working fine with that.
while I am at it, there might be a fix to another issue... in the frontend/src/components/HomePage.tsx component the if userInfo state is null, it shown this screen:
but, as the fetchUserInfo function takes time, the session expired screen is always shown, in case of a slow connection, this screen is shown for a longer time. implementing the loading state to prevent that would make it better altogether. should i go at it...?
Oh... didn't take that into consideration will take the isloading state to the top level component and use that to manage the loading state of all three sync buttons. taking the state up to the frontend/src/components/HomePage.tsx component should do the work. thanks for the suggestion. would also see to it that the syncing success is also working fine with that.
Cool
while I am at it, there might be a fix to another issue... in the frontend/src/components/HomePage.tsx component the if userInfo state is null, it shown this screen: but, as the fetchUserInfo function takes time, the session expired screen is always shown, in case of a slow connection, this screen is shown for a longer time. implementing the loading state to prevent that would make it better altogether. should i go at it...?
I do not think that it is required. it had earlier caused some issues when I tested using multiple accounts.
Closed by #64 #65