Skip to content

Commit

Permalink
feat(odin): Content pipeline (#710)
Browse files Browse the repository at this point in the history
Now we are rendering html with typography elements coming from
"tailwind"

---------

Co-authored-by: Can Sirin <[email protected]>
  • Loading branch information
cansirin and cansirin authored Dec 24, 2023
1 parent 9e2e45d commit 3b2298e
Show file tree
Hide file tree
Showing 54 changed files with 10,452 additions and 4,458 deletions.
37 changes: 6 additions & 31 deletions apps/kampus/app/odin/mufredat/[[...lesson]]/OdinLesson.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
"use client";

import Markdown from "react-markdown";
import { graphql, usePreloadedQuery } from "react-relay";

import { type SerializablePreloadedQuery } from "@kampus/relay";
import useSerializablePreloadedQuery from "@kampus/relay/use-serializable-preloaded-query";

import {
TypographyBlockquote,
TypographyH1,
TypographyH2,
TypographyH3,
TypographyH4,
TypographyInlineCode,
TypographyList,
TypographyP,
} from "~/../../packages/ui";
import { type OdinLessonQuery } from "~/app/odin/mufredat/[[...lesson]]/__generated__/OdinLessonQuery.graphql";
import { OdinLessonBody } from "./OdinLessonBody";
import { OdinLessonTitle } from "./OdinLessonTitle";

interface Props {
preloadedQuery: SerializablePreloadedQuery<OdinLessonQuery>;
Expand All @@ -30,11 +21,10 @@ export const OdinLessonContainer = (props: Props) => {
query OdinLessonQuery($id: ID!) {
odin {
lesson(id: $id) {
title
body {
html
raw
...OdinLessonBody_body
}
...OdinLessonTitle_title
}
}
}
Expand All @@ -46,23 +36,8 @@ export const OdinLessonContainer = (props: Props) => {

return (
<>
<Markdown
components={{
h1: ({ ...props }) => <TypographyH1 {...props} />,
h2: ({ ...props }) => <TypographyH2 {...props} />,
h3: ({ ...props }) => <TypographyH3 {...props} />,
h4: ({ ...props }) => <TypographyH4 {...props} />,
p: ({ ...props }) => <TypographyP {...props} />,
a: ({ ...props }) => (
<a {...props} className="underline" target="_blank" rel="noopener noreferrer" />
),
blockquote: ({ ...props }) => <TypographyBlockquote {...props} />,
code: ({ ...props }) => <TypographyInlineCode {...props} />,
ul: ({ ...props }) => <TypographyList {...props} />,
}}
>
{lesson?.body.html}
</Markdown>
<OdinLessonTitle lesson={data.odin.lesson} />
<OdinLessonBody body={lesson?.body ?? null} />
</>
);
};
28 changes: 28 additions & 0 deletions apps/kampus/app/odin/mufredat/[[...lesson]]/OdinLessonBody.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { graphql, useFragment } from "react-relay";

import { type OdinLessonBody_body$key } from "./__generated__/OdinLessonBody_body.graphql";

interface Props {
body: OdinLessonBody_body$key | null;
}

const useOdinLessonBodyFragment = (key: OdinLessonBody_body$key | null) =>
useFragment(
graphql`
fragment OdinLessonBody_body on OdinLessonBody {
html
}
`,
key
);

export const OdinLessonBody = (props: Props) => {
const body = useOdinLessonBodyFragment(props.body);

return (
<div
className="prose dark:prose-invert hover:prose-a:text-blue-500"
dangerouslySetInnerHTML={{ __html: body?.html ?? "" }}
/>
);
};
23 changes: 23 additions & 0 deletions apps/kampus/app/odin/mufredat/[[...lesson]]/OdinLessonTitle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { graphql, useFragment } from "react-relay";

import { type OdinLessonTitle_title$key } from "./__generated__/OdinLessonTitle_title.graphql";

interface Props {
lesson: OdinLessonTitle_title$key | null;
}

const useOdinLessonTitleFragment = (key: OdinLessonTitle_title$key | null) =>
useFragment(
graphql`
fragment OdinLessonTitle_title on OdinLesson {
title
}
`,
key
);

export const OdinLessonTitle = (props: Props) => {
const lesson = useOdinLessonTitleFragment(props.lesson);

return <h2 className="text-3xl font-bold">{lesson?.title}</h2>;
};

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions apps/kampus/app/odin/mufredat/[[...lesson]]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import OdinLessonQueryNode, {
} from "~/app/odin/mufredat/[[...lesson]]/__generated__/OdinLessonQuery.graphql";
import { OdinLessonContainer } from "~/app/odin/mufredat/[[...lesson]]/OdinLesson";

export const dynamic = "force-dynamic";

export default async function OdinLessonPage({ params }: { params: { lesson: string[] } }) {
const id = params.lesson ? params.lesson.join("/") : "mufredat";

Expand Down
Loading

0 comments on commit 3b2298e

Please sign in to comment.