Skip to content

Commit

Permalink
feat(odin): split componets for relay
Browse files Browse the repository at this point in the history
  • Loading branch information
cansirin committed Dec 24, 2023
1 parent 7caec25 commit 04e182a
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 49 deletions.
15 changes: 10 additions & 5 deletions apps/kampus/app/odin/mufredat/[[...lesson]]/OdinLesson.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
"use client";

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

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

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 @@ -18,8 +22,9 @@ export const OdinLessonContainer = (props: Props) => {
odin {
lesson(id: $id) {
body {
html
...OdinLessonBody_body
}
...OdinLessonTitle_title
}
}
}
Expand All @@ -30,9 +35,9 @@ export const OdinLessonContainer = (props: Props) => {
const lesson = data.odin.lesson;

return (
<div
className="prose dark:prose-invert lg:prose-xl hover:prose-a:text-blue-500"
dangerouslySetInnerHTML={{ __html: lesson?.body?.html ?? "" }}
/>
<>
<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.

0 comments on commit 04e182a

Please sign in to comment.