From 4c2a08057c3ad1277baad64fb48b7968ac9060e2 Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Fri, 20 Mar 2026 09:52:52 -0700 Subject: [PATCH] feat: add digest Pinia store --- web/src/stores/digest.ts | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 web/src/stores/digest.ts diff --git a/web/src/stores/digest.ts b/web/src/stores/digest.ts new file mode 100644 index 0000000..3ac1366 --- /dev/null +++ b/web/src/stores/digest.ts @@ -0,0 +1,40 @@ +import { defineStore } from 'pinia' +import { ref } from 'vue' +import { useApiFetch } from '../composables/useApi' + +export interface DigestEntry { + id: number + job_contact_id: number + created_at: string + subject: string + from_addr: string | null + received_at: string + body: string | null +} + +export interface DigestLink { + url: string + score: number // 2 = job-likely, 1 = other + hint: string +} + +export const useDigestStore = defineStore('digest', () => { + const entries = ref([]) + const loading = ref(false) + const error = ref(null) + + async function fetchAll() { + loading.value = true + const { data, error: err } = await useApiFetch('/api/digest-queue') + loading.value = false + if (err) { error.value = 'Could not load digest queue'; return } + entries.value = data ?? [] + } + + async function remove(id: number) { + entries.value = entries.value.filter(e => e.id !== id) + await useApiFetch(`/api/digest-queue/${id}`, { method: 'DELETE' }) + } + + return { entries, loading, error, fetchAll, remove } +})