Skip to content

Commit

Permalink
Get tasks by type
Browse files Browse the repository at this point in the history
  • Loading branch information
jyan36 committed Oct 26, 2024
1 parent 4553441 commit a03e1bc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
2 changes: 1 addition & 1 deletion frontend/src/APIClients/Queries/TaskQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const GET_TASK_BY_ID = gql`
`;

export const GET_TASKS_BY_TYPE = gql`
query getTaskById($type: TaskType!) {
query getTaskByType($type: TaskType!) {
getTasksByType(type: $type) {
id
type
Expand Down
44 changes: 31 additions & 13 deletions frontend/src/components/pages/tasks/TasksPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,22 @@ const TasksPage = (): React.ReactElement => {
const [choreTasks, setChoreTasks] = useState<ChoreTask[]>([]);
const [isModalOpen, setIsModalOpen] = useState(false);

const [requiredTasksData, setRequiredTasksData] = useState<TableData[]>([]);
const [optionalTasksData, setOptionalTasksData] = useState<TableData[]>([]);
const [customTasksData, setCustomTasksData] = useState<TableData[]>([]);
const [choreTasksData, setChoreTasksData] = useState<TableData[]>([]);

const [taskType, setTaskType] = useState<TaskType>("REQUIRED");
const [taskData, setTaskData] = useState<TableData[]>([]);
const [storedTaskData, setStoredTaskData] = useState<TableData[]>([]);
const [taskDataColumns, setTaskDataColumns] = useState<ColumnInfoTypes[]>([]);

const [taskFilter, setTaskFilter] = useState<string>("");

const { loading, error, data } = useQuery(GET_TASKS_BY_TYPE, {
variables: { type: taskType },
});

// const [createTask] = useMutation<{ createTask: TaskResponse }>(CREATE_TASK);

// const [updateTask] = useMutation<{
Expand Down Expand Up @@ -270,20 +279,29 @@ const TasksPage = (): React.ReactElement => {
}, [taskFilter, storedTaskData, taskData]);

useEffect(() => {
if (taskType === "REQUIRED") {
setStoredTaskData(requiredTasksMockData);
setTaskDataColumns(tasksColumnTypes);
} else if (taskType === "OPTIONAL") {
setStoredTaskData(optionalTasksMockData);
setTaskDataColumns(tasksColumnTypes);
} else if (taskType === "CUSTOM") {
setStoredTaskData(customTasksMockData);
setTaskDataColumns(customTasksColumnTypes);
} else if (taskType === "CHORE") {
setStoredTaskData(choreTasksMockData);
setTaskDataColumns(choreTasksColumnTypes);
if (data) {
if (taskType === "REQUIRED") {
setRequiredTasks(data.getTasksByType);
setStoredTaskData(data.getTasksByType);
setTaskDataColumns(tasksColumnTypes);
} else if (taskType === "OPTIONAL") {
setOptionalTasks(data.getTasksByType);
setStoredTaskData(data.getTasksByType);
setTaskDataColumns(tasksColumnTypes);
} else if (taskType === "CUSTOM") {
setCustomTasks(data.getTasksByType);
setStoredTaskData(data.getTasksByType);
setTaskDataColumns(customTasksColumnTypes);
} else if (taskType === "CHORE") {
setChoreTasks(data.getTasksByType);
setStoredTaskData(data.getTasksByType);
setTaskDataColumns(choreTasksColumnTypes);
}
}
}, [taskType]);
}, [data, taskType]);

if (loading) return <p>Loading...</p>;
if (error) return <p>Error: {error.message}</p>;

return (
<Flex flexDir="column" flexGrow={1}>
Expand Down

0 comments on commit a03e1bc

Please sign in to comment.