re-implement original method of hiding tags
wrap around the promise structure with non-promisey way of hiding values instead of mutating the entries
This commit is contained in:
parent
6e4e41ab88
commit
fafa40fe91
1 changed files with 20 additions and 31 deletions
|
@ -1,5 +1,5 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, onMounted, useTemplateRef, ref } from 'vue'
|
import { computed, onMounted, ref } from 'vue'
|
||||||
import type {
|
import type {
|
||||||
ConfigfulRouteDefinition,
|
ConfigfulRouteDefinition,
|
||||||
ListWithWarnings,
|
ListWithWarnings,
|
||||||
|
@ -17,16 +17,10 @@ import ArticleTile from '../article/article-tile.vue'
|
||||||
type MediaList =
|
type MediaList =
|
||||||
& ListWithWarnings<MediaEntry>
|
& ListWithWarnings<MediaEntry>
|
||||||
|
|
||||||
/**
|
type DisplayedEntries = { [key: string]: {
|
||||||
* A wrapper around {@link ResolvedListEntries} for the app's use only which adds additional fields
|
entry: Promise<MediaEntry>
|
||||||
* in order for the app to effectively display the entries.
|
hiddenByTags?: boolean
|
||||||
*/
|
}}
|
||||||
type DisplayedEntries = ResolvedListEntries<MediaEntry & {
|
|
||||||
/**
|
|
||||||
* specifies whether the entry is hidden by the tags selected by a visitor
|
|
||||||
*/
|
|
||||||
isHidden?: boolean
|
|
||||||
}>
|
|
||||||
|
|
||||||
const ready = ref(false)
|
const ready = ref(false)
|
||||||
const currentRoute = getCurrentRoute()
|
const currentRoute = getCurrentRoute()
|
||||||
|
@ -39,7 +33,6 @@ const viewPath = computed(() => `${currentRoute.path}/view`)
|
||||||
|
|
||||||
const config = ref(null as MediaList | null)
|
const config = ref(null as MediaList | null)
|
||||||
const entries = ref({} as DisplayedEntries)
|
const entries = ref({} as DisplayedEntries)
|
||||||
const entriesRefs = useTemplateRef('tiles' as any)
|
|
||||||
const hasWarnings = ref(false)
|
const hasWarnings = ref(false)
|
||||||
const hideWarnings = defineModel('hideWarnings', { type: Boolean })
|
const hideWarnings = defineModel('hideWarnings', { type: Boolean })
|
||||||
const template = ref(routeConfig.template)
|
const template = ref(routeConfig.template)
|
||||||
|
@ -61,20 +54,14 @@ const className = computed(() => {
|
||||||
* @param tagsToggled the tags currently toggled in the filter panel
|
* @param tagsToggled the tags currently toggled in the filter panel
|
||||||
*/
|
*/
|
||||||
const onToggledTagsChanged = async (tagsToggled: string[]) => {
|
const onToggledTagsChanged = async (tagsToggled: string[]) => {
|
||||||
await Promise.all((entriesRefs as any).value.map(async (val: any) => {
|
await Promise.all(Object.keys(entries.value).map(async entryId => {
|
||||||
const el = val.$el as HTMLElement
|
const entry = entries.value[entryId]
|
||||||
const entry = await entries.value[el.id]
|
const entryVal = await entry.entry
|
||||||
|
|
||||||
if (tagsToggled.length < 1) {
|
if (tagsToggled.length < 1) {
|
||||||
entry.isHidden = false
|
entry.hiddenByTags = false
|
||||||
} else {
|
} else {
|
||||||
entry.isHidden = !entry.tags?.some(own => tagsToggled.includes(own))
|
entry.hiddenByTags = !entryVal.tags?.some(own => tagsToggled.includes(own))
|
||||||
}
|
|
||||||
|
|
||||||
if (entry?.isHidden) {
|
|
||||||
el.classList.add('hidden')
|
|
||||||
} else {
|
|
||||||
el.classList.remove('hidden')
|
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
@ -93,7 +80,11 @@ onMounted(async () => {
|
||||||
let listConfig = await fetchAndParseConfig<MediaList>(routeConfig.config)
|
let listConfig = await fetchAndParseConfig<MediaList>(routeConfig.config)
|
||||||
const list = await fetchConfigsFromList<MediaEntry>(listConfig)
|
const list = await fetchConfigsFromList<MediaEntry>(listConfig)
|
||||||
config.value = listConfig
|
config.value = listConfig
|
||||||
entries.value = list.entries
|
Object.keys(list.entries).forEach(entryId => {
|
||||||
|
entries.value[entryId] = {
|
||||||
|
entry: list.entries[entryId],
|
||||||
|
}
|
||||||
|
})
|
||||||
document.title = routeConfig.fullTitle
|
document.title = routeConfig.fullTitle
|
||||||
ready.value = true
|
ready.value = true
|
||||||
hasWarnings.value = !!(await Promise.all(Object.values(list.entries))).find(other => !!other.warnings)
|
hasWarnings.value = !!(await Promise.all(Object.values(list.entries))).find(other => !!other.warnings)
|
||||||
|
@ -136,19 +127,17 @@ onMounted(async () => {
|
||||||
v-for='(entry, id) in entries'
|
v-for='(entry, id) in entries'
|
||||||
)
|
)
|
||||||
GalleryTile(
|
GalleryTile(
|
||||||
v-if='template === "gallery-list"'
|
v-if='template === "gallery-list" && (!entry.hiddenByTags)'
|
||||||
ref='tiles'
|
:class='{ hidden: entry.hiddenByTags && !config.removeFromView }'
|
||||||
:class='{ hidden: entry.isHidden && !config.removeFromView }'
|
|
||||||
:hideWarnings='hideWarnings'
|
:hideWarnings='hideWarnings'
|
||||||
:id='id'
|
:id='id'
|
||||||
:viewPath='viewPath'
|
:viewPath='viewPath'
|
||||||
:isInternal='true'
|
:isInternal='true'
|
||||||
:entry='entry'
|
:entry='entry.entry'
|
||||||
)
|
)
|
||||||
ArticleTile(
|
ArticleTile(
|
||||||
v-else-if='template === "article-list"'
|
v-else-if='template === "article-list" && (!entry.hiddenByTags || !config.removeFromView)'
|
||||||
ref='tiles'
|
:class='{ hidden: entry.hiddenByTags && !config.removeFromView }'
|
||||||
:class='{ hidden: entry.isHidden && !config.removeFromView }'
|
|
||||||
:hideWarnings='hideWarnings'
|
:hideWarnings='hideWarnings'
|
||||||
:id='id'
|
:id='id'
|
||||||
:viewPath='viewPath'
|
:viewPath='viewPath'
|
||||||
|
|
Loading…
Add table
Reference in a new issue