feat: people import

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-06-22 22:56:31 -04:00
parent 583e6a3359
commit b6b3e53095
3 changed files with 324 additions and 1 deletions
+59
View File
@@ -9,11 +9,13 @@ import type { ServiceObject } from '@PeopleManager/models/service'
import { useCollectionsStore } from '@PeopleManager/stores/collectionsStore'
import { useEntitiesStore } from '@PeopleManager/stores/entitiesStore'
import { useServicesStore } from '@PeopleManager/stores/servicesStore'
import { useImportStore } from '@PeopleManager/stores/importStore'
export const usePeopleStore = defineStore('peopleStore', () => {
const servicesStore = useServicesStore()
const collectionsStore = useCollectionsStore()
const entitiesStore = useEntitiesStore()
const importStore = useImportStore()
// UI state
const sidebarVisible = ref(true)
@@ -31,6 +33,9 @@ export const usePeopleStore = defineStore('peopleStore', () => {
const editingCollection = shallowRef<CollectionObject | null>(null)
const collectionEditorMode = ref<'create' | 'edit'>('create')
// Import state
const showImportDialog = ref(false)
// Derived state
const collections = computed(() => collectionsStore.collections)
const entities = computed(() => entitiesStore.entities)
@@ -161,6 +166,55 @@ export const usePeopleStore = defineStore('peopleStore', () => {
closeEntityEditor()
}
// --- Import actions ---
/**
* Queue selected VCF files and open the import dialog.
* Defaults each file's target to the currently selected collection.
*/
async function openImport(files: File[]) {
importStore.removeAllFiles()
importStore.reset()
for (const file of files) {
const contents = await file.text()
const id = importStore.addFile({
name: file.name,
contents,
size: file.size,
type: file.type,
})
if (selectedCollection.value) {
importStore.setCollectionForFile(id, selectedCollection.value.identifier)
}
}
importStore.stage = 'selecting'
showImportDialog.value = true
}
/**
* Close the import dialog. When refresh is requested, reload the entity lists for
* every collection that received contacts, then clear the import queue.
*/
async function closeImport(refresh: boolean = false) {
showImportDialog.value = false
if (refresh) {
const targets = new Set<CollectionObject['identifier']>()
for (const id of importStore.order) {
const target = importStore.sessions[id]?.targetIdentifier
if (target) targets.add(target)
}
for (const target of targets) {
await entitiesStore.list([target])
}
}
importStore.removeAllFiles()
importStore.reset()
}
// --- Lifecycle ---
async function initialize() {
@@ -190,6 +244,7 @@ export const usePeopleStore = defineStore('peopleStore', () => {
showCollectionEditor,
editingCollection,
collectionEditorMode,
showImportDialog,
// Derived
collections,
@@ -211,6 +266,10 @@ export const usePeopleStore = defineStore('peopleStore', () => {
saveEntity,
deleteEntity,
// Import actions
openImport,
closeImport,
// Lifecycle
initialize,
}