diff --git a/reminder-dashboard/src/api.ts b/reminder-dashboard/src/api.ts
index 086b7bc..bb336c3 100644
--- a/reminder-dashboard/src/api.ts
+++ b/reminder-dashboard/src/api.ts
@@ -54,6 +54,11 @@ export type Todo = {
value: string;
};
+export type CreateTodo = {
+ channel_id: string;
+ value: string;
+};
+
export type ChannelInfo = {
id: string;
name: string;
@@ -209,17 +214,12 @@ export const patchGuildTodo = (guild: string) => ({
});
export const postGuildTodo = (guild: string) => ({
- mutationFn: (reminder: Reminder) =>
- axios.post(`/dashboard/api/guild/${guild}/todos`, reminder).then((resp) => resp.data),
+ mutationFn: (todo: CreateTodo) =>
+ axios.post(`/dashboard/api/guild/${guild}/todos`, todo).then((resp) => resp.data),
});
-export const deleteGuildTodo = () => ({
- mutationFn: (todo: Todo) =>
- axios.delete(`/dashboard/api/todos`, {
- data: {
- id: todo.id,
- },
- }),
+export const deleteGuildTodo = (guild: string) => ({
+ mutationFn: (todoId: number) => axios.delete(`/dashboard/api/guild/${guild}/todos/${todoId}`),
});
export const fetchUserReminders = () => ({
diff --git a/reminder-dashboard/src/components/Guild/index.tsx b/reminder-dashboard/src/components/Guild/index.tsx
index 957f6cd..631d0c2 100644
--- a/reminder-dashboard/src/components/Guild/index.tsx
+++ b/reminder-dashboard/src/components/Guild/index.tsx
@@ -5,6 +5,7 @@ import { createPortal, PropsWithChildren } from "preact/compat";
import { Import } from "../Import";
import { useGuild } from "../App/useGuild";
import { Link } from "wouter";
+import { usePathname } from "wouter/use-browser-location";
import "./index.scss";
@@ -18,13 +19,14 @@ export const Guild = ({ children }: PropsWithChildren) => {
return ;
} else {
const importModal = createPortal(, document.getElementById("bottom-sidebar"));
+ const path = usePathname();
return (
<>
{importModal}
Reminders
@@ -32,7 +34,10 @@ export const Guild = ({ children }: PropsWithChildren) => {
-
+
Todo lists
diff --git a/reminder-dashboard/src/components/Todo/CreateTodo.tsx b/reminder-dashboard/src/components/Todo/CreateTodo.tsx
index b082780..f0d661d 100644
--- a/reminder-dashboard/src/components/Todo/CreateTodo.tsx
+++ b/reminder-dashboard/src/components/Todo/CreateTodo.tsx
@@ -1,18 +1,64 @@
-import { useQuery } from "react-query";
-import { fetchGuildChannels } from "../../api";
+import { useMutation, useQuery, useQueryClient } from "react-query";
+import { fetchGuildChannels, 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 = () => {
const guild = useGuild();
+ const [recentlyCreated, setRecentlyCreated] = useState(false);
+ const [newTodo, setNewTodo] = useState({ value: "", channel_id: null });
+
+ const flash = useFlash();
+
+ const queryClient = useQueryClient();
const { isSuccess, data: channels } = useQuery(fetchGuildChannels(guild));
+ const mutation = useMutation({
+ ...postGuildTodo(guild),
+ onSuccess: (data) => {
+ if (data.error) {
+ flash({
+ message: data.error,
+ type: "error",
+ });
+ } else {
+ flash({
+ message: "Todo created",
+ type: "success",
+ });
+ queryClient.invalidateQueries({
+ queryKey: ["GUILD_TODO"],
+ });
+ setRecentlyCreated(true);
+ setTimeout(() => {
+ setRecentlyCreated(false);
+ }, ICON_FLASH_TIME);
+ }
+ },
+ });
+
+ console.log(newTodo);
return (
diff --git a/src/web/mod.rs b/src/web/mod.rs
index 98bc89a..69cb466 100644
--- a/src/web/mod.rs
+++ b/src/web/mod.rs
@@ -29,9 +29,9 @@ pub mod string {
}
pub mod string_opt {
- use std::fmt::Display;
+ use std::{fmt::Display, str::FromStr};
- use serde::{Deserializer, Serializer};
+ use serde::{de, Deserialize, Deserializer, Serializer};
pub fn serialize(value: &Option, serializer: S) -> Result
where
@@ -44,6 +44,17 @@ pub mod string_opt {
serializer.serialize_none()
}
}
+
+ pub fn deserialize<'de, T, D>(deserializer: D) -> Result