diff --git a/web/src/components/ServerBar.tsx b/web/src/components/ServerBar.tsx index 121718e..af55728 100644 --- a/web/src/components/ServerBar.tsx +++ b/web/src/components/ServerBar.tsx @@ -34,8 +34,28 @@ export function ServerBar() { const { showMenu, MenuPortal } = useContextMenu(); useEffect(() => { - fetchServers(); - }, [fetchServers]); + fetchServers().then(() => { + // ponytail: restore last active server + channel from localStorage + try { + const raw = localStorage.getItem('dumpster:lastChannel'); + if (raw) { + const { serverId, channelId } = JSON.parse(raw); + const srv = useServerStore.getState().servers.find((s) => s.id === serverId); + if (srv) { + setActiveServer(serverId); + setDM(false); + // Fetch channels then restore the channel + useChannelStore.getState().fetchChannels(serverId).then(() => { + const ch = useChannelStore.getState().channelsByServer[serverId]?.find((c) => c.id === channelId); + if (ch) { + setActiveChannel(channelId); + } + }); + } + } + } catch { /* ignore bad localStorage */ } + }); + }, [fetchServers, setActiveServer, setActiveChannel, setDM]); const handleSelect = (id: string) => { setActiveServer(id); diff --git a/web/src/stores/channel.ts b/web/src/stores/channel.ts index 1714e79..3c03551 100644 --- a/web/src/stores/channel.ts +++ b/web/src/stores/channel.ts @@ -48,7 +48,19 @@ export const useChannelStore = create((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) => {