re-implement amendVariantsWithDefaults
This commit is contained in:
parent
15ed807d8c
commit
42936273bf
5 changed files with 25 additions and 21 deletions
libs/types/src/content/templates
projects/frontend/src
|
@ -49,13 +49,13 @@ export type GalleryEntryInheritedProperties = {
|
|||
* and will be displayed with the tile
|
||||
*/
|
||||
warning?: string
|
||||
}
|
||||
} & ListWithEntries<GalleryEntryInheritedProperties>
|
||||
|
||||
/**
|
||||
* Defines an entry in a gallery that can be displayed in a tiled manner
|
||||
* and can be clicked by a visitor to display its variants or the entry itself if there are none
|
||||
*/
|
||||
export type GalleryEntryProperties = GalleryEntryInheritedProperties & {
|
||||
export type GalleryEntry = GalleryEntryInheritedProperties & {
|
||||
/**
|
||||
* the url to the thumbnail to show for the entry in the gallery tile
|
||||
*/
|
||||
|
@ -66,10 +66,6 @@ export type GalleryEntryProperties = GalleryEntryInheritedProperties & {
|
|||
url?: string
|
||||
}
|
||||
|
||||
export type GalleryEntry =
|
||||
& GalleryEntryProperties
|
||||
& ListWithEntries<GalleryEntryProperties>
|
||||
|
||||
/**
|
||||
* Defines the model of the `GalleryList` template
|
||||
*/
|
||||
|
|
|
@ -186,7 +186,7 @@ export const fetchConfigByIdFromList = async <T>(list: ListWithEntries<T> | List
|
|||
export const fetchNestedConfigs = async <T>(
|
||||
list: ListWithNestedEntries<T>,
|
||||
idsByDepth: string[],
|
||||
proccessCallback?: (t: T) => T,
|
||||
proccessCallback?: (parent: ListEntriesWithNestedEntries<T>, child: ListEntriesWithNestedEntries<T>) => ListEntriesWithNestedEntries<T>,
|
||||
): Promise<ListWithNestedEntries<T>> => {
|
||||
/* DOCUMENT STRUCTURE:
|
||||
...listConfig
|
||||
|
@ -213,7 +213,11 @@ export const fetchNestedConfigs = async <T>(
|
|||
let idsToLoop = [ ...idsByDepth ]
|
||||
let current = await fetchConfigByIdFromList(list, idsToLoop.shift()!) as ListEntriesWithNestedEntries<T>
|
||||
if (idsToLoop.length > 0) {
|
||||
resolve(await fetchNestedConfigs(current as any, idsToLoop))
|
||||
let next = await fetchNestedConfigs(current as any, idsToLoop) as ListEntriesWithNestedEntries<T>
|
||||
if (!!proccessCallback) {
|
||||
next = proccessCallback(current, next)
|
||||
}
|
||||
resolve(next)
|
||||
} else {
|
||||
resolve(current)
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import type {
|
|||
} from '@goldenwere/mackenzii-types'
|
||||
import { type RouteRecordRaw, useRouter } from 'vue-router'
|
||||
|
||||
import { amendVariantsWithDefaults } from './gallery-utilities'
|
||||
import { amendVariantsWithDefaults, _amendVariantWithDefaults } from './gallery-utilities'
|
||||
import { fetchAndParseYaml, fetchNestedConfigs, fetchConfigsFromList, storage } from 'src/utilities/fetch'
|
||||
import { getCurrentRoute } from 'src/utilities/vuetils'
|
||||
import { useRouteStore } from 'src/routes'
|
||||
|
@ -62,8 +62,9 @@ const onDisplayEntries = async () => {
|
|||
resetTags()
|
||||
galleryReady.value = false
|
||||
if (!!variants) {
|
||||
const value = await fetchNestedConfigs<GalleryEntry>(config, variants)
|
||||
entries.value = (await fetchConfigsFromList(value)).entries
|
||||
const value = await fetchNestedConfigs<GalleryEntry>(config, variants, _amendVariantWithDefaults)
|
||||
const children = (await fetchConfigsFromList(value)).entries
|
||||
entries.value = amendVariantsWithDefaults(value, children)
|
||||
} else {
|
||||
const value = await fetchConfigsFromList<GalleryEntry>(config)
|
||||
entries.value = value.entries
|
||||
|
@ -136,7 +137,7 @@ const onHideWarningsToggled = (event: Event) => {
|
|||
})
|
||||
} else {
|
||||
Object.keys(entries.value).forEach(entryId => {
|
||||
entries.value[entryId].isHidden = !entries.value[entryId].tags?.some(own => tagsToggled.includes(own))
|
||||
entries.value[entryId].isHidden = !entries.value[entryId].tags?.some((own: string) => tagsToggled.includes(own))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,13 +13,15 @@ export const getTitleFromEntryOrId = (entry: GalleryEntry, id: string) => (
|
|||
: id
|
||||
)
|
||||
|
||||
export const amendVariantsWithDefaults = (entry: GalleryEntry) => {
|
||||
// const variants = deepCopy(entry.variants)
|
||||
// if (!!variants) {
|
||||
// Object.keys(variants).forEach(id => _amendVariantWithDefaults(entry, variants[id]))
|
||||
// }
|
||||
export const amendVariantsWithDefaults = (parent: GalleryEntryInheritedProperties, children: GalleryEntryInheritedProperties) => {
|
||||
const _children = deepCopy(children)
|
||||
if (!!_children) {
|
||||
Object.keys(children).forEach(id => {
|
||||
_children[id] = _amendVariantWithDefaults(parent, children[id])
|
||||
})
|
||||
}
|
||||
|
||||
// return variants
|
||||
return _children
|
||||
}
|
||||
|
||||
export const _amendVariantWithDefaults = (parent: GalleryEntryInheritedProperties, variant: GalleryEntryInheritedProperties) => {
|
||||
|
|
|
@ -7,7 +7,7 @@ import type {
|
|||
RoutedWindow,
|
||||
} from '@goldenwere/mackenzii-types'
|
||||
|
||||
import { amendVariantsWithDefaults, getTitleFromEntryOrId } from './gallery-utilities'
|
||||
import { _amendVariantWithDefaults, getTitleFromEntryOrId } from './gallery-utilities'
|
||||
import { fetchAndParseYaml, fetchConfigByIdFromList, fetchNestedConfigs } from 'src/utilities/fetch'
|
||||
import { getCurrentRoute } from 'src/utilities/vuetils'
|
||||
import { useRouteStore } from 'src/routes'
|
||||
|
@ -46,8 +46,9 @@ onMounted(async () => {
|
|||
config.value = listConfig
|
||||
let ids = props.variants
|
||||
let viewId = ids.pop()!
|
||||
let entries = await fetchNestedConfigs(listConfig, ids)
|
||||
entry.value = await fetchConfigByIdFromList(entries, viewId)
|
||||
let entries = await fetchNestedConfigs(listConfig, ids, _amendVariantWithDefaults)
|
||||
let finalEntry = await fetchConfigByIdFromList<GalleryEntry>(entries, viewId)
|
||||
entry.value = _amendVariantWithDefaults(entries, finalEntry)
|
||||
id.value = props.variants[props.variants.length - 1]
|
||||
title.value = getTitleFromEntryOrId(entry.value, id.value)
|
||||
document.title = routeSubConfig.fullTitle?.replace('$ENTRY', title.value)
|
||||
|
|
Loading…
Add table
Reference in a new issue