sidebar: sort channels by last opened (localStorage)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -108,11 +108,21 @@ export default function App() {
|
|||||||
const messagesById = new Map(messages.map((m) => [m.id, m]));
|
const messagesById = new Map(messages.map((m) => [m.id, m]));
|
||||||
const activeChannel = channels.find((c) => c.id === activeChannelId);
|
const activeChannel = channels.find((c) => c.id === activeChannelId);
|
||||||
|
|
||||||
|
// Sort channels by last opened (stored in localStorage)
|
||||||
|
function getLastOpened(channelId: string): number {
|
||||||
|
return Number(localStorage.getItem(`colony_last_opened_${channelId}`)) || 0;
|
||||||
|
}
|
||||||
|
function markOpened(channelId: string) {
|
||||||
|
localStorage.setItem(`colony_last_opened_${channelId}`, String(Date.now()));
|
||||||
|
}
|
||||||
|
const sortedChannels = [...channels].sort((a, b) => getLastOpened(b.id) - getLastOpened(a.id));
|
||||||
|
|
||||||
const sidebar = (
|
const sidebar = (
|
||||||
<ChannelSidebar
|
<ChannelSidebar
|
||||||
channels={channels}
|
channels={sortedChannels}
|
||||||
activeId={activeChannelId}
|
activeId={activeChannelId}
|
||||||
onSelect={(id) => {
|
onSelect={(id) => {
|
||||||
|
markOpened(id);
|
||||||
setActiveChannelId(id);
|
setActiveChannelId(id);
|
||||||
setSheetOpen(false);
|
setSheetOpen(false);
|
||||||
}}
|
}}
|
||||||
|
|||||||
Reference in New Issue
Block a user