bettersight-statement-extra.../frontend/src/views/ExtractorView.vue

85 lines
3.1 KiB
Vue

<script setup>
/**
* ExtractorView.vue
*
* The whole current page: upload, result, and side-by-side review.
* Owns useFileUpload/useExtraction once (rather than each consuming
* component owning its own copy) since both FileUploadZone and
* SourceDocumentPanel need the same chosenFile/currentPdfUrl state.
*/
import { onMounted } from 'vue'
import { useExtractionStore } from '../stores/extractionStore'
import { useFileUpload } from '../composables/useFileUpload'
import { useExtraction } from '../composables/useExtraction'
import FileUploadZone from '../components/FileUploadZone.vue'
import RestoreBanner from '../components/RestoreBanner.vue'
import ResultCard from '../components/ResultCard.vue'
import ResizablePanels from '../components/ResizablePanels.vue'
import SourceDocumentPanel from '../components/SourceDocumentPanel.vue'
import TransactionsTable from '../components/TransactionsTable.vue'
const extractionStore = useExtractionStore()
const {
chosenFile, currentPdfUrl, isDragOver, isImage,
onFileInputChange, onDragOver, onDragLeave, onDrop, restoreOnLoad,
} = useFileUpload()
const { isProcessing, phaseText, runExtraction } = useExtraction()
function handleExtract() {
if (!chosenFile.value) return
runExtraction(chosenFile.value, extractionStore.openingBalanceInput, extractionStore.closingBalanceInput)
}
// On page load, restore any previous session right away - before any
// file is even chosen - so a crash mid-edit never loses work. The
// source file itself isn't persisted (not practical to store in
// localStorage), so the preview stays empty until the same file is
// re-picked.
onMounted(restoreOnLoad)
</script>
<template>
<div class="eyebrow">Extraction &amp; verification</div>
<h1>Bank Statement Extractor</h1>
<div class="sub">
Upload a bank statement PDF or photo. A text PDF structures the transactions and proves the
arithmetic against two independent extraction passes; a scanned or photographed statement is
read via OCR instead, with no second pass to cross-check it against.
</div>
<FileUploadZone
:chosen-file="chosenFile"
:is-drag-over="isDragOver"
:is-processing="isProcessing"
:phase-text="phaseText"
@file-input-change="onFileInputChange"
@drag-over="onDragOver"
@drag-leave="onDragLeave"
@drop="onDrop"
@extract="handleExtract"
/>
<div v-if="extractionStore.currentResult">
<RestoreBanner />
<ResultCard />
</div>
<!--
Source Document and Transactions (and the opening/closing balance
fields that live in the latter) are always visible, even before a
file is chosen - the balance fields need to be enterable BEFORE
clicking Extract, since they're submitted as part of that same
request. Each panel shows its own empty state until there's
something to display - see SourceDocumentPanel.vue/
TransactionsTable.vue.
-->
<ResizablePanels>
<template #source>
<SourceDocumentPanel :preview-url="currentPdfUrl" :is-image="isImage" />
</template>
<template #transactions>
<TransactionsTable />
</template>
</ResizablePanels>
</template>