Skip to content

Commit

Permalink
Fixed a bug when adding a task. Removed fetchAllTaskds endpoint from …
Browse files Browse the repository at this point in the history
…contentApi.
  • Loading branch information
RaayNoff committed Sep 4, 2022
1 parent 2574bbc commit 41d1acb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 31 deletions.
3 changes: 0 additions & 3 deletions src/components/pages/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ const Home: FC = () => {
const {} = contentApi.useFetchAllListsQuery(0, {
pollingInterval: 60000,
});
const {} = contentApi.useFetchAllTasksQuery(0, {
pollingInterval: 30000,
});

useEffect(() => {
const mediaQuery = window.matchMedia("(max-width: 768.98px)");
Expand Down
18 changes: 9 additions & 9 deletions src/hooks/useTaskById.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ import { notTask } from "../types/noData";
import { useTypedSelector } from "./useTypedSelector";

export const useTaskById = (taskId: number): ITask => {
const { data: tasks } = contentApi.useFetchAllTasksQuery(0);
const { data: lists } = contentApi.useFetchAllListsQuery(0);
const {
taskInfo: { lastDeletedTaskId },
} = useTypedSelector((state) => state.popups);

if (
!tasks ||
tasks.length < 1 ||
!lists ||
lists.length < 1 ||
taskId === -1 ||
taskId === lastDeletedTaskId
)
return notTask;

const _temp: ITask[] = [];

tasks.forEach((task) => {
if (task.id === taskId) _temp.push(task);
});
lists.forEach((list) =>
list.tasks.forEach((task) => {
if (task.id === taskId) _temp.push(task);
})
);

const [result] = _temp;

return result;
return _temp[0];
};
10 changes: 7 additions & 3 deletions src/hooks/useTasks.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { contentApi } from "../services/contentApi";
import { ITask } from "../types/models/ITask";
import { notTaskArr } from "../types/noData";

export default function useTasks() {
const { data: tasks } = contentApi.useFetchAllTasksQuery(0);
const { data: lists } = contentApi.useFetchAllListsQuery(0);

if (!tasks || tasks.length < 1) return notTaskArr;
if (!lists || lists.length < 1) return notTaskArr;
const result: ITask[] = [];

return tasks;
lists.forEach((list) => result.push(...list.tasks));

return result;
}
25 changes: 9 additions & 16 deletions src/services/contentApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const contentApi = createApi({
baseQuery: baseQueryWithReauth,
refetchOnReconnect: true,
refetchOnMountOrArgChange: true,
tagTypes: ["Lists", "Tasks"],
tagTypes: ["Lists"],
endpoints: (build) => ({
fetchAllLists: build.query<IList[], number>({
query: () => ({
Expand All @@ -73,7 +73,7 @@ export const contentApi = createApi({
color: color,
},
}),
invalidatesTags: ["Lists", "Tasks"],
invalidatesTags: ["Lists"],
}),
fetchListsEdit: build.mutation<string, IEditListArgs>({
query: ({ color, listName, listId }) => ({
Expand All @@ -84,14 +84,14 @@ export const contentApi = createApi({
color: color,
},
}),
invalidatesTags: ["Lists", "Tasks"],
invalidatesTags: ["Lists"],
}),
fetchListsDelete: build.mutation<string, IDeleteListArgs>({
query: ({ listId }) => ({
url: BackendApi.FETCH_LISTS_DELETE + `/${listId}`,
method: "DELETE",
}),
invalidatesTags: ["Lists", "Tasks"],
invalidatesTags: ["Lists"],
}),
fetchListsShare: build.mutation<string, IShareListArgs>({
query: ({ email, listId }) => ({
Expand All @@ -101,14 +101,7 @@ export const contentApi = createApi({
email: email,
},
}),
invalidatesTags: ["Lists", "Tasks"],
}),
fetchAllTasks: build.query<ITask[], any>({
query: () => ({
url: BackendApi.FETCH_TASKS,
method: "GET",
}),
providesTags: ["Tasks"],
invalidatesTags: ["Lists"],
}),
fetchTaskAdd: build.mutation<string, IAddTaskArgs>({
query: ({ description, endTime, listId, taskName }) => ({
Expand All @@ -120,7 +113,7 @@ export const contentApi = createApi({
endTime: endTime,
},
}),
invalidatesTags: ["Tasks", "Lists"],
invalidatesTags: ["Lists"],
}),
fetchTaskEdit: build.mutation<string, IEditTaskArgs>({
query: ({ taskId, taskName, description, status }) => ({
Expand All @@ -132,7 +125,7 @@ export const contentApi = createApi({
status: status,
},
}),
invalidatesTags: ["Tasks", "Lists"],
invalidatesTags: ["Lists"],
}),
fetchTaskComment: build.mutation<string, ICommentTaskArgs>({
query: ({ userEmail, content, taskId, timestamp }) => ({
Expand All @@ -144,14 +137,14 @@ export const contentApi = createApi({
timestamp: timestamp,
},
}),
invalidatesTags: ["Tasks", "Lists"],
invalidatesTags: ["Lists"],
}),
fetchTaskDelete: build.mutation<string, IDeleteTaskArgs>({
query: ({ taskId }) => ({
url: BackendApi.FETCH_TASKS_DELETE + `/${taskId}`,
method: "DELETE",
}),
invalidatesTags: ["Tasks", "Lists"],
invalidatesTags: ["Lists"],
}),
}),
});

0 comments on commit 41d1acb

Please sign in to comment.