Skip to content

Commit

Permalink
Merge pull request #185 from gita/skeleton-loader
Browse files Browse the repository at this point in the history
added skeleton where needed
  • Loading branch information
samanyougarg authored Aug 11, 2023
2 parents f1b340c + a5c2b38 commit 9c0a141
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 38 deletions.
27 changes: 23 additions & 4 deletions app/chapter/[chapterNumber]/verse/[verseNumber]/verse-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { SvgFloralDivider } from "../../../../../components/svgs";
import Translation from "../../../../../components/Verse/Translation";
import Commentary from "../../../../../components/Verse/Commentary";
import PageHeader from "../../../../../components/Headers/PageHeader";
import { Skeleton } from "../../../../../components/Shared/Skeleton";

type Props = {
chapterNumber: string;
Expand Down Expand Up @@ -107,15 +108,21 @@ export default function VersePage({ chapterNumber, verseNumber }: Props) {
>
BG {currentVerse?.chapter_number}.{currentVerse?.verse_number}
</h1>
{devnagari && (
{devnagari && currentVerse.text ? (
<p
className={classNames(
"font-dev text-my-orange mt-8 max-w-md mx-auto",
styles.fontSize.subHeading1
)}
>
{currentVerse?.text}
{currentVerse.text}
</p>
) : (
<div className="flex flex-col items-center w-full max-w-md mx-auto pt-10">
<Skeleton height="h-8" width="w-full" margin="mb-2" />
<Skeleton height="h-8" width="w-5/6" margin="mb-2" />
<Skeleton height="h-8" width="w-4/5" margin="mb-2" />
</div>
)}
{verseText && (
<p
Expand All @@ -127,15 +134,27 @@ export default function VersePage({ chapterNumber, verseNumber }: Props) {
{currentVerse?.transliteration}
</p>
)}
{synonyms && (
{synonyms && currentVerse?.word_meanings ? (
<p
className={classNames(
"mt-6 mx-auto dark:text-gray-50",
styles.fontSize.subHeading2
)}
>
{currentVerse?.word_meanings}
{currentVerse.word_meanings}
</p>
) : (
<>
<div className="flex flex-col items-center w-full max-w-md mx-auto pt-3">
<Skeleton height="h-5" width="w-full" margin="mb-3" />
<Skeleton height="h-5" width="w-5/6" margin="mb-3" />
</div>
<div className="flex flex-col items-center w-full pt-3">
<Skeleton height="h-5" width="w-full" margin="mb-3" />
<Skeleton height="h-5" width="w-5/6" margin="mb-3" />
<Skeleton height="h-5" width="w-4/5" margin="mb-3" />
</div>
</>
)}
{(translation || purport) && (
<SvgFloralDivider
Expand Down
42 changes: 27 additions & 15 deletions components/Home/VerseOfDay.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useEffect, useState } from "react";
import { gql, ApolloQueryResult, useApolloClient } from "@apollo/client";
import Link from "next/link";
import { Skeleton } from "../Shared/Skeleton";

interface DailyVerse {
verseNumber: number;
Expand Down Expand Up @@ -68,21 +69,32 @@ const VerseOfDay = () => {
return (
<div className="relative max-w-7xl mx-auto z-10 px-4 sm:px-6 mt-24">
<div className="bg-white dark:bg-dark-100 shadow-lg rounded-xl px-12 pb-8 pt-5 text-gray-400">
<h2 className="text-my-orange font-bold mb-4 divider line one-line px-4">
Verse of the day - BG {dailyVerse?.chapterNumber}.
{dailyVerse?.verseNumber}
</h2>
<p className="text-lg">
{dailyVerse?.gitaTranslationsByVerseId?.nodes[0]?.description}{" "}
</p>
<button className="uppercase text-black dark:text-white mt-4 font-bold text-sm hover:text-gray-700 dark:hover:text-gray-400 focus:outline-none">
<Link
href={`chapter/${dailyVerse?.chapterNumber}/verse/${dailyVerse?.verseNumber}`}
shallow
>
See more
</Link>
</button>
{dailyVerse ? (
<>
<h2 className="text-my-orange font-bold mb-4 divider line one-line px-4">
Verse of the day - BG {dailyVerse?.chapterNumber}.
{dailyVerse?.verseNumber}
</h2>
<p className="text-lg">
{dailyVerse?.gitaTranslationsByVerseId?.nodes[0]?.description}{" "}
</p>
<button className="uppercase text-black dark:text-white mt-4 font-bold text-sm hover:text-gray-700 dark:hover:text-gray-400 focus:outline-none">
<Link
href={`chapter/${dailyVerse?.chapterNumber}/verse/${dailyVerse?.verseNumber}`}
shallow
>
See more
</Link>
</button>
</>
) : (
<>
<Skeleton height="h-4" width="w-2/12" margin="my-4" />
<Skeleton height="h-5" width="w-10/12" margin="mb-3" />
<Skeleton height="h-5" width="w-9/12" margin="mb-4" />
<Skeleton height="h-5" width="w-1/12" margin="mb-3" />
</>
)}
</div>
</div>
);
Expand Down
15 changes: 15 additions & 0 deletions components/Shared/Skeleton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { FC } from "react";

type SkeletonProps = {
height: string;
width: string;
margin: string;
};

export const Skeleton: FC<SkeletonProps> = ({ height, width, margin }) => {
return (
<div
className={`${height} ${width} ${margin} rounded-md bg-gray-300 animate-pulse`}
/>
);
};
33 changes: 22 additions & 11 deletions components/Verse/Commentary.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import useMyStyles from "../../hooks/useMyStyles";
import classNames from "../../utils/classNames";
import splitIntoParagraphs from "../../utils/splitIntoParagraphs";
import { Skeleton } from "../Shared/Skeleton";

interface Props {
commentaryData: GitaLanguage[] | undefined;
Expand All @@ -21,17 +22,27 @@ export default function Commentary({ commentaryData }: Props) {
>
Commentary
</h1>
{paragraphs?.map((paragraph) => (
<p
key={paragraph}
className={classNames(
"mt-6 mx-auto text-justify dark:text-gray-50 whitespace-pre-wrap",
styles.fontSize.para
)}
>
{paragraph}
</p>
))}
{paragraphs?.[0] ? (
paragraphs.map((paragraph) => (
<p
key={paragraph}
className={classNames(
"mt-6 mx-auto text-justify dark:text-gray-50 whitespace-pre-wrap",
styles.fontSize.para
)}
>
{paragraph}
</p>
))
) : (
<>
<Skeleton width="w-full" height="h-5" margin="my-3" />
<Skeleton width="w-full" height="h-5" margin="my-3" />
<Skeleton width="w-full" height="h-5" margin="my-3" />
<Skeleton width="w-full" height="h-5" margin="my-3" />
<Skeleton width="w-4/5" height="h-5" margin="my-3" />
</>
)}
</div>
);
}
24 changes: 16 additions & 8 deletions components/Verse/Translation.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import useMyStyles from "../../hooks/useMyStyles";
import classNames from "../../utils/classNames";
import { Skeleton } from "../Shared/Skeleton";

interface Props {
translationData: GitaLanguage[] | undefined;
Expand All @@ -18,14 +19,21 @@ export default function Translation({ translationData }: Props) {
>
Translation
</h1>
<p
className={classNames(
"mt-6 mx-auto text-justify dark:text-gray-50 ",
styles.fontSize.para
)}
>
{translationData ? translationData[0]?.description : ""}
</p>
{translationData && translationData[0]?.description ? (
<p
className={classNames(
"mt-6 mx-auto text-justify dark:text-gray-50 ",
styles.fontSize.para
)}
>
{translationData[0].description}
</p>
) : (
<>
<Skeleton height="h-5" width="w-full" margin="my-3" />
<Skeleton height="h-5" width="w-4/5" margin="my-3" />
</>
)}
</div>
);
}

0 comments on commit 9c0a141

Please sign in to comment.