Skip to content

Commit

Permalink
feat: not found page with link to home
Browse files Browse the repository at this point in the history
  • Loading branch information
Pettor committed Feb 25, 2024
1 parent a2b9641 commit dfdad7d
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/components/views/error/ErrorView.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default meta;
type Story = StoryObj<typeof meta>;

const commonProps = {
onHome: () => console.log("onHome"),
onBack: () => console.log("onHome"),
} satisfies ComponentProps;

export const Fullscreen = {
Expand Down
7 changes: 3 additions & 4 deletions src/components/views/error/ErrorView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@ import { BasicLayout } from "../../layout/BasicLayout";

export interface ErrorViewProps {
message?: string;
onHome(): void;
onBack(): void;
}

export function ErrorView({ message, onHome }: ErrorViewProps): ReactElement {
export function ErrorView({ message, onBack }: ErrorViewProps): ReactElement {
return (
<BasicLayout>
<div className="flex flex-col gap-4">
<article className="prose lg:prose-xl">
<h3 className="text-center">Ops! 😅 </h3>
<strong>{message ?? "Something went wrong! 😱"}</strong>
</article>
{/* <div className="divider divider-vertical w-full h-2" /> */}
<button className="btn btn-primary mt-4" onClick={onHome}>
<button className="btn btn-primary mt-4" onClick={onBack}>
Start over 🦖
</button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/error/UseErrorView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ export function useErrorView(): ErrorViewProps {
const navigate = useNavigate();

return {
onHome: () => navigate("/"),
onBack: () => navigate("/"),
};
}
2 changes: 1 addition & 1 deletion src/components/views/not-found/NotFoundView.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Meta, StoryObj } from "@storybook/react";
import { NotFoundView as Component } from "../not-found/NotFoundView";
import { NotFoundView as Component } from "./NotFoundView";
import { FullSizeDecorator } from "~/stories/decorators/FullSizeDecorator";
import { MockBrowserDecorator } from "~/stories/decorators/MockBrowserDecorator";
import { MockPhoneDecorator } from "~/stories/decorators/MockPhoneDecorator";
Expand Down
15 changes: 13 additions & 2 deletions src/components/views/not-found/NotFoundView.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import type { ReactElement } from "react";
import { BasicLayout } from "../../layout/BasicLayout";

export function NotFoundView(): ReactElement {
export interface NotFoundViewProps {
onBack(): void;
}

export function NotFoundView({ onBack }: NotFoundViewProps): ReactElement {
return (
<BasicLayout container>
<h1>Not Found</h1>
<div className="flex flex-col gap-4 items-center">
<article className="prose lg:prose-xl p-4 text-pretty max-w-64 lg:max-w-full">
<strong>{"Could not find the page you were looking for! 🕵️"}</strong>
</article>
<button className="btn btn-primary mt-4 w-48" onClick={onBack}>
Start over 🦖
</button>
</div>
</BasicLayout>
);
}
10 changes: 10 additions & 0 deletions src/components/views/not-found/UseNotFoundView.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { useNavigate } from "react-router-dom";
import type { NotFoundViewProps } from "./NotFoundView";

export function useNotFoundView(): NotFoundViewProps {
const navigate = useNavigate();

return {
onBack: () => navigate("/"),
};
}
2 changes: 1 addition & 1 deletion src/core/routes/GlobalRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function GlobalRoutes(): RouteProps[] {
},
{
path: "/editor",
lazy: () => import("~/pages/editor/ImageEditorRoute"),
lazy: () => import("~/pages/editor/EditorRoute"),
},
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { useThemeSwitcher } from "~/components/library/theme/UseThemeSwitcher";
import { ErrorView } from "~/components/views/error/ErrorView";
import { LoadingView } from "~/components/views/loading/LoadingView";

export interface ImageEditorPageProps {
export interface EditorPageProps {
url: string;
}

export function ImageEditorPage({ url }: ImageEditorPageProps): ReactElement {
export function EditorPage({ url }: EditorPageProps): ReactElement {
const navigate = useNavigate();
const themeSwitchProps = useThemeSwitcher();

Expand All @@ -25,7 +25,7 @@ export function ImageEditorPage({ url }: ImageEditorPageProps): ReactElement {
themeSwitchProps,
}}
LoaderComponent={() => <LoadingView />}
ErrorComponent={() => <ErrorView />}
ErrorComponent={() => <ErrorView onBack={() => console.log("onBack")} />}
/>
);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ReactElement } from "react";
import { useAtomValue } from "jotai";
import { ImageEditorPage } from "./ImageEditorPage";
import { EditorPage } from "./EditorPage";
import { ErrorView } from "~/components/views/error/ErrorView";
import { useErrorView } from "~/components/views/error/UseErrorView";
import { getDownloadUrlAtom } from "~/core/routes/atoms/DroppedFileAtoms";
Expand All @@ -13,9 +13,9 @@ export function Component(): ReactElement {
return <ErrorView {...errorViewProps} message="File somehow went missing 🤔" />;
}

return <ImageEditorPage url={fileUrl} />;
return <EditorPage url={fileUrl} />;
}
Component.displayName = "ImageEditorPage";
Component.displayName = "EditorPage";

export function ErrorBoundary(): ReactElement {
const errorViewProps = useErrorView();
Expand Down
4 changes: 3 additions & 1 deletion src/pages/not-found/NotFoundPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { ReactElement } from "react";
import { NotFoundView } from "~/components/views/not-found/NotFoundView";
import { useNotFoundView } from "~/components/views/not-found/UseNotFoundView";

export function NotFoundPage(): ReactElement {
return <NotFoundView />;
const notFoundViewProps = useNotFoundView();
return <NotFoundView {...notFoundViewProps} />;
}

0 comments on commit dfdad7d

Please sign in to comment.