eebc8e2413
- utils/date.js: add formatRelative(iso, {future,nullText}); migrate 6 sites
(SourceRow, SubscriptionsTab, SourceHealthDot, SchedulerStatusBar +
thin adapters in BackupRunsTable/SystemActivityTab for their '—' null text).
PostCard (30d->absolute) and CredentialCard (mo/y buckets) intentionally
keep bespoke formatters.
- utils/toast.js: toast(opts) wraps the globalThis.window?.__fcToast?.(...)
incantation; migrate 63 call sites across 24 files.
- utils/downloadStatus.js: single source for the download-event status enum
-> label/color/icon; collapse the 3 duplicate maps (DownloadStatChips,
DownloadsFilterPopover, DownloadEventRow).
Net -33 lines. Platform metadata was already centralized in platformColor.js.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
78 lines
2.3 KiB
JavaScript
78 lines
2.3 KiB
JavaScript
import { defineStore } from 'pinia'
|
|
import { toast } from '../utils/toast.js'
|
|
import { ref, computed } from 'vue'
|
|
import { useApi } from '../composables/useApi.js'
|
|
|
|
export const useGallerySelectionStore = defineStore('gallerySelection', () => {
|
|
const api = useApi()
|
|
|
|
const isSelectMode = ref(false)
|
|
const order = ref([]) // image ids, selection order = source of truth
|
|
const commonTags = ref([])
|
|
const consensus = ref({}) // { category: [ {canonical_tag_id,...} ] }
|
|
|
|
const count = computed(() => order.value.length)
|
|
function isSelected(id) { return order.value.includes(id) }
|
|
|
|
function toggle(id) {
|
|
const i = order.value.indexOf(id)
|
|
if (i === -1) order.value.push(id)
|
|
else order.value.splice(i, 1)
|
|
}
|
|
function clear() {
|
|
order.value = []
|
|
commonTags.value = []
|
|
consensus.value = {}
|
|
}
|
|
function enterSelectMode() { isSelectMode.value = true }
|
|
function exitSelectMode() { isSelectMode.value = false; clear() }
|
|
|
|
async function loadCommonTags() {
|
|
if (order.value.length === 0) { commonTags.value = []; return }
|
|
const body = await api.post('/api/images/common-tags', {
|
|
body: { image_ids: order.value }
|
|
})
|
|
commonTags.value = body.tags
|
|
}
|
|
|
|
async function loadConsensus() {
|
|
if (order.value.length === 0) { consensus.value = {}; return }
|
|
const body = await api.post('/api/suggestions/bulk', {
|
|
body: { image_ids: order.value }
|
|
})
|
|
consensus.value = body.suggestions
|
|
}
|
|
|
|
async function refresh() {
|
|
await Promise.all([loadCommonTags(), loadConsensus()])
|
|
}
|
|
|
|
async function bulkAdd(tagId, source = 'manual') {
|
|
const body = await api.post('/api/images/bulk/tags', {
|
|
body: { image_ids: order.value, tag_id: tagId, source }
|
|
})
|
|
await refresh()
|
|
toast({
|
|
text: `Added to ${body.added_count} image(s)`, type: 'success'
|
|
})
|
|
return body
|
|
}
|
|
|
|
async function bulkRemove(tagId) {
|
|
const body = await api.post('/api/images/bulk/tags/remove', {
|
|
body: { image_ids: order.value, tag_id: tagId }
|
|
})
|
|
await refresh()
|
|
toast({
|
|
text: `Removed from ${body.removed_count} image(s)`, type: 'success'
|
|
})
|
|
return body
|
|
}
|
|
|
|
return {
|
|
isSelectMode, order, commonTags, consensus, count,
|
|
isSelected, toggle, clear, enterSelectMode, exitSelectMode,
|
|
loadCommonTags, loadConsensus, refresh, bulkAdd, bulkRemove
|
|
}
|
|
})
|