refactor: use unified manager design
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -22,7 +22,15 @@ const emit = defineEmits<{
|
||||
// State
|
||||
const loading = ref(false)
|
||||
const searchQuery = ref('')
|
||||
const collectionEntities = ref<EntityObject[]>([])
|
||||
|
||||
// Entities belonging to the selected collection, sourced live from the manager store
|
||||
const collectionEntities = computed<EntityObject[]>(() => {
|
||||
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 })
|
||||
|
||||
Reference in New Issue
Block a user