Skip to content
This repository has been archived by the owner on Dec 3, 2022. It is now read-only.

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
imbhargav5 committed Jul 16, 2021
1 parent a172b8e commit 9de24a3
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 194 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"react-no-ssr": "^1.1.0",
"react-relay": "^0.0.0-experimental-4c4107dd",
"relay-compiler-language-typescript": "^14.0.0",
"relay-nextjs": "^0.1.2",
"relay-nextjs": "^0.3.0",
"relay-runtime": "^11.0.2",
"rooks": "^5.0.2-alpha.1",
"styled-components": "^5.3.0",
Expand Down

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.

5 changes: 5 additions & 0 deletions src/config/relay/server/getRelayServerEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ export const fetchQuery = async (
return fromCache;
}

console.log(JSON.stringify({
query: operation.text,
variables,
}))

const response = await fetch(APP_CONFIG.API_URL, {
body: JSON.stringify({
query: operation.text,
Expand Down
13 changes: 6 additions & 7 deletions src/features/chapters/ChapterById.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import * as React from 'react';
import { graphql, useFragment } from 'react-relay/hooks';
import Link from 'next/link';
import { Slug_GitaChapterQueryResponse } from '@/__generated__/Slug_GitaChapterQuery.graphql';
import {
ChapterById_ChapterDataFragment,
ChapterById_ChapterDataFragment$key,
} from '@/__generated__/ChapterById_ChapterDataFragment.graphql';
import { GitaChapter } from '@/types/api';

type ChapterByIdProps = {
query: Slug_GitaChapterQueryResponse;
chapterById: ChapterById_ChapterDataFragment$key;
};

export function ChapterById({ query }: ChapterByIdProps) {
const data = useFragment<ChapterById_ChapterDataFragment$key>(
export function ChapterById({ chapterById }: ChapterByIdProps) {
const data = useFragment(
graphql`
fragment ChapterById_ChapterDataFragment on GitaChapter {
name
Expand All @@ -38,8 +36,9 @@ export function ChapterById({ query }: ChapterByIdProps) {
}
}
`,
query.GitaChapter
chapterById
);
console.log(data);
if (!data || !data.verses) {
return null;
}
Expand Down Expand Up @@ -77,7 +76,7 @@ export function ChapterById({ query }: ChapterByIdProps) {
</h2>
<p className="text-gray-500">{verse.text}</p>
<p>
<Link href={`/verse/${verse._id}/fakeslug`}>
<Link href={`/verse/${verse.verse_order}`}>
<a className="text-indigo-500 inline-flex items-center mt-4">
View Verse
</a>
Expand Down
4 changes: 1 addition & 3 deletions src/features/chapters/ChaptersList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ export function ChaptersList({
</h2>
<p className="leading-relaxed text-base">{chapter.name} </p>
<p>
<Link
href={`/chapter/${chapter._id}/${chapter.slug?.current}`}
>
<Link href={`/chapter/${chapter.chapter_number}`}>
<a className="text-indigo-500 inline-flex items-center mt-4">
View Chapter
</a>
Expand Down
27 changes: 14 additions & 13 deletions src/pages/chapter/[chapter_number].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { ChapterById } from '@/features/chapters/ChapterById';
import { graphql, useFragment, usePreloadedQuery } from 'react-relay/hooks';
import { getRelayClientEnvironment } from '@/config/relay/getRelayClientEnvironment';
import { RelayProps, withRelay } from 'relay-nextjs';
import { Chapter_Number_GitaChapterQuery } from '@/__generated__/Chapter_Number_GitaChapterQuery.graphql';
import { ChapterNumber_GitaChapterQuery } from '@/__generated__/ChapterNumber_GitaChapterQuery.graphql';
import { Layout } from '@/components/Layout';

export interface IChapterPageProps {}

const ChapterQuery = graphql`
query Chapter_Number_GitaChapterQuery($chapter_number: ID!) {
query ChapterNumber_GitaChapterQuery($chapter_number: Float!) {
allGitaChapter(where: { chapter_number: { eq: $chapter_number } }) {
_id
...ChapterById_ChapterDataFragment
Expand All @@ -21,21 +21,15 @@ const ChapterQuery = graphql`

function HandleData({
preloadedQuery,
}: RelayProps<{}, Chapter_Number_GitaChapterQuery>) {
const query = usePreloadedQuery<Chapter_Number_GitaChapterQuery>(
ChapterQuery,
preloadedQuery
);
const router = useRouter();
const { id, slug } = router.query;
const stringId = Array.isArray(id) ? id[0] : id;
if (stringId) {
return <ChapterById query={query} />;
}: RelayProps<{}, ChapterNumber_GitaChapterQuery>) {
const { allGitaChapter } = usePreloadedQuery(ChapterQuery, preloadedQuery);
if (allGitaChapter && allGitaChapter[0]) {
return <ChapterById chapterById={allGitaChapter[0]} />;
}
return null;
}

function ChapterPage(props: RelayProps<{}, Chapter_Number_GitaChapterQuery>) {
function ChapterPage(props: RelayProps<{}, ChapterNumber_GitaChapterQuery>) {
return (
<Layout>
<Suspenseful>
Expand All @@ -54,4 +48,11 @@ export default withRelay(ChapterPage, ChapterQuery, {

return getRelayServerEnvironment();
},
variablesFromContext: (context) => {
const { chapter_number } = context.query;

return {
chapter_number: typeof chapter_number === 'string' ? parseFloat(5) : 1,
};
},
});
Loading

0 comments on commit 9de24a3

Please sign in to comment.