Use hooks for "create" tasks

This commit is contained in:
AbdBarho
2023-01-08 18:57:18 +01:00
parent bbee761c90
commit ad91bfe201
6 changed files with 50 additions and 91 deletions
@@ -17,7 +17,7 @@ export const useGenericTaskAPI = <TaskType,>(taskApiEndpoint: string) => {
const [tasks, setTasks] = useState<ConcreteTaskResponse[]>([]);
const { isLoading, mutate, error } = useSWRImmutable<ConcreteTaskResponse>(
const { data, isLoading, mutate, error } = useSWRImmutable<ConcreteTaskResponse>(
"/api/new_task/" + taskApiEndpoint,
fetcher,
{
@@ -26,10 +26,10 @@ export const useGenericTaskAPI = <TaskType,>(taskApiEndpoint: string) => {
);
useEffect(() => {
if (tasks.length === 0 && !isLoading && !error) {
if (data === undefined && !isLoading && !error) {
mutate();
}
}, [tasks, isLoading, mutate, error]);
}, [data, isLoading, mutate, error]);
const { trigger } = useSWRMutation("/api/update_task", poster, {
onSuccess: async (response) => {