Skip to content

Commit

Permalink
feat: create category/embedded page #173
Browse files Browse the repository at this point in the history
  • Loading branch information
wazolab committed Mar 18, 2024
1 parent 152c0f9 commit 7379fb0
Showing 1 changed file with 113 additions and 0 deletions.
113 changes: 113 additions & 0 deletions pages/category/embedded/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<script setup lang="ts">
import { vidoConfig } from '~/plugins/vido-config'
import { getMenu } from '~/lib/apiMenu'
import { type PropertyTranslations, getPropertyTranslations } from '~/lib/apiPropertyTranslations'
import { type Settings, getSettings, headerFromSettings } from '~/lib/apiSettings'
import { menuStore as useMenuStore } from '~/stores/menu'
import { siteStore as useSiteStore } from '~/stores/site'
import PoisTable from '~/components/PoisList/PoisTable.vue'

Check failure on line 8 in pages/category/embedded/index.vue

View workflow job for this annotation

GitHub Actions / Lint code base (ubuntu-latest, 18)

'PoisTable' is defined but never used
import CategorySelector from '~/components/PoisList/CategorySelector.vue'
const siteStore = useSiteStore()
const { $vidoConfigSet, $settings, $propertyTranslations, $trackingInit } = useNuxtApp()
// TODO: Get this globally as share it across components / pages
let config = siteStore.config
if (process.server && !config) {
config = vidoConfig(useRequestHeaders())
$vidoConfigSet(config)
siteStore.$patch({ config })
}
if (!config)
throw createError({ statusCode: 500, statusMessage: 'Wrong config', fatal: true })
// Fetch common data
// TODO: Move common data on upper-level (ex: layout)
const categoryListData = ref<{
settings: Settings
translations: PropertyTranslations
}>()
const { data: cachedCategoryListData } = useNuxtData('categoryList')
if (cachedCategoryListData.value) {
categoryListData.value = cachedCategoryListData.value
}
else {
const { data, error } = await useAsyncData('categoryList', async () => {
const [settings, translations] = await Promise.all([
getSettings(config!),
getPropertyTranslations(config!),
])
return { settings, translations }
})
if (error.value || !data.value)
throw createError({ statusCode: 500, statusMessage: 'Global config not found.', fatal: true })
categoryListData.value = data.value
}
// MenuItems
const menuStore = useMenuStore()
const { data: cachedMenuItems } = useNuxtData('menu-items')
if (cachedMenuItems.value) {
menuStore.fetchConfig(cachedMenuItems.value)
}
else {
const { data, error } = await useAsyncData('menu-items', async () => await getMenu(config!))
if (error.value || !data.value)
throw createError({ statusCode: 404, statusMessage: 'Menu not found', fatal: true })
menuStore.fetchConfig(data.value)
}
const { settings, translations } = categoryListData.value!
useHead(headerFromSettings(settings))
// Not sure about future usage as we could have data from useNuxtData
$settings.set(settings)
$propertyTranslations.set(translations)
if (process.client)
$trackingInit(config)
const router = useRouter()
function onCategoryUpdate(categoryId: number) {
if (!categoryId)
return
router.push(`/category/embedded/${categoryId}`)
}
</script>

<template>
<div>
<CategorySelector
class="w-50"
:menu-items="menuStore.menuItems || {}"
@category-change="onCategoryUpdate"
/>
<!-- <PoisTable /> -->
</div>
</template>

<style lang="scss" scoped>
@import '~/assets/details';
.page-index {
color: $color-text;
background-color: #fefefe;
padding: 1rem;
min-width: 21rem;
-webkit-font-smoothing: antialiased;
text-rendering: optimizelegibility;
line-height: 1.3;
word-wrap: break-word;
@extend %font-light;
}
</style>

0 comments on commit 7379fb0

Please sign in to comment.