feat: restore last active channel on login

- Channel store saves {serverId, channelId} to localStorage on select
- ServerBar restores last server+channel after fetching servers
- Fetches channels for the saved server, then sets the channel if valid
- Gracefully handles missing/deleted servers or channels
This commit is contained in:
2026-07-02 15:44:55 -04:00
parent bca2ad5bcd
commit 883b775c2f
2 changed files with 35 additions and 3 deletions
+13 -1
View File
@@ -48,7 +48,19 @@ export const useChannelStore = create<ChannelState>((set) => ({
}
},
setActiveChannel: (id) => set({ activeChannelId: id }),
setActiveChannel: (id) => {
set({ activeChannelId: id });
if (id) {
// ponytail: persist last active channel for session restore
const state = useChannelStore.getState();
for (const [serverId, channels] of Object.entries(state.channelsByServer)) {
if (channels.some((c) => c.id === id)) {
localStorage.setItem('dumpster:lastChannel', JSON.stringify({ serverId, channelId: id }));
break;
}
}
}
},
addChannel: (channel) =>
set((state) => {