-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move the layouts in the frontend to a separate component
- Loading branch information
Showing
8 changed files
with
239 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<script setup lang="ts"> | ||
import type { NodeUnion, ParagraphUnion } from '#build/graphql-operations' | ||
import type { LayoutSection } from '~/types/layout-section' | ||
const props = defineProps({ | ||
page: { | ||
type: Object as PropType<NodeUnion>, | ||
required: true, | ||
}, | ||
}) | ||
const layout = computed<LayoutSection[]>(() => { | ||
if (!props.page.layout) | ||
return [] | ||
const sections: ParagraphUnion[] = props.page.layout.filter( | ||
item => item.__typename === 'ParagraphLayout', | ||
) | ||
sections.forEach((section: LayoutSection) => { | ||
if (!props.page.layout) | ||
return | ||
const children = props.page.layout.filter( | ||
item => item.composition?.position?.parentId === section.id, | ||
) | ||
section.children = {} | ||
// Add the components to their respective regions. | ||
for (const child of children) { | ||
if (!child.composition.position?.region) | ||
continue | ||
if (!section.children[child.composition.position.region]) | ||
section.children[child.composition.position.region] = [] | ||
const component = { ...child } as any | ||
delete component.composition | ||
section.children[child.composition.position.region].push(component) | ||
} | ||
// Add empty regions to the layout. | ||
for (const region of section.composition.layout?.regions || []) { | ||
if (!section.children[region]) | ||
section.children[region] = [] | ||
} | ||
// Sort the regions by the order they appear in the layout. | ||
section.children = Object.fromEntries( | ||
Object.entries(section.children).sort(([a], [b]) => { | ||
const aIndex = section.composition.layout?.regions?.indexOf(a) ?? -1 | ||
const bIndex = section.composition.layout?.regions?.indexOf(b) ?? -1 | ||
return aIndex - bIndex | ||
}), | ||
) | ||
}) | ||
return sections | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div class="flex flex-col max-w-6xl gap-8 m-auto"> | ||
<BasePageTitle v-if="page?.showTitle"> | ||
{{ page?.title }} | ||
</BasePageTitle> | ||
|
||
<div | ||
v-for="sections in layout" | ||
:key="sections.id" | ||
class="flex flex-wrap" | ||
> | ||
<div | ||
v-for="(section, section_name) in sections.children" | ||
:key="section_name" | ||
class="flex-1" | ||
> | ||
<div | ||
v-for="(component, component_name) in section" | ||
:key="component_name" | ||
> | ||
<component | ||
:is="component.__typename" | ||
v-bind="component" | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.