diff --git a/CLAUDE.md b/CLAUDE.md
index bd42413..4de2778 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -357,6 +357,18 @@ security only, not the full SaaS-shaped doc — and the judgment call on what co
`renameProject` patches the matching entry's `name`,
`deleteProject` filters it out and clears
`activeProjectId` if it was the one removed).
+ `documentsByProject` (NEW - per-project id, lazy-loaded) is
+ the single shared cache behind `ProjectSidebar.vue`'s own
+ document hierarchy - moved here from a component-local
+ `reactive({})` specifically so `useBatchExtraction.js`/
+ `TransactionsTable.vue`'s "Move to project"/
+ `DocumentNavBar.vue`'s delete can all keep an
+ already-expanded project's list live via
+ `addDocumentToCache`/`removeDocumentFromCache`/
+ `moveDocumentInCache` (each a no-op if that project was
+ never expanded) - see "Sidebar's per-project document list
+ didn't update live" under Key decisions & lessons for the
+ real bug this fixed and the full verification record.
/repositories — raw HTTP/storage access only: extractionRepository.js
(fetch calls to /api/process|recheck|export),
localStorageRepository.js (kept for any future per-viewer
@@ -1509,6 +1521,48 @@ pattern, not new rendering logic needing its own from-scratch verification. Not
machine-verified: whether pages now actually paint on first load without needing a
zoom nudge - Claude-in-Chrome still did not connect this session.
+**Sidebar's per-project document list didn't update live - a real architectural gap,
+fixed by centralizing the cache into `projectsStore`.** Reported: a newly loaded
+document didn't appear under its project in the sidebar, and the user correctly
+anticipated the same gap for a document moved from the transactions view - right
+instinct, confirmed by reading the code: `ProjectSidebar.vue`'s per-project document
+list was a `reactive({})` **local to that one component**, lazy-loaded once per project
+on first expand and then cached indefinitely, with zero way for `useBatchExtraction.js`
+(new document), `TransactionsTable.vue`'s "Move to project", or `DocumentNavBar.vue`'s
+own delete to ever tell it something changed.
+
+Fixed by moving the cache itself into `projectsStore.js` (`documentsByProject`,
+keyed by project id) - the natural owner, since it already holds `projects`/
+`activeProjectId`, and every component that needs to read OR write this cache already
+has access to the shared store, unlike reaching into a sibling component's local state.
+Four new actions: `loadProjectDocuments(projectId)` (the same lazy-fetch-once behavior
+`ProjectSidebar.vue` always had, just relocated), `addDocumentToCache`/
+`removeDocumentFromCache`/`moveDocumentInCache` - each a no-op if that project's list
+was never loaded in the first place (nothing stale to fix - it'll fetch fresh whenever
+it IS expanded), so call sites don't need to know or care whether the sidebar has ever
+touched that project. All three real mutation sites now call the relevant action
+immediately after their own successful backend call: `useBatchExtraction.js` (new
+document → `addDocumentToCache`), `TransactionsTable.vue`'s `confirmMove`
+(→ `moveDocumentInCache`, called before `extractionStore.setActiveDocumentProject`
+mutates the document's own `project` field, so the OLD project id is still readable
+at the moment of the call), and `DocumentNavBar.vue`'s `confirmDelete`
+(→ `removeDocumentFromCache` - this component didn't even import `projectsStore`
+before, now does). `ProjectSidebar.vue`'s own per-document delete already called the
+equivalent local-cache cleanup; now calls the shared store action instead, the same as
+the other three.
+
+Verified end-to-end against the real running PocketBase, not just read: created a
+project, loaded its (empty) cached list, created a document and confirmed
+`addDocumentToCache` made it appear immediately, moved it to a second project and
+confirmed `moveDocumentInCache` removed it from the first project's cache and added it
+to the second's, deleted it and confirmed `removeDocumentFromCache` cleared it - then
+re-fetched the first project's documents directly from PocketBase and confirmed the
+server-side state matched the client-side cache exactly (0, the same as what the cache
+showed) at every step. `npm run build` passes; the `app` container rebuilt;
+`measure.py` unaffected (no backend touched). Not machine-verified: the actual
+sidebar UI reflecting a live update without a manual collapse/re-expand -
+Claude-in-Chrome still did not connect this session.
+
**Governing rule: never silently correct or exclude data.** This shows up in several
concrete places, not just as an abstract principle:
- A row with an unusual status (e.g. HSBC's "Cancelled" wires) stays in the output and is
diff --git a/frontend/src/components/DocumentNavBar.vue b/frontend/src/components/DocumentNavBar.vue
index d518050..0df3851 100644
--- a/frontend/src/components/DocumentNavBar.vue
+++ b/frontend/src/components/DocumentNavBar.vue
@@ -15,11 +15,13 @@
*/
import { computed, ref } from 'vue'
import { useExtractionStore } from '../stores/extractionStore'
+import { useProjectsStore } from '../stores/projectsStore'
import * as documentsService from '../services/documentsService'
import DocumentOptionsModal from './DocumentOptionsModal.vue'
import ConfirmModal from './ConfirmModal.vue'
const extractionStore = useExtractionStore()
+const projectsStore = useProjectsStore()
const positionText = computed(
() => `${extractionStore.activeIndex + 1} of ${extractionStore.documents.length}`,
@@ -62,6 +64,10 @@ async function confirmDelete() {
extractionStore.clearError()
try {
await documentsService.deleteDocument(doc.pbId)
+ // Keeps the sidebar's own per-project document list live if that
+ // project is currently expanded there (a no-op otherwise) - same
+ // reasoning as useBatchExtraction.js's/TransactionsTable's own calls.
+ projectsStore.removeDocumentFromCache(doc.project, doc.pbId)
extractionStore.removeDocument(doc.pbId)
showDeleteConfirm.value = false
} catch (err) {
diff --git a/frontend/src/components/ProjectSidebar.vue b/frontend/src/components/ProjectSidebar.vue
index 12811c3..2ab6f34 100644
--- a/frontend/src/components/ProjectSidebar.vue
+++ b/frontend/src/components/ProjectSidebar.vue
@@ -23,7 +23,7 @@
* inline rename/delete controls hide; icons + the expand toggle stay
* reachable via their own title tooltips.
*/
-import { reactive, ref, computed } from 'vue'
+import { ref, computed } from 'vue'
import { useProjectsStore } from '../stores/projectsStore'
import { useUiStore } from '../stores/uiStore'
import { useExtractionStore } from '../stores/extractionStore'
@@ -106,11 +106,12 @@ async function confirmRename(project) {
// ── Per-project document hierarchy ──────────────────────────────────
// expandedProjects is a reactive Set (Vue 3 proxies Set/Map natively -
// .add/.delete trigger reactivity directly, no need to reassign a new
-// Set each time). projectDocuments is lazy-loaded per project id on
-// first expand and cached for the rest of the session - re-fetched only
-// if a document is added/removed through this same component.
+// Set each time). The document lists themselves live in projectsStore's
+// own documentsByProject (not component-local) specifically so
+// useBatchExtraction.js/TransactionsTable's "Move to project"/
+// DocumentNavBar's delete can all keep an already-expanded project's
+// list live - see projectsStore.js's own comment for the full reasoning.
const expandedProjects = ref(new Set())
-const projectDocuments = reactive({})
const loadingProjectId = ref(null)
async function toggleExpand(project) {
@@ -119,11 +120,11 @@ async function toggleExpand(project) {
return
}
expandedProjects.value.add(project.id)
- if (projectDocuments[project.id]) return
+ if (projectsStore.documentsByProject[project.id]) return
loadingProjectId.value = project.id
errorMessage.value = ''
try {
- projectDocuments[project.id] = await documentsService.listDocuments({ project: project.id })
+ await projectsStore.loadProjectDocuments(project.id)
} catch (e) {
errorMessage.value = `Could not load "${project.name}"'s documents: ` + e.message
expandedProjects.value.delete(project.id)
@@ -168,9 +169,7 @@ async function confirmDeleteDoc() {
errorMessage.value = ''
try {
await documentsService.deleteDocument(doc.id)
- if (projectDocuments[doc.project]) {
- projectDocuments[doc.project] = projectDocuments[doc.project].filter((d) => d.id !== doc.id)
- }
+ projectsStore.removeDocumentFromCache(doc.project, doc.id)
// Keeps the main workspace in sync too, if this document happened to
// be loaded there (removeDocument is a harmless no-op otherwise).
extractionStore.removeDocument(doc.id)
@@ -248,8 +247,8 @@ async function confirmDeleteDoc() {
Loading…
-