2024-09-05 22:29:12 +02:00
|
|
|
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";
|
2024-09-06 15:01:44 +02:00
|
|
|
import { BrightnessHigh, BrightnessHighFill, MoonFill } from "react-bootstrap-icons";
|
2024-09-10 20:33:22 +02:00
|
|
|
import { useTranslation } from "react-i18next";
|
2024-09-05 22:29:12 +02:00
|
|
|
|
|
|
|
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();
|
2024-09-05 22:29:12 +02:00
|
|
|
|
|
|
|
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")}
|
2024-09-05 22:29:12 +02:00
|
|
|
</NavDropdown.Item>
|
|
|
|
<NavDropdown.Item as={Link} to="/settings">
|
2024-09-10 20:33:22 +02:00
|
|
|
{t("navbar.settings")}
|
2024-09-05 22:29:12 +02:00
|
|
|
</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>
|
2024-09-05 22:29:12 +02:00
|
|
|
</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")}
|
2024-09-05 22:29:12 +02:00
|
|
|
</Nav.Link>
|
|
|
|
);
|
|
|
|
|
|
|
|
const ThemeIcon =
|
|
|
|
settings.dark_mode === null
|
|
|
|
? BrightnessHigh
|
|
|
|
: settings.dark_mode
|
|
|
|
? MoonFill
|
|
|
|
: BrightnessHighFill;
|
|
|
|
|
2024-09-06 15:01:44 +02:00
|
|
|
const theme = settings.dark_mode ? "dark" : "light";
|
|
|
|
|
2024-09-05 22:29:12 +02:00
|
|
|
return (
|
2024-09-06 15:01:44 +02:00
|
|
|
<Navbar expand="lg" className={`mb-4 mx-2 bg-${theme}`} color={theme} variant={theme}>
|
2024-09-05 22:29:12 +02:00
|
|
|
<Navbar.Brand to="/" as={Link}>
|
|
|
|
<Logo />
|
|
|
|
</Navbar.Brand>
|
|
|
|
<Navbar.Toggle aria-controls="main-navbar" />
|
|
|
|
<Navbar.Collapse id="main-navbar">
|
2024-09-06 15:01:44 +02:00
|
|
|
<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")}
|
2024-09-06 15:01:44 +02:00
|
|
|
</>
|
|
|
|
}
|
|
|
|
align="end"
|
|
|
|
>
|
|
|
|
<NavDropdown.Item as="button" name="theme" value="auto" type="submit">
|
2024-09-10 20:33:22 +02:00
|
|
|
{t("navbar.theme-auto")}
|
2024-09-06 15:01:44 +02:00
|
|
|
</NavDropdown.Item>
|
|
|
|
<NavDropdown.Item as="button" name="theme" value="dark" type="submit">
|
2024-09-10 20:33:22 +02:00
|
|
|
{t("navbar.theme-dark")}
|
2024-09-06 15:01:44 +02:00
|
|
|
</NavDropdown.Item>
|
|
|
|
<NavDropdown.Item as="button" name="theme" value="light" type="submit">
|
2024-09-10 20:33:22 +02:00
|
|
|
{t("navbar.theme-light")}
|
2024-09-06 15:01:44 +02:00
|
|
|
</NavDropdown.Item>
|
|
|
|
</NavDropdown>
|
|
|
|
</fetcher.Form>
|
|
|
|
</Nav>
|
2024-09-05 22:29:12 +02:00
|
|
|
</Navbar.Collapse>
|
|
|
|
</Navbar>
|
|
|
|
);
|
|
|
|
}
|