Skip to content

Commit

Permalink
fixes: Lesson Template and ClientOnly (#600)
Browse files Browse the repository at this point in the history
* fixing missing materials section

* fixing remaining issues on EDU Lesson template

* adding mock component for ClientOnly (nuxt-only) in Storybook

* fixing vue build errors
  • Loading branch information
stephiescastle authored Sep 5, 2024
1 parent 5fec399 commit 2269489
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 39 deletions.
5 changes: 5 additions & 0 deletions apps/vue-storybook/.storybook/_mock-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ export default (app) => {
'<a href="#" @click.prevent="log()" :class="this.class" v-bind="$attrs"><slot></slot></a>'
})

// Nuxt ClientOnly
app.component('ClientOnly', {
template: '<slot></slot>'
})

// use static dsn widget instead of fetch
app.component('FetchDsnWidget', DsnWidget)
}
1 change: 0 additions & 1 deletion packages/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"twitter-widgets": "^2.0.0",
"vue": "^3.4.21",
"vue-bind-once": "^0.2.1",
"vue-observe-visibility": "^1.0.0",
"vue3-compare-image": "^1.2.5",
"vue3-observe-visibility": "^1.0.1"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<template>
<div v-if="data">
<VueCompareImage
v-if="theBeforeImageSrc && theAfterImageSrc"
class="h-full animate-fadeIn"
:left-image="theBeforeImageSrc.url"
left-image-alt="Left image"
:right-image="theAfterImageSrc.url"
right-image-alt="Right image"
/>
<ClientOnly>
<VueCompareImage
v-if="theBeforeImageSrc && theAfterImageSrc"
class="h-full animate-fadeIn"
:left-image="theBeforeImageSrc.url"
left-image-alt="Left image"
:right-image="theAfterImageSrc.url"
right-image-alt="Right image"
/>
</ClientOnly>
<div
v-if="data.caption || customDetailUrl"
class="lg:px-0 p-4 pb-0 print:pl-0"
Expand Down
27 changes: 15 additions & 12 deletions packages/vue/src/templates/edu/PageEduLesson/PageEduLesson.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<script setup lang="ts">
import { computed, reactive, ref } from 'vue'
import type {
BlockData,
ImageObject,
PageEduResourcesObject,
StreamfieldBlockData
Expand All @@ -24,13 +23,15 @@ import AboutTheAuthor from './../../../components/AboutTheAuthor/AboutTheAuthor.
import { HeadingLevel } from '../../../components/BaseHeading/BaseHeading.vue'
interface EduLessonSectionObject extends PageEduLessonSectionProps {
type?: 'streamfield'
type?: string
}
interface EduLessonProcedureBlocks {
blocks: StreamfieldBlockData[]
}
interface EduLessonProcedure {
procedure: EduLessonProcedureBlocks
export interface EduLessonProcedure {
sectionHeading?: string
steps?: EduLessonProcedureBlocks[]
stepsNumbering?: boolean
}
interface PageEduLessonObject extends PageEduResourcesObject {
Expand Down Expand Up @@ -193,8 +194,8 @@ const consolidatedBlocks = computed(() => {
} else if (section === 'procedures' && data.procedures?.length) {
// get blocks in nested procedures
data.procedures.forEach((item) => {
if (item.procedure?.blocks?.length) {
blocks.push(...item.procedure.blocks)
if (item.steps?.length) {
blocks.push(...item.steps)
}
})
}
Expand All @@ -218,17 +219,15 @@ const consolidatedBlocks = computed(() => {
// organize data to render with PageEduLessonSection component
const consolidatedSections = computed((): EduLessonSectionObject[] => {
const sections = []
const sections: EduLessonSectionObject[] = []
// include custom top section
if (keyedCustomSections.value && keyedCustomSections.value['top']) {
sections.push({ type: 'streamfield', blocks: keyedCustomSections.value['top'] })
}
sectionOrder.forEach((section) => {
if (data && data[section]) {
sections.push({
heading: staticSectionHeadings.value
? (staticSectionHeadings.value[section] as BlockData)
: undefined,
heading: staticSectionHeadings.value ? staticSectionHeadings.value[section] : undefined,
blocks: section !== 'materials' && section !== 'procedures' ? data[section] : undefined,
text: section === 'materials' ? data[section] : undefined,
procedures: section === 'procedures' ? data[section] : undefined
Expand All @@ -243,7 +242,11 @@ const consolidatedSections = computed((): EduLessonSectionObject[] => {
if (keyedCustomSections.value && keyedCustomSections.value['bottom']) {
sections.push({ type: 'streamfield', blocks: keyedCustomSections.value['bottom'] })
}
return sections as EduLessonSectionObject[]
const filteredSections = sections.filter(
(item) => item.text !== undefined || item.blocks !== undefined || item.procedures !== undefined
)
return filteredSections
})
</script>
<template>
Expand Down Expand Up @@ -332,7 +335,7 @@ const consolidatedSections = computed((): EduLessonSectionObject[] => {
v-for="(value, _key) in consolidatedSections"
:key="_key"
>
<template v-if="value.blocks?.length || value.procedures?.length">
<template v-if="value.blocks?.length || value.procedures?.length || value.text?.length">
<BlockStreamfield
v-if="value.type === 'streamfield'"
:data="value.blocks"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,17 @@ import type { ImageObject, StreamfieldBlockData } from './../../../interfaces'
import BlockHeading, {
type BlockHeadingObject
} from './../../../components/BlockHeading/BlockHeading.vue'
import type { EduLessonProcedure } from './PageEduLesson.vue'
import BaseHeading from './../../../components/BaseHeading/BaseHeading.vue'
import BlockText from './../../../components/BlockText/BlockText.vue'
import LayoutHelper from './../../../components/LayoutHelper/LayoutHelper.vue'
import BlockImageStandard from './../../../components/BlockImage/BlockImageStandard.vue'
import BlockStreamfield from './../../../components/BlockStreamfield/BlockStreamfield.vue'
export interface PageEduLessonSectionProps {
heading: BlockHeadingObject
heading?: BlockHeadingObject
blocks?: StreamfieldBlockData[]
procedures?: {
sectionHeading: string
stepsNumbering: boolean
steps: {
blocks: StreamfieldBlockData[]
}[]
}[]
procedures?: EduLessonProcedure[]
text?: string
image?: ImageObject
}
Expand All @@ -36,14 +31,14 @@ const props = withDefaults(defineProps<PageEduLessonSectionProps>(), {
const { heading, blocks, image } = reactive(props)
const anchorId = computed(() => {
return 'lesson_' + camelCase(heading.heading)
return 'lesson_' + camelCase(heading?.heading)
})
</script>
<template>
<section
:id="anchorId"
class="PageEduLessonSection"
:aria-label="heading.heading"
:aria-label="heading?.heading"
>
<LayoutHelper
indent="col-3"
Expand Down
8 changes: 0 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2269489

Please sign in to comment.