Keep the sidebar's per-project document list live across the app
Reported: a newly loaded document didn't show up under its project in
the sidebar, with the same gap correctly anticipated for a document
moved from the transactions view.
Root cause: ProjectSidebar.vue's own per-project document list was a
reactive({}) local to that one component, lazy-loaded once per project
on first expand and cached indefinitely - nothing else in the app had
any way to tell it something changed.
Moved the cache into projectsStore.js (documentsByProject, keyed by
project id) - the natural shared owner. Four new actions:
loadProjectDocuments (the same lazy-fetch-once behavior, just
relocated), addDocumentToCache/removeDocumentFromCache/
moveDocumentInCache, each a no-op if that project was never expanded
so call sites don't need to know or care. All three real mutation
sites now call the relevant action right after their own successful
backend call: useBatchExtraction.js (new document), TransactionsTable's
"Move to project" (called before the document's own project field is
mutated, so the old project id is still readable), and
DocumentNavBar's delete (which didn't even import projectsStore
before). ProjectSidebar's own per-document delete now calls the same
shared action instead of mutating local state.
Verified end-to-end against the real running PocketBase: created a
project, loaded its cache, created a document and confirmed it
appeared immediately, moved it to a second project and confirmed it
left the first project's cache and entered the second's, deleted it
and confirmed it cleared - then re-fetched directly from PocketBase
and confirmed server-side state matched the client cache exactly at
every step. measure.py unaffected (no backend touched). Not
machine-verified: the sidebar UI itself reflecting this without a
manual collapse/re-expand - Claude-in-Chrome did not connect this
session.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
4c0973b6b5
commit
deee78a6c1
54
CLAUDE.md
54
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
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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() {
|
|||
<i class="fa-solid fa-spinner fa-spin"></i> Loading…
|
||||
</li>
|
||||
<template v-else>
|
||||
<li v-if="!projectDocuments[p.id]?.length" class="project-doc-empty">No documents</li>
|
||||
<li v-for="doc in projectDocuments[p.id]" :key="doc.id" class="project-doc-item">
|
||||
<li v-if="!projectsStore.documentsByProject[p.id]?.length" class="project-doc-empty">No documents</li>
|
||||
<li v-for="doc in projectsStore.documentsByProject[p.id]" :key="doc.id" class="project-doc-item">
|
||||
<button type="button" class="project-doc-name" :title="doc.fileName" @click="openDocument(doc)">
|
||||
<i class="fa-solid fa-file-lines"></i>
|
||||
<span>{{ doc.fileName }}</span>
|
||||
|
|
|
|||
|
|
@ -236,6 +236,10 @@ async function confirmMove() {
|
|||
extractionStore.clearError()
|
||||
try {
|
||||
await documentsService.moveToProject(doc.pbId, projectId)
|
||||
// Keeps the sidebar's own per-project document lists live if either
|
||||
// the old or new project is currently expanded there (each a no-op
|
||||
// otherwise) - same reasoning as useBatchExtraction.js's own call.
|
||||
projectsStore.moveDocumentInCache(doc.project, projectId, { id: doc.pbId, fileName: doc.fileName })
|
||||
extractionStore.setActiveDocumentProject(projectId)
|
||||
clearTimeout(moveConfirmNoteTimer)
|
||||
moveConfirmNote.value = `Moved to ${projectName}`
|
||||
|
|
|
|||
|
|
@ -64,6 +64,10 @@ export function useBatchExtraction() {
|
|||
project: projectsStore.activeProjectId,
|
||||
openingBalanceInput, closingBalanceInput,
|
||||
})
|
||||
// Keeps the sidebar's own per-project document list live if
|
||||
// that project is currently expanded there - a no-op otherwise
|
||||
// (see projectsStore.js's own comment on why this cache exists).
|
||||
projectsStore.addDocumentToCache(record.project, record)
|
||||
extractionStore.addDocument({
|
||||
pbId: record.id,
|
||||
docKey,
|
||||
|
|
|
|||
|
|
@ -8,11 +8,21 @@
|
|||
*/
|
||||
import { defineStore } from 'pinia'
|
||||
import * as projectsService from '../services/projectsService'
|
||||
import * as documentsService from '../services/documentsService'
|
||||
|
||||
export const useProjectsStore = defineStore('projects', {
|
||||
state: () => ({
|
||||
projects: [],
|
||||
activeProjectId: null,
|
||||
// ProjectSidebar.vue's own per-project document hierarchy - lazy-
|
||||
// loaded on first expand (see loadProjectDocuments) and cached here
|
||||
// (not component-local) specifically so every OTHER place a document
|
||||
// gets created/moved/deleted (useBatchExtraction.js, TransactionsTable's
|
||||
// "Move to project", DocumentNavBar's delete, ProjectSidebar's own
|
||||
// delete) can keep an already-expanded project's list live via the
|
||||
// add/remove/move actions below, instead of the sidebar only ever
|
||||
// learning about a change by being collapsed and re-expanded.
|
||||
documentsByProject: {},
|
||||
}),
|
||||
actions: {
|
||||
async loadProjects() {
|
||||
|
|
@ -37,6 +47,27 @@ export const useProjectsStore = defineStore('projects', {
|
|||
await projectsService.deleteProject(project)
|
||||
this.projects = this.projects.filter((p) => p.id !== project.id)
|
||||
if (this.activeProjectId === project.id) this.activeProjectId = null
|
||||
delete this.documentsByProject[project.id]
|
||||
},
|
||||
|
||||
/** Fetches a project's own document list once and caches it - a later call is a no-op unless `force`, same lazy-cache behavior ProjectSidebar.vue's own expand toggle always had. */
|
||||
async loadProjectDocuments(projectId, { force = false } = {}) {
|
||||
if (!force && this.documentsByProject[projectId]) return
|
||||
this.documentsByProject[projectId] = await documentsService.listDocuments({ project: projectId })
|
||||
},
|
||||
/** Adds a freshly-created document to its own project's cached list, if that project has ever been expanded - unshift, not push, to match listDocuments' own newest-first sort. A no-op if the project's list was never loaded (nothing stale to fix - it'll fetch fresh whenever it IS expanded). */
|
||||
addDocumentToCache(projectId, doc) {
|
||||
if (this.documentsByProject[projectId]) this.documentsByProject[projectId].unshift(doc)
|
||||
},
|
||||
removeDocumentFromCache(projectId, docId) {
|
||||
if (this.documentsByProject[projectId]) {
|
||||
this.documentsByProject[projectId] = this.documentsByProject[projectId].filter((d) => d.id !== docId)
|
||||
}
|
||||
},
|
||||
/** "Move to project" from anywhere - removes from the old project's cache and adds to the new one, each a no-op if that project's list was never loaded. */
|
||||
moveDocumentInCache(fromProjectId, toProjectId, doc) {
|
||||
this.removeDocumentFromCache(fromProjectId, doc.id)
|
||||
this.addDocumentToCache(toProjectId, doc)
|
||||
},
|
||||
},
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue