Centralize task types

This commit is contained in:
AbdBarho
2023-01-10 06:51:59 +01:00
parent 942dc42d03
commit 54a042d002
29 changed files with 162 additions and 192 deletions
@@ -1,18 +1,11 @@
import { useState } from "react";
import fetcher from "src/lib/fetcher";
import poster from "src/lib/poster";
import { BaseTask, TaskResponse } from "src/types/Task";
import useSWRImmutable from "swr/immutable";
import useSWRMutation from "swr/mutation";
// TODO: type & centralize types for all tasks
export interface TaskResponse<TaskType> {
id: string;
userId: string;
task: TaskType;
}
export const useGenericTaskAPI = <TaskType,>(taskApiEndpoint: string) => {
export const useGenericTaskAPI = <TaskType extends BaseTask>(taskApiEndpoint: string) => {
type ConcreteTaskResponse = TaskResponse<TaskType>;
const [tasks, setTasks] = useState<ConcreteTaskResponse[]>([]);