chore: initial commit — existing single-user document scanner codebase
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import * as api from '../api/client.js'
|
||||
|
||||
export const useDocumentsStore = defineStore('documents', () => {
|
||||
const documents = ref([])
|
||||
const total = ref(0)
|
||||
const loading = ref(false)
|
||||
const error = ref(null)
|
||||
|
||||
async function fetchDocuments({ topic, page = 1, perPage = 20 } = {}) {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
const data = await api.listDocuments({ topic, page, perPage })
|
||||
documents.value = data.items
|
||||
total.value = data.total
|
||||
} catch (e) {
|
||||
error.value = e.message
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function upload(file, autoClassify = true) {
|
||||
const doc = await api.uploadDocument(file, autoClassify)
|
||||
documents.value.unshift(doc)
|
||||
total.value++
|
||||
return doc
|
||||
}
|
||||
|
||||
async function remove(id) {
|
||||
await api.deleteDocument(id)
|
||||
documents.value = documents.value.filter(d => d.id !== id)
|
||||
total.value--
|
||||
}
|
||||
|
||||
async function reclassify(id, topics = null) {
|
||||
const result = await api.classifyDocument(id, topics)
|
||||
const idx = documents.value.findIndex(d => d.id === id)
|
||||
if (idx !== -1) documents.value[idx].topics = result.topics
|
||||
return result.topics
|
||||
}
|
||||
|
||||
return { documents, total, loading, error, fetchDocuments, upload, remove, reclassify }
|
||||
})
|
||||
@@ -0,0 +1,38 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import * as api from '../api/client.js'
|
||||
|
||||
export const useSettingsStore = defineStore('settings', () => {
|
||||
const settings = ref(null)
|
||||
const loading = ref(false)
|
||||
const error = ref(null)
|
||||
|
||||
async function fetchSettings() {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
settings.value = await api.getSettings()
|
||||
} catch (e) {
|
||||
error.value = e.message
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function save(patch) {
|
||||
const updated = await api.patchSettings(patch)
|
||||
settings.value = updated
|
||||
return updated
|
||||
}
|
||||
|
||||
async function testConnection(provider) {
|
||||
return api.testProvider(provider)
|
||||
}
|
||||
|
||||
async function resetPrompt() {
|
||||
const data = await api.getDefaultPrompt()
|
||||
return data.system_prompt
|
||||
}
|
||||
|
||||
return { settings, loading, error, fetchSettings, save, testConnection, resetPrompt }
|
||||
})
|
||||
@@ -0,0 +1,42 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import * as api from '../api/client.js'
|
||||
|
||||
export const useTopicsStore = defineStore('topics', () => {
|
||||
const topics = ref([])
|
||||
const loading = ref(false)
|
||||
const error = ref(null)
|
||||
|
||||
async function fetchTopics() {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
const data = await api.listTopics()
|
||||
topics.value = data.topics
|
||||
} catch (e) {
|
||||
error.value = e.message
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function addTopic(payload) {
|
||||
const topic = await api.createTopic(payload)
|
||||
topics.value.push(topic)
|
||||
return topic
|
||||
}
|
||||
|
||||
async function editTopic(id, patch) {
|
||||
const updated = await api.updateTopic(id, patch)
|
||||
const idx = topics.value.findIndex(t => t.id === id)
|
||||
if (idx !== -1) topics.value[idx] = updated
|
||||
return updated
|
||||
}
|
||||
|
||||
async function removeTopic(id) {
|
||||
await api.deleteTopic(id)
|
||||
topics.value = topics.value.filter(t => t.id !== id)
|
||||
}
|
||||
|
||||
return { topics, loading, error, fetchTopics, addTopic, editTopic, removeTopic }
|
||||
})
|
||||
Reference in New Issue
Block a user