Skip to content

Commit

Permalink
feat(ewd): talk embeds
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtaholik committed Mar 14, 2024
1 parent 30ff3e4 commit 838774f
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 7 deletions.
49 changes: 49 additions & 0 deletions apps/epic-web/src/pages/talks/[talk]/embed.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React from 'react'
import {GetServerSideProps} from 'next'
import EmbedTemplate, {VideoEmbedPageProps} from 'templates/embed-template'
import {getPropsForEmbed} from 'utils/get-props-for-embeds'

export const getServerSideProps: GetServerSideProps = async (context) => {
const props = await getPropsForEmbed(context, 'talk', false)

if (!props) {
return {
notFound: true,
}
}

const {
module,
section,
lesson,
videoResourceId,
videoResource,
theme,
login: {providers, csrfToken},
convertkitSubscriber,
abilityRules,
} = props

return {
props: {
module,
section,
lesson,
videoResourceId,
videoResource,
theme,
login: {
providers,
csrfToken,
},
convertkitSubscriber,
abilityRules,
},
}
}

const LessonEmbed: React.FC<VideoEmbedPageProps> = (props) => {
return <EmbedTemplate {...props} />
}

export default LessonEmbed
File renamed without changes.
29 changes: 22 additions & 7 deletions apps/epic-web/src/utils/get-props-for-embeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,32 @@ import {getTutorial} from 'lib/tutorials'
import {getTip} from 'lib/tips'
import {Exercise} from '@skillrecordings/skill-lesson/schemas/exercise'
import {getBonus} from 'lib/bonuses'
import {getTalk} from 'lib/talks'

export const getPropsForEmbed = async (
context: GetServerSidePropsContext<ParsedUrlQuery, PreviewData>,
resourceType: 'tutorial' | 'workshop' | 'tip' | 'bonus',
resourceType: 'tutorial' | 'workshop' | 'tip' | 'bonus' | 'talk',
isSolution?: boolean,
) => {
// resource
const {query} = context
const {params} = context
const lessonSlug = (params?.lesson || params?.tip) as string
const lessonSlug = (params?.lesson || params?.tip || params?.talk) as string
const sectionSlug = params?.section as string
const moduleSlug = params?.module as string
const module = await getModule(resourceType, moduleSlug)
const section = await getSection(sectionSlug)
const lesson =
resourceType === 'tip'
? ((await getTip(lessonSlug)) as Exercise)
: await getExercise(lessonSlug, false)
const getLesson = async () => {
switch (resourceType) {
case 'tip':
return (await getTip(lessonSlug)) as Exercise
case 'talk':
return (await getTalk(lessonSlug)) as Exercise
default:
return await getExercise(lessonSlug, false)
}
}
const lesson = await getLesson()

if (!lesson) {
return null
Expand Down Expand Up @@ -113,7 +121,7 @@ export const getPropsForEmbed = async (
}

const getModule = async (
type: 'tutorial' | 'workshop' | 'tip' | 'bonus',
type: 'tutorial' | 'workshop' | 'tip' | 'bonus' | 'talk',
slug: string,
) => {
switch (type) {
Expand All @@ -123,6 +131,13 @@ const getModule = async (
return await getWorkshop(slug)
case 'bonus':
return await getBonus(slug)
case 'talk':
return {
moduleType: 'talk',
slug: {
current: 'talks',
},
}
case 'tip':
return {
moduleType: 'tip',
Expand Down

0 comments on commit 838774f

Please sign in to comment.