diff --git a/website/src/hooks/tasks/useGenericTaskAPI.tsx b/website/src/hooks/tasks/useGenericTaskAPI.tsx index 1dc12f81..fc09367b 100644 --- a/website/src/hooks/tasks/useGenericTaskAPI.tsx +++ b/website/src/hooks/tasks/useGenericTaskAPI.tsx @@ -7,19 +7,16 @@ import useSWRMutation from "swr/mutation"; export const useGenericTaskAPI = (taskType: TaskTypeEnum): TaskApiHook => { const [response, setReponse] = useState>({ taskAvailability: "AWAITING_INITIAL" }); - const [isLoading, setIsLoading] = useState(true); - - const { mutate: requestNewTask } = useSWRImmutable>( + // Note: We use isValidating to indiate we are loading beause it signals eash load, not just the first one. + const { isValidating: isLoading, mutate: requestNewTask } = useSWRImmutable>( "/api/new_task/" + taskType, get, { onSuccess: (response) => { - setIsLoading(false); setReponse({ taskAvailability: "AVAILABLE", ...response }); }, onError: () => { // We could check for code 503 here for truely unavailable, but we need to do something with other errors anyway. - setIsLoading(false); setReponse({ taskAvailability: "NONE_AVAILABLE" }); }, revalidateOnMount: true, @@ -29,12 +26,10 @@ export const useGenericTaskAPI = (taskType: TaskTypeE const { trigger: completeTask } = useSWRMutation>("/api/update_task", post, { onSuccess: () => { - setIsLoading(true); requestNewTask(); }, onError: () => { // We could check for code 503 here for truely unavailable, but we need to do something with other errors anyway. - setIsLoading(false); setReponse({ taskAvailability: "NONE_AVAILABLE" }); }, });