From 5e99a6f9deec59a2cd0a35f35fa5fc8d4cc4e4d3 Mon Sep 17 00:00:00 2001 From: jude Date: Thu, 11 Apr 2024 15:31:27 +0100 Subject: [PATCH] Add create todo under each channel Sort channels for consistency --- reminder-dashboard/src/api.ts | 10 +++++-- .../src/components/Guild/GuildTodos.tsx | 13 ++++++--- .../src/components/Todo/CreateTodo.tsx | 29 +++---------------- 3 files changed, 20 insertions(+), 32 deletions(-) diff --git a/reminder-dashboard/src/api.ts b/reminder-dashboard/src/api.ts index 76eca8a..d97ea1a 100644 --- a/reminder-dashboard/src/api.ts +++ b/reminder-dashboard/src/api.ts @@ -129,9 +129,13 @@ export const fetchGuildInfo = (guild: string) => ({ export const fetchGuildChannels = (guild: string) => ({ queryKey: ["GUILD_CHANNELS", guild], queryFn: () => - axios.get(`/dashboard/api/guild/${guild}/channels`).then((resp) => resp.data) as Promise< - ChannelInfo[] - >, + axios + .get(`/dashboard/api/guild/${guild}/channels`) + .then((resp) => + resp.data.sort((a: ChannelInfo, b: ChannelInfo) => + a.name == b.name ? 0 : a.name > b.name ? 1 : -1, + ), + ) as Promise, staleTime: GUILD_INFO_STALE_TIME, }); diff --git a/reminder-dashboard/src/components/Guild/GuildTodos.tsx b/reminder-dashboard/src/components/Guild/GuildTodos.tsx index 8eb9b77..a811b52 100644 --- a/reminder-dashboard/src/components/Guild/GuildTodos.tsx +++ b/reminder-dashboard/src/components/Guild/GuildTodos.tsx @@ -19,11 +19,15 @@ export const GuildTodos = () => { return ( <> - Create Todo - -
- Todo list

Server

+ {sortedTodos + .filter((todo) => todo.channel_id == null) + .map((todo) => ( + <> + + + ))} + {channels.map((channel) => { return ( <> @@ -35,6 +39,7 @@ export const GuildTodos = () => { ))} + ); })} diff --git a/reminder-dashboard/src/components/Todo/CreateTodo.tsx b/reminder-dashboard/src/components/Todo/CreateTodo.tsx index a3a0597..224efd1 100644 --- a/reminder-dashboard/src/components/Todo/CreateTodo.tsx +++ b/reminder-dashboard/src/components/Todo/CreateTodo.tsx @@ -1,20 +1,19 @@ -import { useMutation, useQuery, useQueryClient } from "react-query"; -import { fetchGuildChannels, postGuildTodo } from "../../api"; +import { useMutation, useQueryClient } from "react-query"; +import { postGuildTodo } from "../../api"; import { useGuild } from "../App/useGuild"; import { useState } from "preact/hooks"; import { useFlash } from "../App/FlashContext"; import { ICON_FLASH_TIME } from "../../consts"; -export const CreateTodo = () => { +export const CreateTodo = ({ channel }) => { const guild = useGuild(); const [recentlyCreated, setRecentlyCreated] = useState(false); - const [newTodo, setNewTodo] = useState({ value: "", channel_id: null }); + const [newTodo, setNewTodo] = useState({ value: "", channel_id: channel }); const flash = useFlash(); const queryClient = useQueryClient(); - const { isSuccess, data: channels } = useQuery(fetchGuildChannels(guild)); const mutation = useMutation({ ...postGuildTodo(guild), onSuccess: (data) => { @@ -45,26 +44,6 @@ export const CreateTodo = () => { class="input todo-input" onInput={(ev) => setNewTodo((todo) => ({ ...todo, value: ev.currentTarget.value }))} /> -
-
- -
-
- -
-