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