Skip to content

Commit

Permalink
feat: with the db
Browse files Browse the repository at this point in the history
  • Loading branch information
joelhooks committed Feb 15, 2024
1 parent f1349ff commit 311165d
Show file tree
Hide file tree
Showing 13 changed files with 92,465 additions and 93,267 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ SENTRY_DSN="your-dsn"
GITHUB_CLIENT_ID="MOCK_GITHUB_CLIENT_ID"
GITHUB_CLIENT_SECRET="MOCK_GITHUB_CLIENT_SECRET"
GITHUB_TOKEN="MOCK_GITHUB_TOKEN"

MUX_TOKEN_ID="MUX_TOKEN_ID"
MUX_TOKEN_SECRET="MUX_TOKEN_SECRET"
185,232 changes: 92,077 additions & 93,155 deletions app/data/playlists-short.js

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions app/inngest/inngest.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {inngest} from '#app/inngest/inngest.server'

import { inngest } from '#app/inngest/inngest.server'

export const inngestConfig = {
client: inngest,
functions: [],
client: inngest,
functions: [],
}
6 changes: 3 additions & 3 deletions app/inngest/inngest.server.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {EventSchemas, Inngest} from 'inngest'
import { EventSchemas, Inngest } from 'inngest'

// Create a client to send and receive events
type Events = {}
export const inngest = new Inngest({
id: 'epic-egghead',
schemas: new EventSchemas().fromRecord<Events>(),
id: 'epic-egghead',
schemas: new EventSchemas().fromRecord<Events>(),
})
5 changes: 4 additions & 1 deletion app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ export const links: LinksFunction = () => {
export const meta: MetaFunction<typeof loader> = ({ data }) => {
return [
{ title: data ? 'egghead' : 'Error | egghead' },
{ name: 'description', content: `bite-sized video courses for busy developers` },
{
name: 'description',
content: `bite-sized video courses for busy developers`,
},
]
}

Expand Down
83 changes: 57 additions & 26 deletions app/routes/_content+/courses+/$course+/$lesson.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,67 @@
import {useLoaderData} from "#node_modules/@remix-run/react";
import { useLoaderData } from '#node_modules/@remix-run/react'
import { invariantResponse } from '@epic-web/invariant'
import { json, type LoaderFunctionArgs } from '@remix-run/node'
import {courses} from "#app/data/playlists-short"

import { prisma } from '#app/utils/db.server.ts'
import MuxPlayer from '@mux/mux-player-react'

Check warning on line 5 in app/routes/_content+/courses+/$course+/$lesson.tsx

View workflow job for this annotation

GitHub Actions / ⬣ ESLint

`@mux/mux-player-react` import should occur before import of `@remix-run/node`

export async function loader({ params }: LoaderFunctionArgs) {
console.log({params})
const course = courses.find(course => course.slug === params.course)
const lesson = course?.lessons.find(lesson => lesson.slug === params.lesson)
console.log({ params })

// const lesson = course?.lessons.find(lesson => lesson.slug === params.lesson)
// invariantResponse(lesson, 'Lesson not found', { status: 404 })
const lesson = await prisma.lesson.findFirst({
where: {
slug: params.lesson,
},
include: {
video: true,
course: {
include: {
instructor: true,
},
},
},
})

invariantResponse(lesson, 'Lesson not found', { status: 404 })

console.log({ lesson: lesson.video })

invariantResponse(lesson, 'Lesson not found', { status: 404 })
const muxAsset = await fetch(
`https://api.mux.com/video/v1/assets/${lesson.video?.mux_asset_id}`,
{
headers: {
Authorization: `Basic ${Buffer.from(
`${process.env.MUX_TOKEN_ID}:${process.env.MUX_TOKEN_SECRET}`,
).toString('base64')}`,
'Content-Type': 'application/json',
},
},
)
.then(res => res.json())
.then((data: any) => data?.data)

return json({ course, lesson })
return json({ course: lesson.course, lesson, muxAsset })
}

export default function LessonRoute() {
const data = useLoaderData<typeof loader>()
const lesson = data.lesson

return (
<div className="container mb-48 mt-36 flex flex-col items-center justify-center">
<div className="relative">
{lesson.title} by {lesson.instructor}
{lesson.image && (
<img
src={lesson.image}
alt={lesson.title}
className="h-52 w-52 object-cover"
/>
)}
</div>
</div>
)
}
const { course, lesson, muxAsset } = useLoaderData<typeof loader>()

console.log(muxAsset)

return (
<div className="container mb-48 mt-36 flex flex-col items-center justify-center">
<div className="relative">
{lesson.title} by {course?.instructor?.full_name}
{course?.image_url && (
<img
src={course?.image_url}
alt={lesson.title}
className="h-52 w-52 object-cover"
/>
)}
<MuxPlayer playbackId={muxAsset.playback_ids[0].id} />
</div>
</div>
)
}
71 changes: 42 additions & 29 deletions app/routes/_content+/courses+/$course+/index.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,52 @@
import {useLoaderData} from "#node_modules/@remix-run/react";
import { useLoaderData } from '#node_modules/@remix-run/react'
import { invariantResponse } from '@epic-web/invariant'
import { json, type LoaderFunctionArgs } from '@remix-run/node'
import {Link} from "@remix-run/react";
import {courses} from "#app/data/playlists-short"

import { Link } from '@remix-run/react'
import { prisma } from '#app/utils/db.server.ts'

export async function loader({ params }: LoaderFunctionArgs) {
const course = courses.find(course => course.slug === params.course)
const course = await prisma.course.findFirst({
where: {
slug: params.course,
},
include: {
lessons: true,
instructor: true,
},
})

invariantResponse(course, 'Course not found', { status: 404 })
invariantResponse(course, 'Course not found', { status: 404 })

return json({ course })
return json({ course })
}

export default function ProfileRoute() {
const data = useLoaderData<typeof loader>()
const course = data.course
const data = useLoaderData<typeof loader>()
const course = data.course

console.log(course)

return (
<div className="container mb-48 mt-36 flex flex-col items-center justify-center">
<div className="relative">
{course.title} by {course.instructor}
<img
src={course.image}
alt={course.title}
className="h-52 w-52 object-cover"
/>
<ul>
{course.lessons.map(lesson => (
<li key={lesson.id}>
<Link to={`/courses/${course.slug}/${lesson.slug}`}>{lesson.title}</Link>
</li>
))}
</ul>
</div>
</div>
)
}
return (
<div className="container mb-48 mt-36 flex flex-col items-center justify-center">
<div className="relative">
{course.title} by {course.instructor?.full_name}
{course.image_url && (
<img
src={course.image_url}
alt={course.title}
className="h-52 w-52 object-cover"
/>
)}
<ul>
{course.lessons.map(lesson => (
<li key={lesson.id}>
<Link to={`/courses/${course.slug}/${lesson.slug}`}>
{lesson.title}
</Link>
</li>
))}
</ul>
</div>
</div>
)
}
82 changes: 41 additions & 41 deletions app/routes/_content+/courses+/index.tsx
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
import {useLoaderData} from "#node_modules/@remix-run/react";
import { useLoaderData } from '#node_modules/@remix-run/react'
import { json } from '@remix-run/node'
import {Link} from "@remix-run/react";
import {GeneralErrorBoundary} from "#app/components/error-boundary.tsx";
import {ErrorList} from "#app/components/forms.tsx";
import {courses} from "#app/data/playlists-short"
import {cn, useDelayedIsPending} from "#app/utils/misc.tsx";
import { Link } from '@remix-run/react'
import { GeneralErrorBoundary } from '#app/components/error-boundary.tsx'
import { ErrorList } from '#app/components/forms.tsx'
import { cn, useDelayedIsPending } from '#app/utils/misc.tsx'
import { prisma } from '#app/utils/db.server.ts'

Check warning on line 7 in app/routes/_content+/courses+/index.tsx

View workflow job for this annotation

GitHub Actions / ⬣ ESLint

`#app/utils/db.server.ts` import should occur before import of `#app/utils/misc.tsx`

export async function loader() {
return json({ status: 'idle', courses } as const)
const courses = await prisma.course.findMany()
return json({ status: 'idle', courses } as const)
}

export default function Index() {
const data = useLoaderData<typeof loader>()
const isPending = useDelayedIsPending({
formMethod: 'GET',
formAction: '/courses',
})
const data = useLoaderData<typeof loader>()
const isPending = useDelayedIsPending({
formMethod: 'GET',
formAction: '/courses',
})


return (
<div className="container mb-48 mt-36 flex flex-col items-center justify-center gap-6">
<main>
{data.status === 'idle' ? (
data.courses.length ? (
<ul
className={cn(
'flex w-full flex-wrap items-center justify-center gap-4 delay-200',
{ 'opacity-50': isPending },
)}
>
{data.courses.map(course => (
<li key={course.id}>
<Link to={`/courses/${course.slug}`}>{course.title}</Link>
</li>
))}
</ul>
) : (
<p>No users found</p>
)
) : data.status === 'error' ? (
<ErrorList errors={['There was an error parsing the results']} />
) : null}
</main>
</div>
)
return (
<div className="container mb-48 mt-36 flex flex-col items-center justify-center gap-6">
<main>
{data.status === 'idle' ? (
data.courses.length ? (
<ul
className={cn(
'flex w-full flex-wrap items-center justify-center gap-4 delay-200',
{ 'opacity-50': isPending },
)}
>
{data.courses.map(course => (
<li key={course.id}>
<Link to={`/courses/${course.slug}`}>{course.title}</Link>
</li>
))}
</ul>
) : (
<p>No users found</p>
)
) : data.status === 'error' ? (
<ErrorList errors={['There was an error parsing the results']} />
) : null}
</main>
</div>
)
}

export function ErrorBoundary() {
return <GeneralErrorBoundary />
}
return <GeneralErrorBoundary />
}
4 changes: 1 addition & 3 deletions app/routes/_marketing+/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { type MetaFunction } from '@remix-run/node'
export const meta: MetaFunction = () => [{ title: 'egghead' }]


export default function Index() {
return (
<main className="font-poppins grid h-full place-items-center">
<div className="grid place-items-center px-4 py-16 xl:grid-cols-2 xl:gap-24">
<div className="flex max-w-md flex-col items-center text-center xl:order-2 xl:items-start xl:text-left">
<h1
data-heading
className="mt-8 animate-slide-top text-4xl font-medium text-foreground [animation-fill-mode:backwards] [animation-delay:0.3s] md:text-5xl xl:mt-4 xl:animate-slide-left xl:text-6xl xl:[animation-fill-mode:backwards] xl:[animation-delay:0.8s]"
className="mt-8 animate-slide-top text-4xl font-medium text-foreground [animation-delay:0.3s] [animation-fill-mode:backwards] md:text-5xl xl:mt-4 xl:animate-slide-left xl:text-6xl xl:[animation-delay:0.8s] xl:[animation-fill-mode:backwards]"
>
<a href="https://egghead.io">egghead</a>
</h1>
Expand All @@ -20,7 +19,6 @@ export default function Index() {
bite-sized video courses for busy web developers
</p>
</div>

</div>
</main>
)
Expand Down
8 changes: 4 additions & 4 deletions app/routes/api.inngest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { serve } from "inngest/remix";
import {inngestConfig} from "#app/inngest/inngest.config.ts";
import { serve } from 'inngest/remix'
import { inngestConfig } from '#app/inngest/inngest.config.ts'

const handler = serve(inngestConfig);
const handler = serve(inngestConfig)

export { handler as action, handler as loader };
export { handler as action, handler as loader }
Loading

0 comments on commit 311165d

Please sign in to comment.