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:
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user