124 lines
4.1 KiB
Vue
124 lines
4.1 KiB
Vue
<script setup>
|
|
/**
|
|
* DocumentNavBar.vue
|
|
*
|
|
* The active document's filename (click to rename or delete it - see
|
|
* DocumentOptionsModal.vue) plus prev/next between completed documents.
|
|
* Prev/next only show once there's more than one document to browse,
|
|
* but the filename itself - and the ability to delete it - is available
|
|
* from the very first document, not just once a batch exists (deleting
|
|
* before download was the actual ask; it shouldn't require a second
|
|
* document to be loaded first). Switches extractionStore.activeIndex,
|
|
* which is what SourceDocumentPanel/TransactionsTable all read through
|
|
* (see extractionStore.js's getters), so this is the only place that
|
|
* needs to know navigation exists at all.
|
|
*/
|
|
import { computed, ref } from 'vue'
|
|
import { useExtractionStore } from '../stores/extractionStore'
|
|
import * as documentsService from '../services/documentsService'
|
|
import DocumentOptionsModal from './DocumentOptionsModal.vue'
|
|
import ConfirmModal from './ConfirmModal.vue'
|
|
|
|
const extractionStore = useExtractionStore()
|
|
|
|
const positionText = computed(
|
|
() => `${extractionStore.activeIndex + 1} of ${extractionStore.documents.length}`,
|
|
)
|
|
|
|
const showOptions = ref(false)
|
|
const showDeleteConfirm = ref(false)
|
|
const renaming = ref(false)
|
|
const deleting = ref(false)
|
|
|
|
function openOptions() {
|
|
if (!extractionStore.activeDocument) return
|
|
showOptions.value = true
|
|
}
|
|
|
|
async function handleRename(name) {
|
|
const doc = extractionStore.activeDocument
|
|
if (!doc) return
|
|
renaming.value = true
|
|
extractionStore.clearError()
|
|
try {
|
|
await documentsService.updateDocument(doc.pbId, { fileName: name })
|
|
extractionStore.setActiveDocumentFileName(name)
|
|
showOptions.value = false
|
|
} catch (err) {
|
|
extractionStore.setError('Could not rename this document: ' + err.message)
|
|
}
|
|
renaming.value = false
|
|
}
|
|
|
|
function handleDeleteRequest() {
|
|
showOptions.value = false
|
|
showDeleteConfirm.value = true
|
|
}
|
|
|
|
async function confirmDelete() {
|
|
const doc = extractionStore.activeDocument
|
|
if (!doc) return
|
|
deleting.value = true
|
|
extractionStore.clearError()
|
|
try {
|
|
await documentsService.deleteDocument(doc.pbId)
|
|
extractionStore.removeDocument(doc.pbId)
|
|
showDeleteConfirm.value = false
|
|
} catch (err) {
|
|
extractionStore.setError('Could not delete this document: ' + err.message)
|
|
showDeleteConfirm.value = false
|
|
}
|
|
deleting.value = false
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<div v-if="extractionStore.documents.length > 0" class="doc-nav">
|
|
<button
|
|
v-if="extractionStore.documents.length > 1"
|
|
class="doc-nav-arrow"
|
|
type="button"
|
|
title="Previous document"
|
|
:disabled="extractionStore.activeIndex === 0"
|
|
@click="extractionStore.prev()"
|
|
><i class="fa-solid fa-chevron-left"></i></button>
|
|
|
|
<button type="button" class="doc-nav-label-btn" title="Rename or delete this document" @click="openOptions">
|
|
<i class="fa-solid fa-file-lines doc-nav-file-icon"></i>
|
|
<span class="doc-nav-name">{{ extractionStore.activeDocument?.fileName }}</span>
|
|
<span v-if="extractionStore.documents.length > 1" class="doc-nav-position">({{ positionText }})</span>
|
|
<i class="fa-solid fa-ellipsis doc-nav-options-hint"></i>
|
|
</button>
|
|
|
|
<button
|
|
v-if="extractionStore.documents.length > 1"
|
|
class="doc-nav-arrow"
|
|
type="button"
|
|
title="Next document"
|
|
:disabled="extractionStore.activeIndex === extractionStore.documents.length - 1"
|
|
@click="extractionStore.next()"
|
|
><i class="fa-solid fa-chevron-right"></i></button>
|
|
|
|
<DocumentOptionsModal
|
|
:visible="showOptions"
|
|
:file-name="extractionStore.activeDocument?.fileName ?? ''"
|
|
:renaming="renaming"
|
|
@rename="handleRename"
|
|
@delete="handleDeleteRequest"
|
|
@cancel="showOptions = false"
|
|
/>
|
|
<ConfirmModal
|
|
:visible="showDeleteConfirm"
|
|
title="Delete document?"
|
|
title-icon="fa-trash"
|
|
:message="`Delete “${extractionStore.activeDocument?.fileName}”? This removes it permanently and can't be undone.`"
|
|
confirm-label="Delete"
|
|
confirm-icon="fa-trash"
|
|
:danger="true"
|
|
:busy="deleting"
|
|
@confirm="confirmDelete"
|
|
@cancel="showDeleteConfirm = false"
|
|
/>
|
|
</div>
|
|
</template>
|