From cfb123dda26256dcebf116f159771c04f695676c Mon Sep 17 00:00:00 2001 From: matevip Date: Mon, 18 May 2026 23:28:56 +0800 Subject: [PATCH] fix(wiki): keep the raw-material filter across page-list refreshes (#156) --- mateclaw-ui/src/stores/useAgentStore.ts | 8 +++++++- mateclaw-ui/src/stores/useCronJobStore.ts | 8 +++++++- mateclaw-ui/src/stores/useMemoryStore.ts | 8 +++++++- mateclaw-ui/src/stores/useThemeStore.ts | 8 +++++++- mateclaw-ui/src/stores/useWikiStore.ts | 18 ++++++++++++++---- mateclaw-ui/src/stores/useWorkspaceStore.ts | 8 +++++++- .../views/Wiki/components/WikiPageSidebar.vue | 6 ++++-- .../views/Wiki/components/WikiPageViewer.vue | 3 ++- 8 files changed, 55 insertions(+), 12 deletions(-) diff --git a/mateclaw-ui/src/stores/useAgentStore.ts b/mateclaw-ui/src/stores/useAgentStore.ts index 925309ed..168c437a 100644 --- a/mateclaw-ui/src/stores/useAgentStore.ts +++ b/mateclaw-ui/src/stores/useAgentStore.ts @@ -1,4 +1,4 @@ -import { defineStore } from 'pinia' +import { acceptHMRUpdate, defineStore } from 'pinia' import { ref } from 'vue' import { agentApi } from '@/api/index' import type { Agent } from '@/types/index' @@ -41,3 +41,9 @@ export const useAgentStore = defineStore('agent', () => { return { agents, loading, fetchAgents, createAgent, updateAgent, deleteAgent } }) + +// Enable HMR for this store: editing it during `pnpm dev` patches the live +// store instead of requiring a full page reload. Stripped from prod builds. +if (import.meta.hot) { + import.meta.hot.accept(acceptHMRUpdate(useAgentStore, import.meta.hot)) +} diff --git a/mateclaw-ui/src/stores/useCronJobStore.ts b/mateclaw-ui/src/stores/useCronJobStore.ts index 2adb4b3d..237b5b99 100644 --- a/mateclaw-ui/src/stores/useCronJobStore.ts +++ b/mateclaw-ui/src/stores/useCronJobStore.ts @@ -1,4 +1,4 @@ -import { defineStore } from 'pinia' +import { acceptHMRUpdate, defineStore } from 'pinia' import { ref } from 'vue' import { cronJobApi } from '@/api/index' import type { CronJob } from '@/types/index' @@ -51,3 +51,9 @@ export const useCronJobStore = defineStore('cronJob', () => { return { jobs, loading, fetchJobs, createJob, updateJob, deleteJob, toggleJob, runNow } }) + +// Enable HMR for this store: editing it during `pnpm dev` patches the live +// store instead of requiring a full page reload. Stripped from prod builds. +if (import.meta.hot) { + import.meta.hot.accept(acceptHMRUpdate(useCronJobStore, import.meta.hot)) +} diff --git a/mateclaw-ui/src/stores/useMemoryStore.ts b/mateclaw-ui/src/stores/useMemoryStore.ts index 05dcf249..d4726174 100644 --- a/mateclaw-ui/src/stores/useMemoryStore.ts +++ b/mateclaw-ui/src/stores/useMemoryStore.ts @@ -1,4 +1,4 @@ -import { defineStore } from 'pinia' +import { acceptHMRUpdate, defineStore } from 'pinia' import { ref } from 'vue' import { http } from '@/api' @@ -85,3 +85,9 @@ export const useMemoryStore = defineStore('memory', () => { subscribeEvents, unsubscribeEvents, } }) + +// Enable HMR for this store: editing it during `pnpm dev` patches the live +// store instead of requiring a full page reload. Stripped from prod builds. +if (import.meta.hot) { + import.meta.hot.accept(acceptHMRUpdate(useMemoryStore, import.meta.hot)) +} diff --git a/mateclaw-ui/src/stores/useThemeStore.ts b/mateclaw-ui/src/stores/useThemeStore.ts index db00551a..d2637658 100644 --- a/mateclaw-ui/src/stores/useThemeStore.ts +++ b/mateclaw-ui/src/stores/useThemeStore.ts @@ -1,4 +1,4 @@ -import { defineStore } from 'pinia' +import { acceptHMRUpdate, defineStore } from 'pinia' import { ref, watch } from 'vue' export type ThemeMode = 'light' | 'dark' | 'system' @@ -48,3 +48,9 @@ export const useThemeStore = defineStore('theme', () => { return { mode, isDark, setMode, toggle } }) + +// Enable HMR for this store: editing it during `pnpm dev` patches the live +// store instead of requiring a full page reload. Stripped from prod builds. +if (import.meta.hot) { + import.meta.hot.accept(acceptHMRUpdate(useThemeStore, import.meta.hot)) +} diff --git a/mateclaw-ui/src/stores/useWikiStore.ts b/mateclaw-ui/src/stores/useWikiStore.ts index 50d9aa35..df0d5a62 100644 --- a/mateclaw-ui/src/stores/useWikiStore.ts +++ b/mateclaw-ui/src/stores/useWikiStore.ts @@ -1,4 +1,4 @@ -import { defineStore } from 'pinia' +import { acceptHMRUpdate, defineStore } from 'pinia' import { ref } from 'vue' import { wikiApi } from '@/api/index' @@ -129,14 +129,18 @@ export const useWikiStore = defineStore('wiki', () => { if (!rawId) totalPageCount.value = pages.value.length } - async function refreshCurrentKB(options: { preserveRawFilter?: boolean } = {}) { + // Background refreshes (job completion, SSE events, fallback polling) must + // not drop the user's active raw-material filter. Re-fetch the page list + // scoped to selectedRawId whenever a filter is applied — otherwise the list + // silently reverts to every material's pages while the filter banner still + // claims a filter is active. + async function refreshCurrentKB() { if (!currentKB.value) return const kbId = currentKB.value.id - const rawId = options.preserveRawFilter ? selectedRawId.value : null const [kbRes] = await Promise.all([ wikiApi.getKB(kbId), fetchRawMaterials(kbId), - fetchPages(kbId, rawId ?? undefined), + fetchPages(kbId, selectedRawId.value ?? undefined), ]) const nextKB = (kbRes as any).data || kbRes currentKB.value = nextKB @@ -221,3 +225,9 @@ export const useWikiStore = defineStore('wiki', () => { scanDirectory, } }) + +// Enable HMR for this store: editing it during `pnpm dev` patches the live +// store instead of requiring a full page reload. Stripped from prod builds. +if (import.meta.hot) { + import.meta.hot.accept(acceptHMRUpdate(useWikiStore, import.meta.hot)) +} diff --git a/mateclaw-ui/src/stores/useWorkspaceStore.ts b/mateclaw-ui/src/stores/useWorkspaceStore.ts index 01935f4b..e85faae8 100644 --- a/mateclaw-ui/src/stores/useWorkspaceStore.ts +++ b/mateclaw-ui/src/stores/useWorkspaceStore.ts @@ -1,4 +1,4 @@ -import { defineStore } from 'pinia' +import { acceptHMRUpdate, defineStore } from 'pinia' import { ref, computed } from 'vue' import { workspaceTeamApi } from '@/api/index' import type { Capability, WorkspaceRole } from '@/composables/capabilities' @@ -126,3 +126,9 @@ export const useWorkspaceStore = defineStore('workspace', () => { refreshAccess, } }) + +// Enable HMR for this store: editing it during `pnpm dev` patches the live +// store instead of requiring a full page reload. Stripped from prod builds. +if (import.meta.hot) { + import.meta.hot.accept(acceptHMRUpdate(useWorkspaceStore, import.meta.hot)) +} diff --git a/mateclaw-ui/src/views/Wiki/components/WikiPageSidebar.vue b/mateclaw-ui/src/views/Wiki/components/WikiPageSidebar.vue index a35c6ee1..8b50e5c7 100644 --- a/mateclaw-ui/src/views/Wiki/components/WikiPageSidebar.vue +++ b/mateclaw-ui/src/views/Wiki/components/WikiPageSidebar.vue @@ -295,7 +295,8 @@ async function handleBatchDelete() { try { await wikiApi.batchDeletePages(store.currentKB.id, selectedSlugs.value) exitBatchMode() - await store.fetchPages(store.currentKB.id) + // Keep the active raw-material filter so the list doesn't jump to all pages. + await store.fetchPages(store.currentKB.id, store.selectedRawId) } catch (e: any) { alert(e?.message || 'Batch delete failed') } @@ -322,7 +323,8 @@ async function restoreArchivedPage(slug: string) { try { await wikiApi.unarchivePage(store.currentKB.id, slug) archivedPages.value = archivedPages.value.filter(p => p.slug !== slug) - await store.fetchPages(store.currentKB.id) + // Keep the active raw-material filter so the list doesn't jump to all pages. + await store.fetchPages(store.currentKB.id, store.selectedRawId) } catch (e: any) { console.error('[Wiki] Unarchive failed', e) alert(e?.message || 'Unarchive failed') diff --git a/mateclaw-ui/src/views/Wiki/components/WikiPageViewer.vue b/mateclaw-ui/src/views/Wiki/components/WikiPageViewer.vue index 08958647..74775dfb 100644 --- a/mateclaw-ui/src/views/Wiki/components/WikiPageViewer.vue +++ b/mateclaw-ui/src/views/Wiki/components/WikiPageViewer.vue @@ -186,7 +186,8 @@ async function handleDelete() { try { await wikiApi.deletePage(store.currentKB.id, store.currentPage.slug) store.currentPage = null - await store.fetchPages(store.currentKB.id) + // Keep the active raw-material filter so the list doesn't jump to all pages. + await store.fetchPages(store.currentKB.id, store.selectedRawId) } catch (e: any) { alert(e?.message || 'Delete failed') }