From f4a1187fdf7de1e0aa47dc1d43c1b7b253a1a415 Mon Sep 17 00:00:00 2001 From: Ai Date: Sat, 23 May 2026 18:06:52 +0300 Subject: [PATCH] fix: re-sort chat list after pin so pinned chats move to top Co-Authored-By: Claude Sonnet 4.6 --- frontend/src/store/index.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/frontend/src/store/index.ts b/frontend/src/store/index.ts index 3418150..3c84188 100644 --- a/frontend/src/store/index.ts +++ b/frontend/src/store/index.ts @@ -53,10 +53,20 @@ export const useStore = create((set, get) => ({ setChats: (chats) => set({ chats, chatsLoading: false }), setChatsLoading: (v) => set({ chatsLoading: v }), - updateChat: (partial) => set(state => ({ - chats: state.chats.map(c => c.id === partial.id ? { ...c, ...partial } : c), - activeChat: state.activeChat?.id === partial.id ? { ...state.activeChat, ...partial } : state.activeChat, - })), + updateChat: (partial) => set(state => { + const updated = state.chats.map(c => c.id === partial.id ? { ...c, ...partial } : c); + updated.sort((a, b) => { + if (a.isPinned && !b.isPinned) return -1; + if (!a.isPinned && b.isPinned) return 1; + const ta = a.lastMessageAt || a.createdAt; + const tb = b.lastMessageAt || b.createdAt; + return new Date(tb).getTime() - new Date(ta).getTime(); + }); + return { + chats: updated, + activeChat: state.activeChat?.id === partial.id ? { ...state.activeChat, ...partial } : state.activeChat, + }; + }), setActiveChat: (chat) => set({ activeChat: chat }),