Skip to content

Commit

Permalink
refactor: replace loadBasicLesson w/ loadLesson
Browse files Browse the repository at this point in the history
We are in the process of moving away from egghead-rails as the source of
lesson metadata. This moves us along that path by eliminating one of th
huge graphql queries for lesson metadata.

issue: #1138
  • Loading branch information
jbranchaud authored and kodiakhq[bot] committed Jul 20, 2022
1 parent 96ea1a9 commit 5876355
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 101 deletions.
95 changes: 0 additions & 95 deletions src/lib/lessons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,98 +165,3 @@ export async function loadLessonForUser(slug: string) {

return lesson as LessonResource
}

export async function loadBasicLesson(slug: string) {
const query = /* GraphQL */ `
query getLesson($slug: String!) {
lesson(slug: $slug) {
slug
title
transcript
description
free_forever
media_url
hls_url
thumb_url
subtitles_url
path
icon_url
created_at
updated_at
published_at
staff_notes_url
collection {
... on Playlist {
title
slug
type
square_cover_480_url
path
lessons {
slug
type
path
title
completed
media_url
duration
}
}
... on Course {
title
slug
type
square_cover_480_url
path
lessons {
slug
type
path
title
completed
media_url
duration
}
}
}
tags {
name
label
http_url
image_url
}
instructor {
full_name
avatar_64_url
slug
twitter
}
comments {
comment
commentable_id
commentable_type
created_at
id
is_commentable_owner
state
user {
avatar_url
full_name
instructor {
first_name
}
}
}
}
}
`

const variables = {
slug: slug,
}

const graphQLClient = getGraphQLClient()
const {lesson} = await graphQLClient.request(query, variables)

return lesson as LessonResource
}
4 changes: 2 additions & 2 deletions src/pages/lessons/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Overlays from 'components/pages/lessons/overlays'
import specialLessons from 'components/pages/lessons/special-lessons'
import Tags from 'components/pages/lessons/tags'
import Transcript from 'components/pages/lessons/transcript'
import {loadBasicLesson, loadLesson} from 'lib/lessons'
import {loadLesson} from 'lib/lessons'
import {useViewer} from 'context/viewer-context'
import {LessonResource, VideoResource} from 'types'
import {NextSeo, VideoJsonLd} from 'next-seo'
Expand Down Expand Up @@ -77,7 +77,7 @@ export const getServerSideProps: GetServerSideProps = async function ({

try {
const initialLesson: LessonResource | undefined =
params && (await loadBasicLesson(params.slug as string))
params && (await loadLesson(params.slug as string))

if (initialLesson && initialLesson?.slug !== params?.slug) {
res.setHeader('Location', initialLesson.path)
Expand Down
8 changes: 4 additions & 4 deletions src/pages/video-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {GetServerSideProps} from 'next'
import VideoResourcePlayer from 'components/player'
import {PlayerProvider} from 'cueplayer-react'
import {VideoResource} from 'types'
import {loadBasicLesson} from 'lib/lessons'
import {loadLesson} from 'lib/lessons'
import PlayerSidebar from 'components/player/player-sidebar'
import PlayerContainer from 'components/player/player-container'

Expand Down Expand Up @@ -39,10 +39,10 @@ export const getServerSideProps: GetServerSideProps = async function ({
params,
query,
}) {
const lesson =
const lessonSlug =
(query?.lesson as string) || 'react-a-beginners-guide-to-react-introduction'
const videoResource: VideoResource = (await loadBasicLesson(
lesson,
const videoResource: VideoResource = (await loadLesson(
lessonSlug,
)) as VideoResource

return {
Expand Down

2 comments on commit 5876355

@vercel
Copy link

@vercel vercel bot commented on 5876355 Jul 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 5876355 Jul 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.