fix: re-sort chat list after pin so pinned chats move to top

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Ai
2026-05-23 18:06:52 +03:00
parent 3a8c5be1ae
commit f4a1187fdf

View File

@@ -53,10 +53,20 @@ export const useStore = create<AppStore>((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 }),