Foxnouns.NET/Foxnouns.Frontend/app/components/nav/Navbar.tsx

85 lines
2.3 KiB
TypeScript
Raw Normal View History

import { Link, useFetcher } from "@remix-run/react";
import Meta from "~/lib/api/meta";
import { User, UserSettings } from "~/lib/api/user";
import Logo from "./Logo";
2024-09-14 18:07:49 +02:00
import { Nav, Navbar, NavDropdown } from "react-bootstrap";
import { BrightnessHigh, BrightnessHighFill, MoonFill } from "react-bootstrap-icons";
2024-09-10 20:33:22 +02:00
import { useTranslation } from "react-i18next";
export default function MainNavbar({
user,
settings,
}: {
meta: Meta;
user?: User;
settings: UserSettings;
}) {
const fetcher = useFetcher();
2024-09-10 20:33:22 +02:00
const { t } = useTranslation();
const userMenu = user ? (
<NavDropdown title={<>@{user.username}</>} align="end">
<NavDropdown.Item as={Link} to={`/@${user.username}`}>
2024-09-10 20:33:22 +02:00
{t("navbar.view-profile")}
</NavDropdown.Item>
<NavDropdown.Item as={Link} to="/settings">
2024-09-10 20:33:22 +02:00
{t("navbar.settings")}
</NavDropdown.Item>
<NavDropdown.Divider />
2024-09-10 20:33:22 +02:00
<fetcher.Form method="POST" action="/auth/log-out">
<NavDropdown.Item as="button" type="submit">
{t("navbar.log-out")}
</NavDropdown.Item>
</fetcher.Form>
</NavDropdown>
) : (
2024-09-10 21:24:40 +02:00
<Nav.Link to="/auth/log-in" as={Link}>
2024-09-10 20:33:22 +02:00
{t("navbar.log-in")}
</Nav.Link>
);
const ThemeIcon =
settings.dark_mode === null
? BrightnessHigh
: settings.dark_mode
? MoonFill
: BrightnessHighFill;
const theme = settings.dark_mode ? "dark" : "light";
return (
<Navbar expand="lg" className={`mb-4 mx-2 bg-${theme}`} color={theme} variant={theme}>
<Navbar.Brand to="/" as={Link}>
<Logo />
</Navbar.Brand>
<Navbar.Toggle aria-controls="main-navbar" />
<Navbar.Collapse id="main-navbar">
<Nav className="ms-auto">
{userMenu}
<fetcher.Form method="POST" action="/dark-mode">
<NavDropdown
title={
<>
2024-09-10 20:33:22 +02:00
<ThemeIcon /> {t("navbar.theme")}
</>
}
align="end"
>
<NavDropdown.Item as="button" name="theme" value="auto" type="submit">
2024-09-10 20:33:22 +02:00
{t("navbar.theme-auto")}
</NavDropdown.Item>
<NavDropdown.Item as="button" name="theme" value="dark" type="submit">
2024-09-10 20:33:22 +02:00
{t("navbar.theme-dark")}
</NavDropdown.Item>
<NavDropdown.Item as="button" name="theme" value="light" type="submit">
2024-09-10 20:33:22 +02:00
{t("navbar.theme-light")}
</NavDropdown.Item>
</NavDropdown>
</fetcher.Form>
</Nav>
</Navbar.Collapse>
</Navbar>
);
}