refactor: standardize provider
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -1,13 +1,10 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { useCollectionsStore } from '@PeopleManager/stores/collectionsStore'
|
||||
import { CollectionObject } from '@PeopleManager/models/collection';
|
||||
|
||||
// Store
|
||||
const collectionsStore = useCollectionsStore()
|
||||
|
||||
// Props
|
||||
const props = defineProps<{
|
||||
collections: CollectionObject[]
|
||||
loading?: boolean
|
||||
selectedCollection?: CollectionObject | null
|
||||
}>()
|
||||
|
||||
@@ -17,43 +14,14 @@ const emit = defineEmits<{
|
||||
'edit': [collection: CollectionObject]
|
||||
}>()
|
||||
|
||||
// State
|
||||
const loading = ref(false)
|
||||
const collections = ref<CollectionObject[]>([])
|
||||
|
||||
// Lifecycle
|
||||
onMounted(async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
collections.value = await collectionsStore.list()
|
||||
} catch (error) {
|
||||
console.error('[People] - Failed to load collections:', error)
|
||||
}
|
||||
loading.value = false
|
||||
})
|
||||
|
||||
// Functions
|
||||
const onCollectionSelect = (collection: CollectionObject) => {
|
||||
console.log('[People] - Collection selected', collection)
|
||||
emit('select', collection)
|
||||
}
|
||||
|
||||
const onCollectionEdit = (collection: CollectionObject) => {
|
||||
emit('edit', collection)
|
||||
}
|
||||
|
||||
// Expose refresh method
|
||||
defineExpose({
|
||||
async refresh() {
|
||||
loading.value = true
|
||||
try {
|
||||
collections.value = await collectionsStore.list()
|
||||
} catch (error) {
|
||||
console.error('[People] - Failed to load collections:', error)
|
||||
}
|
||||
loading.value = false
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -73,18 +41,18 @@ defineExpose({
|
||||
<v-list v-else density="compact" nav class="pa-0">
|
||||
<v-list-item
|
||||
v-for="collection in collections"
|
||||
:key="collection.id"
|
||||
:value="collection.id"
|
||||
:active="selectedCollection?.id === collection.id"
|
||||
:key="collection.identifier"
|
||||
:value="collection.identifier"
|
||||
:active="selectedCollection?.identifier === collection.identifier"
|
||||
@click="onCollectionSelect(collection)"
|
||||
rounded="lg"
|
||||
class="mb-1"
|
||||
>
|
||||
<template #prepend>
|
||||
<v-icon :color="collection.color || 'primary'" icon="mdi-book-outline" size="small" />
|
||||
<v-icon :color="collection.properties.color || 'primary'" icon="mdi-book-outline" size="small" />
|
||||
</template>
|
||||
|
||||
<v-list-item-title>{{ collection.label }}</v-list-item-title>
|
||||
<v-list-item-title>{{ collection.properties.label || 'Unnamed' }}</v-list-item-title>
|
||||
|
||||
<template #append>
|
||||
<v-btn
|
||||
|
||||
Reference in New Issue
Block a user