From c1a49cc6274ca8ed08e75f5c3d35f48cafb45c9b Mon Sep 17 00:00:00 2001 From: vodyanoysh Date: Tue, 31 Mar 2026 23:05:24 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D0=B0=D1=82=D1=8C=20=D1=81=D1=87=D1=91=D1=82=D1=87?= =?UTF-8?q?=D0=B8=D0=BA=20=D0=BD=D0=B5=D0=BF=D1=80=D0=BE=D1=87=D0=B8=D1=82?= =?UTF-8?q?=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20=D0=BD=D0=B0=20=D0=BF=D0=BB?= =?UTF-8?q?=D0=BE=D1=81=D0=BA=D0=B8=D0=B9=20ref?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Вместо мутации вложенных свойств дерева папок использовать отдельный плоский ref> (ключ accountId:folderId). Это гарантирует реактивность при любых изменениях счётчика. - folders.store: unreadCounts, initUnreadCounts, getFolderUnread - MessageList: activeUnread computed читает из getFolderUnread - FolderTreeItem: unreadCount computed читает из getFolderUnread, не зависит от folder.unreadCount prop Co-Authored-By: Claude Sonnet 4.6 --- .../src/components/messages/MessageList.vue | 8 +++- .../src/components/sidebar/FolderTreeItem.vue | 10 ++++- src/renderer/src/stores/folders.store.ts | 39 +++++++++++-------- 3 files changed, 36 insertions(+), 21 deletions(-) diff --git a/src/renderer/src/components/messages/MessageList.vue b/src/renderer/src/components/messages/MessageList.vue index 298a664..cc5845b 100644 --- a/src/renderer/src/components/messages/MessageList.vue +++ b/src/renderer/src/components/messages/MessageList.vue @@ -16,6 +16,10 @@ const selectMode = ref(false) const folderName = computed(() => foldersStore.activeFolder?.name ?? '') const hasSelected = computed(() => messagesStore.selectedIds.size > 0) +const activeUnread = computed(() => { + if (!accountsStore.activeAccountId || !foldersStore.activeFolderId) return 0 + return foldersStore.getFolderUnread(accountsStore.activeAccountId, foldersStore.activeFolderId) +}) const allVisibleSelected = computed(() => messagesStore.filteredMessages.length > 0 && messagesStore.filteredMessages.every((m) => messagesStore.selectedIds.has(m.id)) @@ -136,13 +140,13 @@ async function handleSwipeAction(action: SwipeAction, messageId: string): Promis

{{ folderName }}

diff --git a/src/renderer/src/stores/folders.store.ts b/src/renderer/src/stores/folders.store.ts index 3abd6af..8f0afe0 100644 --- a/src/renderer/src/stores/folders.store.ts +++ b/src/renderer/src/stores/folders.store.ts @@ -13,6 +13,10 @@ export const useFoldersStore = defineStore('folders', () => { const activeFolderId = ref(null) const loading = ref(false) + // Плоский счётчик непрочитанных: ключ `${accountId}:${folderId}` + // Хранится отдельно от дерева — гарантированно реактивен + const unreadCounts = ref>({}) + const folders = computed(() => { if (!accountsStore.activeAccountId) return [] return foldersByAccount.value[accountsStore.activeAccountId] ?? [] @@ -27,6 +31,7 @@ export const useFoldersStore = defineStore('folders', () => { try { const result = await invoke('folders:list', { accountId }) foldersByAccount.value[accountId] = result.folders + initUnreadCounts(accountId, result.folders) // Auto-select inbox const inbox = findFolderByRole(result.folders, SpecialFolderRole.Inbox) @@ -44,10 +49,21 @@ export const useFoldersStore = defineStore('folders', () => { activeFolderId.value = folderId } + function initUnreadCounts(accountId: string, folders: Folder[]): void { + for (const f of folders) { + unreadCounts.value[`${accountId}:${f.id}`] = f.unreadCount + if (f.children.length > 0) initUnreadCounts(accountId, f.children) + } + } + function updateFolderUnread(accountId: string, folderId: string, delta: number): void { - const tree = foldersByAccount.value[accountId] - if (!tree) return - patchUnreadInTree(tree, folderId, delta) + const key = `${accountId}:${folderId}` + const current = unreadCounts.value[key] ?? 0 + unreadCounts.value[key] = Math.max(0, current + delta) + } + + function getFolderUnread(accountId: string, folderId: string): number { + return unreadCounts.value[`${accountId}:${folderId}`] ?? 0 } // Auto-load folders when active account changes @@ -74,28 +90,17 @@ export const useFoldersStore = defineStore('folders', () => { return { foldersByAccount, folders, + unreadCounts, activeFolderId, activeFolder, loading, loadFolders, setActiveFolder, - updateFolderUnread + updateFolderUnread, + getFolderUnread } }) -// Заменяет элемент массива целиком — гарантированно триггерит Vue-реактивность -function patchUnreadInTree(folders: Folder[], folderId: string, delta: number): boolean { - for (let i = 0; i < folders.length; i++) { - if (folders[i].id === folderId) { - folders[i] = { ...folders[i], unreadCount: Math.max(0, folders[i].unreadCount + delta) } - return true - } - if (folders[i].children.length > 0 && patchUnreadInTree(folders[i].children, folderId, delta)) { - return true - } - } - return false -} function findFolderById(folders: Folder[], id: string | null): Folder | null { if (!id) return null