Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added custom 404 page [fixes #210] #226

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/app/chapter/[chapterNumber]/(chapter)/[[...locale]]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,19 @@ export default async function Chapter({ params }: Props) {
languageSettings.translationAuthor.id,
);

const translations = await getTranslations(locale);

if (!chapterData) {
return <NotFound hint={`Chapter ${chapterNumber} not found`} />;
return (
<NotFound
translations={translations}
locale={locale}
hint={chapterNumber}
isChapter={true}
/>
);
}

const translations = await getTranslations(locale);

return (
<>
<script
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,19 @@ const Verse = async ({ params }: Props) => {
languageSettings.translationAuthor.id,
);

const translations = await getTranslations(locale);

if (!verseData) {
return <NotFound hint={`Verse ${verseNumber} not found`} />;
return (
<NotFound
translations={translations}
locale={locale}
hint={verseNumber}
isVerse={true}
/>
);
}

const translations = await getTranslations(locale);

return (
<article>
<script
Expand Down
8 changes: 7 additions & 1 deletion src/app/verse-of-the-day/[[...locale]]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ const Page = async ({ params }: ParamsWithLocale) => {
const dailyVerse = await getDailyVerse(locale);

if (!dailyVerse) {
return <NotFound hint="Daily verse not found" />;
return (
<NotFound
translations={await getTranslations(locale)}
locale={locale}
hint="Daily verse not found"
/>
);
}

return (
Expand Down
43 changes: 41 additions & 2 deletions src/components/NotFound/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,50 @@
import Image from "next/image";

import LinkWithLocale from "components/LinkWithLocale";
import { getTranslate } from "shared/translate";

type Props = {
hint?: string;
};
isChapter?: boolean;
isVerse?: boolean;
} & LocaleAndTranslations;

function NotFound(props: Props) {
const { hint } = props;
const { translations, locale, isChapter, isVerse } = props;

const translate = getTranslate(translations, locale);

return <h1 className="p-10 text-center">{hint || "Not found"}</h1>;
return (
<div className="flex min-h-screen items-center justify-center">
<Image
src={"/quotes-bg.png"}
alt="BG Not Found Banner Image"
layout="fill"
objectFit="cover"
objectPosition="center"
/>
<div className="p-2 text-center drop-shadow-card">
<h1 className="mb-4 text-4xl font-bold text-my-orange ">
{isChapter
? `${translate("Chapter")} ${hint} ${translate("Not found")}`
: isVerse
? `${translate("Verse")} ${hint} ${translate("Not found")}`
: `${translate(hint || "Not found")}`}
</h1>
<p className="mb-8 text-xl text-white">
{" "}
{translate("Sorry, the page you're looking for doesn't exist")}
</p>
<LinkWithLocale
href={"/"}
className="items-center rounded-md border border-gray-300 bg-white px-6 py-3 text-base font-medium text-gray-700 shadow-sm hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-my-orange focus:ring-offset-2"
>
{translate("Go Back to Home")}
</LinkWithLocale>
</div>
</div>
);
}

export default NotFound;
4 changes: 4 additions & 0 deletions src/shared/translate/locales/hi.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,9 @@
"App": "मोबाइल ऐप",
"Privacy": "प्राइवेसी",
"Acknowledgements": "स्वीकृतियाँ",
"Go Back to Home": "होम पेज पर वापस जाएँ",
"Sorry, the page you're looking for doesn't exist": "क्षमा करें, आप जिस पेज की तलाश कर रहे हैं वह मौजूद नहीं है",
"Daily verse not found": "दैनिक श्लोक नहीं मिला",
"Not found": "नहीं मिला",
"Gita AI": "गीता एआई"
}
Loading