feat: use module store

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-02-17 19:11:12 -05:00
parent 6a7b28b86d
commit b663efbb3e
10 changed files with 883 additions and 612 deletions
+6 -40
View File
@@ -1,13 +1,10 @@
<script setup lang="ts">
import { ref, onMounted, computed } from 'vue'
import { useCollectionsStore } from '@ChronoManager/stores/collectionsStore'
import { computed } from 'vue'
import { CollectionObject } from '@ChronoManager/models/collection';
// Store
const collectionsStore = useCollectionsStore()
// Props
const props = defineProps<{
collections: CollectionObject[]
selectedCollection?: CollectionObject | null
type?: 'calendar' | 'tasklist'
}>()
@@ -19,15 +16,11 @@ const emit = defineEmits<{
'toggle-visibility': [collection: CollectionObject]
}>()
// State
const loading = ref(false)
const collections = ref<CollectionObject[]>([])
// Computed
const filteredCollections = computed(() => {
if (!props.type) return collections.value
if (!props.type) return props.collections
return collections.value.filter(collection => {
return props.collections.filter(collection => {
if (props.type === 'calendar') {
return collection.properties.contents?.event
} else if (props.type === 'tasklist') {
@@ -49,17 +42,6 @@ const displayIcon = computed(() => {
return 'mdi-folder'
})
// Lifecycle
onMounted(async () => {
loading.value = true
try {
collections.value = Object.values(await collectionsStore.list())
} catch (error) {
console.error('[Chrono] - Failed to load collections:', error)
}
loading.value = false
})
// Functions
const onCollectionSelect = (collection: CollectionObject) => {
console.log('[Chrono] - Collection selected', collection)
@@ -71,22 +53,8 @@ const onCollectionEdit = (collection: CollectionObject) => {
}
const onToggleVisibility = (collection: CollectionObject) => {
collection.properties.visibility = collection.properties.visibility === false
emit('toggle-visibility', collection)
}
// Expose refresh method
defineExpose({
async refresh() {
loading.value = true
try {
collections.value = Object.values(await collectionsStore.list())
} catch (error) {
console.error('[Chrono] - Failed to load collections:', error)
}
loading.value = false
}
})
</script>
<template>
@@ -101,9 +69,7 @@ defineExpose({
<v-divider class="my-2" />
<div class="collection-selector-content">
<v-progress-linear v-if="loading" indeterminate color="primary" />
<v-list v-else density="compact" nav class="pa-0">
<v-list density="compact" nav class="pa-0">
<v-list-item
v-for="collection in filteredCollections"
:key="collection.identifier"
@@ -142,7 +108,7 @@ defineExpose({
</v-list-item>
</v-list>
<v-alert v-if="!loading && filteredCollections.length === 0" type="info" variant="tonal" density="compact" class="mt-2">
<v-alert v-if="filteredCollections.length === 0" type="info" variant="tonal" density="compact" class="mt-2">
No {{ displayTitle.toLowerCase() }} found
</v-alert>
</div>