Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing headings in edu lesson jump menus, adding generateHash #601

Merged
merged 2 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export const BaseStory = {
}
],

overview: BlockStreamfieldMinimalData.body,
overview: [],
overviewHeading: 'Custom Overview heading',
overviewImage: BlockImageData.image,

Expand Down
45 changes: 23 additions & 22 deletions packages/vue/src/templates/edu/PageEduLesson/PageEduLesson.vue
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,16 @@ const sectionOrder = [
const staticSectionHeadings = computed((): { [key: string]: BlockHeadingObject } | undefined => {
if (data) {
const result = sectionOrder.reduce<Record<string, BlockHeadingObject>>((acc, section) => {
const headingText =
section === 'techAddons'
? 'Tech Add-ons'
: section.charAt(0).toUpperCase() + section.slice(1)
acc[section] = stringAsHeadingBlockData(
(data[`${section}Heading`] as HeadingLevel) || headingText
)
// only include the heading if the section has content
if (data[section]?.length) {
const headingText =
section === 'techAddons'
? 'Tech Add-ons'
: section.charAt(0).toUpperCase() + section.slice(1)
acc[section] = stringAsHeadingBlockData(
(data[`${section}Heading`] as HeadingLevel) || headingText
)
}
return acc
}, {})
return result
Expand Down Expand Up @@ -243,7 +246,7 @@ const consolidatedSections = computed((): EduLessonSectionObject[] => {
sections.push({ type: 'streamfield', blocks: keyedCustomSections.value['bottom'] })
}
const filteredSections = sections.filter(
(item) => item.text !== undefined || item.blocks !== undefined || item.procedures !== undefined
(item) => item.text || item.blocks?.length || item.procedures?.length
)

return filteredSections
Expand Down Expand Up @@ -335,20 +338,18 @@ const consolidatedSections = computed((): EduLessonSectionObject[] => {
v-for="(value, _key) in consolidatedSections"
:key="_key"
>
<template v-if="value.blocks?.length || value.procedures?.length || value.text?.length">
<BlockStreamfield
v-if="value.type === 'streamfield'"
:data="value.blocks"
/>
<PageEduLessonSection
v-else
:heading="value.heading"
:blocks="value.blocks"
:procedures="value.procedures"
:text="value.text"
:image="value.image"
/>
</template>
<BlockStreamfield
v-if="value.type === 'streamfield'"
:data="value.blocks"
/>
<PageEduLessonSection
v-else
:heading="value.heading"
:blocks="value.blocks"
:procedures="value.procedures"
:text="value.text"
:image="value.image"
/>
</template>

<!-- streamfield blocks -->
Expand Down
9 changes: 9 additions & 0 deletions packages/vue/src/utils/generateHash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export function generateHash(str: string): number {
let hash = 0
for (let i = 0, len = str.length; i < len; i++) {
let chr = str.charCodeAt(i)
hash = (hash << 5) - hash + chr
hash |= 0 // Convert to 32bit integer
}
return hash
}