tagsByCategory now calculated on shared filter panel

This commit is contained in:
lightling 2024-05-03 18:17:18 -04:00
parent 64fb80235e
commit d19e922b31
2 changed files with 25 additions and 29 deletions

View file

@ -1,13 +1,32 @@
<script setup lang="ts"> <script setup lang="ts">
import { computed } from 'vue'
import type { EntryTagCollection } from '@goldenwere/static-web-templates-types'
defineProps<{ const props = defineProps<{
tagsByCategory: { [category: string]: Record<string, string> } tags: EntryTagCollection
}>() }>()
const emits = defineEmits<{ const emits = defineEmits<{
(e: 'toggledTagsChanged', value: string[]): void (e: 'toggledTagsChanged', value: string[]): void
}>() }>()
const tagsByCategory = computed(() => {
const value: { [category: string]: Record<string, string> } = { 'NoCategory': {}}
Object.keys(props.tags).forEach(id => {
const tag = props.tags![id]
if (!!tag.category) {
if (!value[tag.category]) {
value[tag.category] = {}
}
value[tag.category][id] = tag.displayName || id
} else {
value['NoCategory'][id] = tag.displayName || id
}
})
return value
})
let tagsToggled: string[] = [] let tagsToggled: string[] = []
/** /**
@ -37,8 +56,8 @@ const resetTags = () => {
</script> </script>
<template lang="pug"> <template lang="pug">
.filters .filter-panel
h2 Filters h2 Filter By Tags
.category( .category(
v-for='(tags, category) in tagsByCategory' v-for='(tags, category) in tagsByCategory'
:id='category' :id='category'

View file

@ -55,28 +55,6 @@ const hasWarnings = ref(false)
const hideWarnings = defineModel('showWarnings', { type: Boolean }) const hideWarnings = defineModel('showWarnings', { type: Boolean })
const tagsByCategory = ref({} as { [category: string]: Record<string, string> }) const tagsByCategory = ref({} as { [category: string]: Record<string, string> })
/**
* Handles updating the displayed tags in the list
*/
const onLoadTags = () => {
if (!!config.tags) {
tagsByCategory.value = { 'NoCategory': {}}
Object.keys(config.tags).forEach(id => {
const tag = config.tags![id]
if (!!tag.category) {
if (!tagsByCategory.value[tag.category]) {
tagsByCategory.value[tag.category] = {}
}
tagsByCategory.value[tag.category][id] = tag.displayName || id
} else {
tagsByCategory.value['NoCategory'][id] = tag.displayName || id
}
})
} else {
tagsByCategory.value = null as any
}
}
/** /**
* Handles updating the displayed entries in the list * Handles updating the displayed entries in the list
*/ */
@ -181,7 +159,6 @@ onMounted(async () => {
config = await fetchAndParseYaml<GalleryList>(routeConfig.config) config = await fetchAndParseYaml<GalleryList>(routeConfig.config)
document.title = routeConfig.title document.title = routeConfig.title
hideWarnings.value = storage.read(`${storageId}::hideWarnings`) || false hideWarnings.value = storage.read(`${storageId}::hideWarnings`) || false
onLoadTags()
onDisplayEntries() onDisplayEntries()
ready.value = true ready.value = true
}) })
@ -212,9 +189,9 @@ onMounted(async () => {
) )
Transition Transition
FilterPanel( FilterPanel(
v-if='galleryReady && !!tagsByCategory' v-if='galleryReady && !!config.tags'
:ref='filterPanelRef' :ref='filterPanelRef'
:tagsByCategory='tagsByCategory' :tags='config.tags'
@toggledTagsChanged='onToggledTagsChanged($event)' @toggledTagsChanged='onToggledTagsChanged($event)'
) )
Transition Transition