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; return (
if (todo.channel_id === null) { <>
return ( <h2>#{channel.name}</h2>
<> {sortedTodos
<h2>Server Todos</h2> .filter((todo) => todo.channel_id == channel.id)
<Todo todo={todo} key={todo.id} /> .map((todo) => (
</> <>
); <Todo todo={todo} key={todo.id} />
} else { </>
const channel = channels.find((ch) => ch.id === todo.channel_id); ))}
return ( </>
<> );
<h2>#{channel.name} Todos</h2>
<Todo todo={todo} key={todo.id} />
</>
);
}
}
return <Todo todo={todo} key={todo.id} />;
})} })}
</> </>
); );