From 24e316b12f209a95552adec981bc3bef4631a585 Mon Sep 17 00:00:00 2001 From: jude Date: Wed, 10 Apr 2024 18:42:29 +0100 Subject: [PATCH] Add delete/patch todos --- reminder-dashboard/src/api.ts | 8 ++- .../src/components/Guild/GuildTodos.tsx | 4 +- .../src/components/Todo/CreateTodo.tsx | 4 +- .../src/components/Todo/index.tsx | 68 +++++++++++++++++-- src/web/routes/dashboard/api/guild/todos.rs | 14 +++- 5 files changed, 85 insertions(+), 13 deletions(-) diff --git a/reminder-dashboard/src/api.ts b/reminder-dashboard/src/api.ts index bb336c3..76eca8a 100644 --- a/reminder-dashboard/src/api.ts +++ b/reminder-dashboard/src/api.ts @@ -49,7 +49,7 @@ export type Reminder = { }; export type Todo = { - id: string; + id: number; channel_id: string; value: string; }; @@ -59,6 +59,10 @@ export type CreateTodo = { value: string; }; +export type UpdateTodo = { + value: string; +}; + export type ChannelInfo = { id: string; name: string; @@ -210,7 +214,7 @@ export const fetchGuildTodos = (guild: string) => ({ }); export const patchGuildTodo = (guild: string) => ({ - mutationFn: (todo: Todo) => axios.patch(`/dashboard/api/guild/${guild}/todos`, todo), + mutationFn: ({ id, todo }) => axios.patch(`/dashboard/api/guild/${guild}/todos/${id}`, todo), }); export const postGuildTodo = (guild: string) => ({ diff --git a/reminder-dashboard/src/components/Guild/GuildTodos.tsx b/reminder-dashboard/src/components/Guild/GuildTodos.tsx index c51402e..5e35c2a 100644 --- a/reminder-dashboard/src/components/Guild/GuildTodos.tsx +++ b/reminder-dashboard/src/components/Guild/GuildTodos.tsx @@ -15,7 +15,9 @@ export const GuildTodos = () => { return ; } - const sortedTodos = guildTodos.sort((a, b) => (a.channel_id < b.channel_id ? 0 : 1)); + const sortedTodos = guildTodos + .sort((a, b) => (a.id > b.id ? -1 : 1)) + .sort((a, b) => (a.channel_id < b.channel_id ? 0 : 1)); let prevChannel; return ( diff --git a/reminder-dashboard/src/components/Todo/CreateTodo.tsx b/reminder-dashboard/src/components/Todo/CreateTodo.tsx index f0d661d..a3a0597 100644 --- a/reminder-dashboard/src/components/Todo/CreateTodo.tsx +++ b/reminder-dashboard/src/components/Todo/CreateTodo.tsx @@ -29,7 +29,7 @@ export const CreateTodo = () => { type: "success", }); queryClient.invalidateQueries({ - queryKey: ["GUILD_TODO"], + queryKey: ["GUILD_TODOS", guild], }); setRecentlyCreated(true); setTimeout(() => { @@ -39,8 +39,6 @@ export const CreateTodo = () => { }, }); - console.log(newTodo); - return (