Accumulate staged files across picks instead of replacing them
Picking/dropping a file replaced whatever was already staged (reported: "I select one document and start again to select another, the first one is replaced"). setFiles now appends instead, deduping exact name+size repeats, so a batch can be built up across several separate picks/drops, not just one multi-select dialog. Each staged file gets an x to remove it before Extract is clicked. The staging list is cleared the moment Extract runs (not after it resolves), so an already-handed-off file can't linger and get re-processed - and duplicated, since extractionStore.documents has no dedup of its own - by a later click. Also resets the native file input after each pick so re-selecting the same file (e.g. after removing it) still fires a change event.
This commit is contained in:
parent
2081bc574b
commit
ec58a956e9
12
CLAUDE.md
12
CLAUDE.md
|
|
@ -749,6 +749,18 @@ restructure; the behavior itself predates it and is unchanged:
|
|||
Transactions table, the Source Document preview, and the visible document name together
|
||||
as one unit - all three read `extractionStore.activeDocument`/`activeIndex`, so
|
||||
`DocumentNavBar` is the only component that needs to know navigation exists at all.
|
||||
Picking/dropping ADDS to the staged list (`useFileUpload.js`'s `chosenFiles`) rather
|
||||
than replacing it (fixed 2026-10-13 - the first version replaced it, so picking a
|
||||
second file after a first lost the first entirely, reported by the user as "I select
|
||||
one document and start again to select another, the first one is replaced") - a batch
|
||||
can be built up across several separate picks/drops, not just one multi-select dialog.
|
||||
Each staged file shows with an × to remove it before Extract is ever clicked
|
||||
(`FileUploadZone.vue`'s `.staged-files` list); an exact duplicate (same name+size as
|
||||
something already staged) is silently skipped rather than appearing twice. The staging
|
||||
list is cleared the moment Extract is clicked (not after the batch finishes) so an
|
||||
already-handed-off file can't sit there and get accidentally re-processed (and
|
||||
duplicated in `extractionStore.documents`, which has no dedup of its own) by a later
|
||||
click.
|
||||
- PDF/image ("Source Document") and Transactions sit side-by-side with a draggable resizer
|
||||
(`ResizablePanels.vue`, the handle styled as a vertical grip-knob), both wrapped in one
|
||||
sticky flex row so they scroll as one unit (not the source-doc column alone). `.txn-col`
|
||||
|
|
|
|||
|
|
@ -66,7 +66,18 @@ h1{ font-family:var(--fd); font-weight:800; font-size:30px; letter-spacing:-.01e
|
|||
.file-zone-label{ font-size:13.5px; color:var(--t2); }
|
||||
.file-zone-label strong{ color:var(--blue); font-weight:600; }
|
||||
.file-zone-sub{ font-size:11.5px; color:var(--t4); margin-top:5px; }
|
||||
.file-zone-sub.file-chosen-name{ font-family:var(--fm); font-size:12px; color:var(--blue); margin-top:5px; }
|
||||
|
||||
.staged-files{ list-style:none; margin:0 0 14px; padding:0; display:flex; flex-direction:column; gap:6px; }
|
||||
.staged-files li{
|
||||
display:flex; align-items:center; justify-content:space-between; gap:10px;
|
||||
background:var(--navy); border:1px solid var(--border-2); border-radius:7px; padding:7px 8px 7px 11px;
|
||||
}
|
||||
.staged-file-name{ font-family:var(--fm); font-size:12px; color:var(--t1); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
|
||||
.staged-file-remove{
|
||||
background:transparent; border:none; cursor:pointer; color:var(--t4); font-size:11px;
|
||||
padding:4px 6px; border-radius:5px; flex-shrink:0; line-height:1;
|
||||
}
|
||||
.staged-file-remove:hover{ color:var(--red); background:rgba(16,24,40,.06); }
|
||||
|
||||
/* .fields-row pairs the balance inputs with the Recheck Balance button -
|
||||
the button sits at the row's own right edge, lining up under the
|
||||
|
|
|
|||
|
|
@ -13,24 +13,18 @@
|
|||
* from ExtractorView (which owns useFileUpload/useBatchExtraction once,
|
||||
* since SourceDocumentPanel also needs the active document's preview).
|
||||
*/
|
||||
import { computed } from 'vue'
|
||||
import { useExtractionStore } from '../stores/extractionStore'
|
||||
import ProcessingIndicator from './ProcessingIndicator.vue'
|
||||
|
||||
const props = defineProps({
|
||||
defineProps({
|
||||
chosenFiles: { type: Array, default: () => [] },
|
||||
isDragOver: { type: Boolean, default: false },
|
||||
isProcessing: { type: Boolean, required: true },
|
||||
phaseText: { type: String, required: true },
|
||||
})
|
||||
const emit = defineEmits(['file-input-change', 'drag-over', 'drag-leave', 'drop', 'extract'])
|
||||
const emit = defineEmits(['file-input-change', 'drag-over', 'drag-leave', 'drop', 'remove-file', 'extract'])
|
||||
|
||||
const extractionStore = useExtractionStore()
|
||||
const fileZoneSubText = computed(() => {
|
||||
if (!props.chosenFiles.length) return '.pdf, .jpg, or .png files'
|
||||
if (props.chosenFiles.length === 1) return props.chosenFiles[0].name
|
||||
return `${props.chosenFiles.length} files selected`
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
|
@ -50,11 +44,21 @@ const fileZoneSubText = computed(() => {
|
|||
@change="emit('file-input-change', $event)"
|
||||
>
|
||||
<div class="file-zone-label"><strong>Drop one or more statement PDFs or photos here</strong> or browse</div>
|
||||
<div class="file-zone-sub" :class="{ 'file-chosen-name': chosenFiles.length > 0 }">{{ fileZoneSubText }}</div>
|
||||
<div class="file-zone-sub">.pdf, .jpg, or .png files - add as many as you like, one at a time or together</div>
|
||||
</div>
|
||||
|
||||
<!-- Each pick/drop ADDS to this list rather than replacing it (see
|
||||
useFileUpload.js's setFiles) - the × lets a wrongly-added file be
|
||||
pulled back out before Extract is ever clicked. -->
|
||||
<ul v-if="chosenFiles.length" class="staged-files">
|
||||
<li v-for="(f, i) in chosenFiles" :key="f.name + ':' + f.size">
|
||||
<span class="staged-file-name">{{ f.name }}</span>
|
||||
<button type="button" class="staged-file-remove" title="Remove this file" @click="emit('remove-file', i)">✕</button>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<button class="btn btn-primary" type="button" :disabled="!chosenFiles.length || isProcessing" @click="emit('extract')">
|
||||
Extract
|
||||
Extract{{ chosenFiles.length > 1 ? ` (${chosenFiles.length})` : '' }}
|
||||
</button>
|
||||
<ProcessingIndicator :is-processing="isProcessing" :phase-text="phaseText" />
|
||||
<div class="error-note" :class="{ visible: !!extractionStore.errorMessage }">{{ extractionStore.errorMessage }}</div>
|
||||
|
|
|
|||
|
|
@ -21,9 +21,14 @@ export function useFileUpload() {
|
|||
const isDragOver = ref(false)
|
||||
|
||||
/**
|
||||
* Validates and stages files for the next Extract click. Invalid
|
||||
* files are skipped (and reported), not rejected wholesale - one bad
|
||||
* file in a multi-select shouldn't block the rest.
|
||||
* Validates and ADDS files to whatever's already staged for the next
|
||||
* Extract click - picking or dropping again doesn't replace the
|
||||
* earlier selection, it accumulates, so a batch can be built up across
|
||||
* several separate picks/drops, not just one multi-select dialog.
|
||||
* Invalid files are skipped (and reported), not rejected wholesale -
|
||||
* one bad file shouldn't block the rest; an exact duplicate (same
|
||||
* name+size as something already staged) is silently skipped too,
|
||||
* rather than appearing twice in the list.
|
||||
*/
|
||||
function setFiles(fileList) {
|
||||
const files = Array.from(fileList || [])
|
||||
|
|
@ -38,11 +43,32 @@ export function useFileUpload() {
|
|||
: `${rejectedCount} file(s) skipped - only .pdf, .jpg, and .png are supported.`
|
||||
)
|
||||
}
|
||||
chosenFiles.value = accepted
|
||||
const staged = new Set(chosenFiles.value.map((f) => f.name + ':' + f.size))
|
||||
for (const f of accepted) {
|
||||
const key = f.name + ':' + f.size
|
||||
if (!staged.has(key)) {
|
||||
chosenFiles.value.push(f)
|
||||
staged.add(key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Removes one staged file (by its position in chosenFiles) before it's ever uploaded. */
|
||||
function removeChosenFile(index) {
|
||||
chosenFiles.value.splice(index, 1)
|
||||
}
|
||||
|
||||
/** Empties the staging list - called once a batch has been handed off to extraction, so those files aren't left sitting there to be accidentally re-extracted (and duplicated) by a later click. */
|
||||
function clearChosenFiles() {
|
||||
chosenFiles.value = []
|
||||
}
|
||||
|
||||
function onFileInputChange(e) {
|
||||
setFiles(e.target.files)
|
||||
// Reset the native input so picking the SAME file again (e.g. after
|
||||
// removing it from the staged list) still fires a change event -
|
||||
// browsers don't fire one for re-selecting an identical file list.
|
||||
e.target.value = ''
|
||||
}
|
||||
|
||||
function onDragOver(e) {
|
||||
|
|
@ -94,6 +120,6 @@ export function useFileUpload() {
|
|||
|
||||
return {
|
||||
chosenFiles, isDragOver,
|
||||
setFiles, onFileInputChange, onDragOver, onDragLeave, onDrop, restoreOnLoad,
|
||||
setFiles, removeChosenFile, clearChosenFiles, onFileInputChange, onDragOver, onDragLeave, onDrop, restoreOnLoad,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import TransactionsTable from '../components/TransactionsTable.vue'
|
|||
const extractionStore = useExtractionStore()
|
||||
const {
|
||||
chosenFiles, isDragOver,
|
||||
onFileInputChange, onDragOver, onDragLeave, onDrop, restoreOnLoad,
|
||||
removeChosenFile, clearChosenFiles, onFileInputChange, onDragOver, onDragLeave, onDrop, restoreOnLoad,
|
||||
} = useFileUpload()
|
||||
const { isProcessing, phaseText, runBatch } = useBatchExtraction()
|
||||
|
||||
|
|
@ -37,7 +37,14 @@ const batchAwarePhaseText = computed(() => {
|
|||
|
||||
function handleExtract() {
|
||||
if (!chosenFiles.value.length) return
|
||||
runBatch(chosenFiles.value, extractionStore.pendingOpeningBalance, extractionStore.pendingClosingBalance)
|
||||
const files = chosenFiles.value
|
||||
// Clear the staging list right away, not after runBatch resolves - the
|
||||
// array reference runBatch is given keeps working regardless (clearing
|
||||
// just points chosenFiles at a new empty array), and this stops an
|
||||
// already-handed-off file from sitting in the staged list where a
|
||||
// later Extract click would re-process (and duplicate) it.
|
||||
clearChosenFiles()
|
||||
runBatch(files, extractionStore.pendingOpeningBalance, extractionStore.pendingClosingBalance)
|
||||
}
|
||||
|
||||
onMounted(restoreOnLoad)
|
||||
|
|
@ -62,6 +69,7 @@ onMounted(restoreOnLoad)
|
|||
@drag-over="onDragOver"
|
||||
@drag-leave="onDragLeave"
|
||||
@drop="onDrop"
|
||||
@remove-file="removeChosenFile"
|
||||
@extract="handleExtract"
|
||||
/>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue