refac
This commit is contained in:
1 parent
a2000df253
commit
743b9fd3ce
12 files changed
+98
-91
No files matched your search
@@ -3,7 +3,7 @@ import { getChatList, getPinnedChatList } from '$lib/apis/chats';
|
||||
|
||||
type ChatListItem = {
|
||||
id: string;
|
||||
[key: string]: any;
|
||||
[key: string]: unknown;
|
||||
};
|
||||
|
||||
const chatsStore = writable<ChatListItem[] | null>(null);
|
||||
@@ -90,6 +90,21 @@ export const loadNextChatListPage = async (token: string = ''): Promise<ChatList
|
||||
}
|
||||
};
|
||||
|
||||
export const setChatActive = (chatId: string, active: boolean): boolean => {
|
||||
let found = false;
|
||||
const updateChat = (chat: ChatListItem) => {
|
||||
if (chat.id !== chatId) {
|
||||
return chat;
|
||||
}
|
||||
found = true;
|
||||
return { ...chat, active };
|
||||
};
|
||||
|
||||
chatsStore.update((items) => (items ? items.map(updateChat) : items));
|
||||
pinnedChatsStore.update((items) => items.map(updateChat));
|
||||
return found;
|
||||
};
|
||||
|
||||
export const resetChatListState = () => {
|
||||
requestGeneration += 1;
|
||||
currentPage = 1;
|
||||
|
||||
Reference in new issue
Block a user