bettersight-statement-extra.../frontend/src/components/FileUploadZone.vue

99 lines
4.8 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<script setup>
/**
* FileUploadZone.vue
*
* Drop zone, file picker, and the Extract button. Also hosts the SINGLE
* shared error-note area - in the original vanilla-JS version this one
* element shows upload-validation errors, process errors, AND download
* errors (even though downloading happens from TransactionsTable's own
* top bar, visually elsewhere on the page) - a pre-existing UX quirk,
* preserved exactly rather than "fixed" unprompted.
*
* Presentational - file-selection/extraction state and handlers come
* from ExtractorView (which owns useFileUpload/useBatchExtraction once,
* since SourceDocumentPanel also needs the active document's preview).
*/
import { useExtractionStore } from '../stores/extractionStore'
import ProcessingIndicator from './ProcessingIndicator.vue'
defineProps({
chosenFiles: { type: Array, default: () => [] },
isDragOver: { type: Boolean, default: false },
isProcessing: { type: Boolean, required: true },
phaseText: { type: String, required: true },
// Billing/usage note aside - this is about EXTRACTION QUALITY, a
// real reported case: a low-resolution photo/screenshot upload can
// read so poorly via OCR that the result needs careful manual review
// even after the backend's own upscaling correction (see CLAUDE.md's
// "Two real bugs found investigating a specific real-world statement
// report" entry). {[name:size]: {width, height}}, keyed the same way
// chosenFiles' own dedup already is - see useFileUpload.js's own
// lowResolutionWarnings docstring.
lowResolutionWarnings: { type: Object, default: () => ({}) },
})
const emit = defineEmits(['file-input-change', 'drag-over', 'drag-leave', 'drop', 'remove-file', 'extract'])
const extractionStore = useExtractionStore()
</script>
<template>
<div class="card upload-card">
<h2>Statement</h2>
<div
class="file-zone"
:class="{ 'drag-over': isDragOver }"
@dragover="emit('drag-over', $event)"
@dragleave="emit('drag-leave')"
@drop="emit('drop', $event)"
>
<input
type="file"
multiple
accept=".pdf,application/pdf,.jpg,.jpeg,.png,image/jpeg,image/png"
@change="emit('file-input-change', $event)"
>
<i class="fa-solid fa-cloud-arrow-up file-zone-icon"></i>
<div class="file-zone-label"><strong>Drop one or more statement PDFs or photos here</strong> or browse</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">
<div class="staged-file-row">
<span class="staged-file-name"><i class="fa-solid fa-file-lines"></i>{{ f.name }}</span>
<button type="button" class="staged-file-remove" title="Remove this file" @click="emit('remove-file', i)">
<i class="fa-solid fa-xmark"></i>
</button>
</div>
<!--
A real reported case: a low-resolution photo/screenshot can
read so poorly via OCR that the result needs careful manual
review even after the backend's own automatic upscaling
correction - surfaced here, at the moment the user can still
easily pick a different file, rather than only discovered
after a confusing/wrong Preview. Both of the choices the user
actually has are already right here: the x above removes
this file (pick a clearer one instead), or Extract below
proceeds with it as-is, accepting the risk.
-->
<div v-if="lowResolutionWarnings[f.name + ':' + f.size]" class="staged-file-warning">
<i class="fa-solid fa-triangle-exclamation"></i>
Low resolution ({{ lowResolutionWarnings[f.name + ':' + f.size].width }}&times;{{ lowResolutionWarnings[f.name + ':' + f.size].height }}px) -
the app will try to correct for this, but text recognition may still suffer and the result may need manual
review/correction. Consider a clearer or higher-resolution photo instead, or continue if you accept the risk.
</div>
</li>
</ul>
<button class="btn btn-primary" type="button" :disabled="!chosenFiles.length || isProcessing" @click="emit('extract')">
<i class="fa-solid fa-bolt"></i>
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>
</div>
</template>