Skip to content

Commit

Permalink
fix: fields coming from metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
nomadbitcoin committed Aug 5, 2024
1 parent 5831ed2 commit 36fd8e1
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions pages/courses/[id].js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ function Course({ course, currentDate }) {
const [loading, setLoading] = useState(true)
const { t, i18n } = useTranslation()
const language = i18n.resolvedLanguage
const courseTitle = course?.metadata?.[language]?.title || course?.title
const courseDescription = course?.metadata?.[language]?.description || course?.description
const courseSections = course?.metadata?.[language]?.sections || course?.sections

useEffect(() => {
if (course?.metadata && !course.metadata.hasOwnProperty(language)) {
Expand Down Expand Up @@ -178,10 +181,9 @@ function Course({ course, currentDate }) {
}, [cohort])

function renderSections(course, language) {
const sections = course?.metadata?.[language]?.sections || course?.sections
if (!sections) return null
if (!courseSections) return null

return Object.keys(sections)
return Object.keys(courseSections)
.sort()
.map((section) => {
const sectionNumber = section.replace('Section_', '')
Expand All @@ -191,7 +193,7 @@ function Course({ course, currentDate }) {
{t('section') + ' ' + sectionNumber}
</span>
<ul className="mt-4 mb-4 flex list-none flex-col">
{sections[section]
{courseSections[section]
.sort((a, b) => a.title.localeCompare(b.title))
.map((lesson) => (
<li key={lesson.title} className="mb-4 items-center rounded py-2 px-4">
Expand Down Expand Up @@ -366,8 +368,8 @@ function Course({ course, currentDate }) {
<ICalendarLink
className="flex flex-row items-center text-white-100"
event={{
title: course?.title,
description: course?.description,
title: courseTitle,
description: courseDescription,
startTime: cohort?.kickoffStartTime,
endTime: cohort?.kickoffEndTime,
location: 'https://pt.discord.w3d.community',
Expand All @@ -384,7 +386,7 @@ function Course({ course, currentDate }) {
>
<img src="/assets/img/google-logo.svg" className="h-9 w-9" />
<a
href={`https://calendar.google.com/calendar/u/0/r/eventedit?dates=${kickoffStartDate}/${kickoffEndDate}&text=Bootcamp Web3dev ${course?.title}`}
href={`https://calendar.google.com/calendar/u/0/r/eventedit?dates=${kickoffStartDate}/${kickoffEndDate}&text=Bootcamp Web3dev ${courseTitle}`}
target="_blank"
>
<p className="text-sm font-bold text-white-100">
Expand Down

0 comments on commit 36fd8e1

Please sign in to comment.