From 583e6a33596b45c68d9a3d4c9d456b46f6a56a06 Mon Sep 17 00:00:00 2001 From: Sebastian Krupinski Date: Sat, 20 Jun 2026 19:25:00 -0400 Subject: [PATCH] refactor: use unified manager design Signed-off-by: Sebastian Krupinski --- src/components/CollectionEditor.vue | 4 +-- src/components/PersonList.vue | 38 ++++++++++++++--------------- src/stores/peopleStore.ts | 22 +++++------------ 3 files changed, 26 insertions(+), 38 deletions(-) diff --git a/src/components/CollectionEditor.vue b/src/components/CollectionEditor.vue index 9e454a7..3236e49 100644 --- a/src/components/CollectionEditor.vue +++ b/src/components/CollectionEditor.vue @@ -64,7 +64,7 @@ const onOpen = async () => { if (props.collection.identifier) { // Edit mode - find the service editingCollectionService.value = services.value.find(s => - s.provider === props.collection!.provider && s.identifier === props.collection!.service + `${s.provider}:${s.identifier}` === String(props.collection!.service) ) || null } else { // Create mode - use first service that can create @@ -233,7 +233,7 @@ watch(() => props.modelValue, async (newValue) => {
([]) + +// Entities belonging to the selected collection, sourced live from the manager store +const collectionEntities = computed(() => { + const collection = props.selectedCollection + if (!collection) { + return [] + } + return entitiesStore.entitiesForCollection(collection.identifier) +}) // Computed const filteredEntities = computed(() => { @@ -46,25 +54,15 @@ const filteredEntities = computed(() => { // Watchers watch(() => props.selectedCollection, async (newCollection) => { - if (newCollection) { - loading.value = true - try { - const sources = { - [newCollection.provider]: { - [String(newCollection.service)]: { - [String(newCollection.identifier)]: true as const, - }, - }, - } - const result = await entitiesStore.list(sources) - collectionEntities.value = Object.values(result) - } catch (error) { - console.error('[People] - Failed to load contacts:', error) - } finally { - loading.value = false - } - } else { - collectionEntities.value = [] + if (!newCollection) { + return + } + loading.value = true + try { + await entitiesStore.list([newCollection.identifier]) + } catch (error) { + console.error('[People] - Failed to load contacts:', error) + } finally { loading.value = false } }, { immediate: true }) diff --git a/src/stores/peopleStore.ts b/src/stores/peopleStore.ts index e572a5f..376753f 100644 --- a/src/stores/peopleStore.ts +++ b/src/stores/peopleStore.ts @@ -8,8 +8,10 @@ import { GroupObject } from '@PeopleManager/models/group' 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' export const usePeopleStore = defineStore('peopleStore', () => { + const servicesStore = useServicesStore() const collectionsStore = useCollectionsStore() const entitiesStore = useEntitiesStore() @@ -56,15 +58,12 @@ export const usePeopleStore = defineStore('peopleStore', () => { if (collectionEditorMode.value === 'create') { const created = await collectionsStore.create( service.provider, - service.identifier || '', - null, + service.identifier ?? '', collection.properties, ) selectedCollection.value = created } else { await collectionsStore.update( - collection.provider, - collection.service, collection.identifier, collection.properties, ) @@ -74,7 +73,7 @@ export const usePeopleStore = defineStore('peopleStore', () => { } async function deleteCollection(collection: CollectionObject) { - await collectionsStore.delete(collection.provider, collection.service, collection.identifier) + await collectionsStore.delete(collection.identifier) if (selectedCollection.value?.identifier === collection.identifier) { selectedCollection.value = null @@ -132,8 +131,6 @@ export const usePeopleStore = defineStore('peopleStore', () => { // Create entity.properties.created = new Date() selectedEntity.value = await entitiesStore.create( - targetCollection.provider, - targetCollection.service, targetCollection.identifier, entity.properties, ) @@ -141,9 +138,6 @@ export const usePeopleStore = defineStore('peopleStore', () => { // Update entity.properties.modified = new Date() selectedEntity.value = await entitiesStore.update( - targetCollection.provider, - targetCollection.service, - targetCollection.identifier, entity.identifier, entity.properties, ) @@ -162,12 +156,7 @@ export const usePeopleStore = defineStore('peopleStore', () => { throw new Error('[People] - No collection selected, cannot delete entity') } - await entitiesStore.delete( - targetCollection.provider, - targetCollection.service, - targetCollection.identifier, - entity.identifier, - ) + await entitiesStore.delete([entity.identifier]) closeEntityEditor() } @@ -177,6 +166,7 @@ export const usePeopleStore = defineStore('peopleStore', () => { async function initialize() { loading.value = true try { + await servicesStore.list() await collectionsStore.list() if (