From 9989ab3b354578cd1d995f698d52adb5a2da602c Mon Sep 17 00:00:00 2001 From: jude Date: Sat, 6 Apr 2024 14:27:58 +0100 Subject: [PATCH] Start work on todo list support for dashboard --- reminder-dashboard/src/api.ts | 33 ++++++++++ .../src/components/App/index.tsx | 19 +++++- .../src/components/Guild/GuildTodos.tsx | 21 ++++++ .../src/components/Guild/index.tsx | 7 +- .../src/components/Todo/index.tsx | 23 +++++++ src/web/mod.rs | 4 ++ src/web/routes/dashboard/api/guild/mod.rs | 2 + src/web/routes/dashboard/api/guild/todos.rs | 66 +++++++++++++++++++ 8 files changed, 170 insertions(+), 5 deletions(-) create mode 100644 reminder-dashboard/src/components/Guild/GuildTodos.tsx create mode 100644 reminder-dashboard/src/components/Todo/index.tsx create mode 100644 src/web/routes/dashboard/api/guild/todos.rs diff --git a/reminder-dashboard/src/api.ts b/reminder-dashboard/src/api.ts index 12141bb..c61549a 100644 --- a/reminder-dashboard/src/api.ts +++ b/reminder-dashboard/src/api.ts @@ -49,6 +49,12 @@ export type Reminder = { utc_time: string; }; +export type Todo = { + id: string; + channel_id: string; + value: string; +}; + export type ChannelInfo = { id: string; name: string; @@ -190,6 +196,33 @@ export const deleteGuildTemplate = (guild: string) => ({ }), }); +export const fetchGuildTodos = (guild: string) => ({ + queryKey: ["GUILD_TODOS", guild], + queryFn: () => + axios.get(`/dashboard/api/guild/${guild}/todos`).then((resp) => resp.data) as Promise< + Todo[] + >, + staleTime: OTHER_STALE_TIME, +}); + +export const patchGuildTodo = (guild: string) => ({ + mutationFn: (todo: Todo) => axios.patch(`/dashboard/api/guild/${guild}/todos`, todo), +}); + +export const postGuildTodo = (guild: string) => ({ + mutationFn: (reminder: Reminder) => + axios.post(`/dashboard/api/guild/${guild}/todos`, reminder).then((resp) => resp.data), +}); + +export const deleteGuildTodo = () => ({ + mutationFn: (todo: Todo) => + axios.delete(`/dashboard/api/todos`, { + data: { + id: todo.id, + }, + }), +}); + export const fetchUserReminders = () => ({ queryKey: ["USER_REMINDERS"], queryFn: () => diff --git a/reminder-dashboard/src/components/App/index.tsx b/reminder-dashboard/src/components/App/index.tsx index 40c922a..d8230f0 100644 --- a/reminder-dashboard/src/components/App/index.tsx +++ b/reminder-dashboard/src/components/App/index.tsx @@ -6,6 +6,8 @@ import { Guild } from "../Guild"; import { FlashProvider } from "./FlashProvider"; import { TimezoneProvider } from "./TimezoneProvider"; import { User } from "../User"; +import { GuildReminders } from "../Guild/GuildReminders"; +import { GuildTodos } from "../Guild/GuildTodos"; export function App() { const queryClient = new QueryClient(); @@ -20,7 +22,22 @@ export function App() {
- + ( + + + + )} + > + + + + } + > diff --git a/reminder-dashboard/src/components/Guild/GuildTodos.tsx b/reminder-dashboard/src/components/Guild/GuildTodos.tsx new file mode 100644 index 0000000..22b72bd --- /dev/null +++ b/reminder-dashboard/src/components/Guild/GuildTodos.tsx @@ -0,0 +1,21 @@ +import { useQuery, useQueryClient } from "react-query"; +import { fetchGuildChannels, fetchGuildTodos } from "../../api"; +import { useState } from "preact/hooks"; +import { useGuild } from "../App/useGuild"; + +export const GuildTodos = () => { + const guild = useGuild(); + + const { + isSuccess, + isFetching, + isFetched, + data: guildReminders, + } = useQuery(fetchGuildTodos(guild)); + const { data: channels } = useQuery(fetchGuildChannels(guild)); + + const [collapsed, setCollapsed] = useState(false); + const queryClient = useQueryClient(); + + return <>; +}; diff --git a/reminder-dashboard/src/components/Guild/index.tsx b/reminder-dashboard/src/components/Guild/index.tsx index 9b3126e..487154f 100644 --- a/reminder-dashboard/src/components/Guild/index.tsx +++ b/reminder-dashboard/src/components/Guild/index.tsx @@ -1,12 +1,11 @@ import { useQuery } from "react-query"; import { fetchGuildInfo } from "../../api"; -import { GuildReminders } from "./GuildReminders"; import { GuildError } from "./GuildError"; -import { createPortal } from "preact/compat"; +import { createPortal, PropsWithChildren } from "preact/compat"; import { Import } from "../Import"; import { useGuild } from "../App/useGuild"; -export const Guild = () => { +export const Guild = ({ children }: PropsWithChildren) => { const guild = useGuild(); const { isSuccess, data: guildInfo } = useQuery(fetchGuildInfo(guild)); @@ -20,7 +19,7 @@ export const Guild = () => { return ( <> {importModal} - + {children} ); } diff --git a/reminder-dashboard/src/components/Todo/index.tsx b/reminder-dashboard/src/components/Todo/index.tsx new file mode 100644 index 0000000..d412671 --- /dev/null +++ b/reminder-dashboard/src/components/Todo/index.tsx @@ -0,0 +1,23 @@ +import { Todo as TodoT } from "../../api"; + +type Props = { + todo: TodoT; +}; + +export const Todo = ({ todo }: Props) => { + return ( +
+