Add create todo under each channel
Sort channels for consistency
This commit is contained in:
parent
5406e6b8ec
commit
b265c3a8dc
@ -129,9 +129,13 @@ export const fetchGuildInfo = (guild: string) => ({
|
|||||||
export const fetchGuildChannels = (guild: string) => ({
|
export const fetchGuildChannels = (guild: string) => ({
|
||||||
queryKey: ["GUILD_CHANNELS", guild],
|
queryKey: ["GUILD_CHANNELS", guild],
|
||||||
queryFn: () =>
|
queryFn: () =>
|
||||||
axios.get(`/dashboard/api/guild/${guild}/channels`).then((resp) => resp.data) as Promise<
|
axios
|
||||||
ChannelInfo[]
|
.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<ChannelInfo[]>,
|
||||||
staleTime: GUILD_INFO_STALE_TIME,
|
staleTime: GUILD_INFO_STALE_TIME,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -19,10 +19,6 @@ export const GuildTodos = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<strong>Create Todo</strong>
|
|
||||||
<CreateTodo />
|
|
||||||
<br />
|
|
||||||
<strong>Todo list</strong>
|
|
||||||
<h2>Server</h2>
|
<h2>Server</h2>
|
||||||
{channels.map((channel) => {
|
{channels.map((channel) => {
|
||||||
return (
|
return (
|
||||||
@ -35,6 +31,7 @@ export const GuildTodos = () => {
|
|||||||
<Todo todo={todo} key={todo.id} />
|
<Todo todo={todo} key={todo.id} />
|
||||||
</>
|
</>
|
||||||
))}
|
))}
|
||||||
|
<CreateTodo channel={channel.id} />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
@ -1,20 +1,19 @@
|
|||||||
import { useMutation, useQuery, useQueryClient } from "react-query";
|
import { useMutation, useQueryClient } from "react-query";
|
||||||
import { fetchGuildChannels, postGuildTodo } from "../../api";
|
import { postGuildTodo } from "../../api";
|
||||||
import { useGuild } from "../App/useGuild";
|
import { useGuild } from "../App/useGuild";
|
||||||
import { useState } from "preact/hooks";
|
import { useState } from "preact/hooks";
|
||||||
import { useFlash } from "../App/FlashContext";
|
import { useFlash } from "../App/FlashContext";
|
||||||
import { ICON_FLASH_TIME } from "../../consts";
|
import { ICON_FLASH_TIME } from "../../consts";
|
||||||
|
|
||||||
export const CreateTodo = () => {
|
export const CreateTodo = ({ channel }) => {
|
||||||
const guild = useGuild();
|
const guild = useGuild();
|
||||||
|
|
||||||
const [recentlyCreated, setRecentlyCreated] = useState(false);
|
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 flash = useFlash();
|
||||||
|
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const { isSuccess, data: channels } = useQuery(fetchGuildChannels(guild));
|
|
||||||
const mutation = useMutation({
|
const mutation = useMutation({
|
||||||
...postGuildTodo(guild),
|
...postGuildTodo(guild),
|
||||||
onSuccess: (data) => {
|
onSuccess: (data) => {
|
||||||
@ -45,26 +44,6 @@ export const CreateTodo = () => {
|
|||||||
class="input todo-input"
|
class="input todo-input"
|
||||||
onInput={(ev) => setNewTodo((todo) => ({ ...todo, value: ev.currentTarget.value }))}
|
onInput={(ev) => setNewTodo((todo) => ({ ...todo, value: ev.currentTarget.value }))}
|
||||||
/>
|
/>
|
||||||
<div class="control has-icons-left">
|
|
||||||
<div class="select">
|
|
||||||
<select
|
|
||||||
name="channel"
|
|
||||||
class="channel-selector"
|
|
||||||
onInput={(ev) =>
|
|
||||||
setNewTodo((todo) => ({
|
|
||||||
...todo,
|
|
||||||
channel_id: ev.currentTarget.value || null,
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<option value="">(None)</option>
|
|
||||||
{isSuccess && channels.map((c) => <option value={c.id}>{c.name}</option>)}
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div class="icon is-small is-left">
|
|
||||||
<i class="fas fa-hashtag"></i>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<button onClick={() => mutation.mutate(newTodo)} class="button is-success save-btn">
|
<button onClick={() => mutation.mutate(newTodo)} class="button is-success save-btn">
|
||||||
<span class="icon">
|
<span class="icon">
|
||||||
{mutation.isLoading ? (
|
{mutation.isLoading ? (
|
||||||
|
Loading…
Reference in New Issue
Block a user