Skip to content

Commit 82be75c

Browse files
committed
refactor(frontend): add StatusBar component
1 parent 548ef12 commit 82be75c

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { useMemo } from "react";
2+
import { useAppContext } from "../contexts/AppContext";
3+
import { Alert, AlertProps } from "@mui/material";
4+
5+
6+
export default function StatusBar() {
7+
const { status, statusMessage } = useAppContext();
8+
const { severity, text } = useMemo<{severity: AlertProps['severity'], text: string}>( () => {
9+
switch (status) {
10+
case "pending":
11+
return { severity: "success", text: "Ready" };
12+
case "loading":
13+
return { severity: "info", text: "Loading..." };
14+
case "error":
15+
return { severity: "error", text: `Error: ${statusMessage}` };
16+
}
17+
}, [status, statusMessage])
18+
19+
return (
20+
<Alert severity={severity} className="text-grey-500">{text}</Alert>
21+
)
22+
}

frontend/src/app/contexts/AppContext.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { Dispatch, PropsWithChildren, createContext, useContext, useReducer } from 'react';
33
import { Sample, Page } from '@/app/types';
44

5-
type Status = "loading" | "error" | "pending";
5+
export type Status = "loading" | "error" | "pending";
66

77
/** The various action types to dispatch */
88
type Action =

frontend/src/app/page.tsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { useQueryState } from "nuqs";
1111
import SampleDialog from "./components/SampleDialog";
1212
import {ConfirmationDialog} from "@/app/components/ConfirmationDialog";
1313
import {Badge} from "@mui/base";
14+
import StatusBar from "./components/StatusBar";
1415

1516
export default function Home() {
1617

@@ -129,10 +130,7 @@ export default function Home() {
129130
</Box>
130131
</Box>
131132

132-
{/** Draft StatusBar (TODO: store the a date, hide message if old, except for errors) */}
133-
<Alert severity="success" hidden={status !== "pending"} className="text-grey-500">Ready</Alert>
134-
<Alert severity="info" hidden={status !== "loading"} className="text-grey-500">Loading...</Alert>
135-
<Alert severity="error" hidden={status !== "error"} title={statusMessage} >Error: {statusMessage}</Alert>
133+
<StatusBar/>
136134

137135
{/** Create Sample Dialog */}
138136
<SampleDialog

0 commit comments

Comments
 (0)