Show all channels and filter todos accordingly

This commit is contained in:
jude 2024-04-11 15:26:24 +01:00
parent 4ee0bc4e37
commit 5406e6b8ec

View File

@ -15,10 +15,7 @@ export const GuildTodos = () => {
return <Loader />;
}
const sortedTodos = guildTodos
.sort((a, b) => (a.id > b.id ? -1 : 1))
.sort((a, b) => (a.channel_id === b.channel_id ? 0 : a.channel_id > b.channel_id ? -1 : 1));
let prevChannel: string;
const sortedTodos = guildTodos.sort((a, b) => (a.id > b.id ? -1 : 1));
return (
<>
@ -26,28 +23,20 @@ export const GuildTodos = () => {
<CreateTodo />
<br />
<strong>Todo list</strong>
{sortedTodos.map((todo) => {
if (prevChannel !== todo.channel_id) {
prevChannel = todo.channel_id;
if (todo.channel_id === null) {
<h2>Server</h2>
{channels.map((channel) => {
return (
<>
<h2>Server Todos</h2>
<Todo todo={todo} key={todo.id} />
</>
);
} else {
const channel = channels.find((ch) => ch.id === todo.channel_id);
return (
<h2>#{channel.name}</h2>
{sortedTodos
.filter((todo) => todo.channel_id == channel.id)
.map((todo) => (
<>
<h2>#{channel.name} Todos</h2>
<Todo todo={todo} key={todo.id} />
</>
))}
</>
);
}
}
return <Todo todo={todo} key={todo.id} />;
})}
</>
);