2022-09-06 14:21:33 +00:00
|
|
|
import {
|
|
|
|
faRunning,
|
|
|
|
faHome,
|
|
|
|
faSun,
|
|
|
|
faMoon,
|
|
|
|
} from "@fortawesome/free-solid-svg-icons";
|
2022-06-20 16:30:45 +00:00
|
|
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
2022-08-26 22:32:40 +00:00
|
|
|
import { useEffect, useState } from "react";
|
2022-06-20 16:30:45 +00:00
|
|
|
import { Notification } from "../types";
|
2022-03-20 08:56:28 +00:00
|
|
|
|
|
|
|
function prettyName(s: string | undefined): string {
|
|
|
|
if (!s) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
return s.replaceAll("/", " / ");
|
|
|
|
}
|
|
|
|
|
|
|
|
export function TopBar({
|
|
|
|
pageName,
|
2022-03-31 12:28:07 +00:00
|
|
|
unsavedChanges,
|
2022-09-06 14:21:33 +00:00
|
|
|
isLoading,
|
2022-03-20 08:56:28 +00:00
|
|
|
notifications,
|
|
|
|
onClick,
|
2022-08-26 22:32:40 +00:00
|
|
|
onThemeClick,
|
2022-07-04 09:38:16 +00:00
|
|
|
onHomeClick,
|
2022-06-20 16:30:45 +00:00
|
|
|
onActionClick,
|
2022-04-04 16:33:13 +00:00
|
|
|
lhs,
|
|
|
|
rhs,
|
2022-03-20 08:56:28 +00:00
|
|
|
}: {
|
|
|
|
pageName?: string;
|
2022-03-31 12:28:07 +00:00
|
|
|
unsavedChanges: boolean;
|
2022-09-06 14:21:33 +00:00
|
|
|
isLoading: boolean;
|
2022-03-20 08:56:28 +00:00
|
|
|
notifications: Notification[];
|
|
|
|
onClick: () => void;
|
2022-08-26 22:32:40 +00:00
|
|
|
onThemeClick: () => void;
|
2022-07-04 09:38:16 +00:00
|
|
|
onHomeClick: () => void;
|
2022-06-20 16:30:45 +00:00
|
|
|
onActionClick: () => void;
|
2022-04-04 16:33:13 +00:00
|
|
|
lhs?: React.ReactNode;
|
|
|
|
rhs?: React.ReactNode;
|
2022-03-20 08:56:28 +00:00
|
|
|
}) {
|
2022-09-06 14:21:33 +00:00
|
|
|
const [theme, setTheme] = useState<string>(localStorage.theme ?? "light");
|
2022-08-26 22:32:40 +00:00
|
|
|
|
2022-03-20 08:56:28 +00:00
|
|
|
return (
|
2022-07-22 11:44:28 +00:00
|
|
|
<div id="sb-top" onClick={onClick}>
|
2022-04-04 16:33:13 +00:00
|
|
|
{lhs}
|
|
|
|
<div className="main">
|
|
|
|
<div className="inner">
|
2022-04-10 09:04:07 +00:00
|
|
|
<span
|
2022-08-02 12:40:04 +00:00
|
|
|
className={`sb-current-page ${
|
2022-09-06 14:21:33 +00:00
|
|
|
isLoading
|
|
|
|
? "sb-loading"
|
|
|
|
: unsavedChanges
|
|
|
|
? "sb-unsaved"
|
|
|
|
: "sb-saved"
|
2022-08-02 12:40:04 +00:00
|
|
|
}`}
|
2022-04-10 09:04:07 +00:00
|
|
|
>
|
|
|
|
{prettyName(pageName)}
|
2022-04-04 16:33:13 +00:00
|
|
|
</span>
|
|
|
|
{notifications.length > 0 && (
|
2022-08-02 12:40:04 +00:00
|
|
|
<div className="sb-notifications">
|
2022-04-04 16:33:13 +00:00
|
|
|
{notifications.map((notification) => (
|
2022-07-14 11:32:28 +00:00
|
|
|
<div
|
|
|
|
key={notification.id}
|
2022-08-02 12:40:04 +00:00
|
|
|
className={`sb-notification-${notification.type}`}
|
2022-07-14 11:32:28 +00:00
|
|
|
>
|
|
|
|
{notification.message}
|
|
|
|
</div>
|
2022-04-04 16:33:13 +00:00
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
)}
|
2022-08-02 12:40:04 +00:00
|
|
|
<div className="sb-actions">
|
2022-06-17 18:17:22 +00:00
|
|
|
<button
|
|
|
|
onClick={(e) => {
|
2022-07-04 09:38:16 +00:00
|
|
|
onHomeClick();
|
|
|
|
e.stopPropagation();
|
|
|
|
}}
|
|
|
|
title="Navigate to the 'index' page"
|
|
|
|
>
|
|
|
|
<FontAwesomeIcon icon={faHome} />
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
onClick={(e) => {
|
2022-06-20 16:30:45 +00:00
|
|
|
onActionClick();
|
2022-06-17 18:17:22 +00:00
|
|
|
e.stopPropagation();
|
|
|
|
}}
|
2022-07-04 09:38:16 +00:00
|
|
|
title="Open the command palette"
|
2022-06-17 18:17:22 +00:00
|
|
|
>
|
2022-06-20 16:30:45 +00:00
|
|
|
<FontAwesomeIcon icon={faRunning} />
|
2022-06-17 18:17:22 +00:00
|
|
|
</button>
|
2022-08-26 22:32:40 +00:00
|
|
|
<button
|
|
|
|
onClick={(e) => {
|
|
|
|
onThemeClick();
|
2022-09-06 14:21:33 +00:00
|
|
|
setTheme(localStorage.theme ?? "light");
|
2022-08-26 22:32:40 +00:00
|
|
|
e.stopPropagation();
|
|
|
|
}}
|
|
|
|
title="Toggle theme"
|
|
|
|
>
|
2022-09-06 14:21:33 +00:00
|
|
|
<FontAwesomeIcon icon={theme === "dark" ? faSun : faMoon} />
|
2022-08-26 22:32:40 +00:00
|
|
|
</button>
|
2022-05-06 16:55:04 +00:00
|
|
|
</div>
|
2022-04-04 16:33:13 +00:00
|
|
|
</div>
|
2022-03-20 08:56:28 +00:00
|
|
|
</div>
|
2022-04-04 16:33:13 +00:00
|
|
|
{rhs}
|
2022-03-20 08:56:28 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|