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