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