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";
|
|
|
|
|
|
|
|
import Nav from "react-bootstrap/Nav";
|
|
|
|
import Navbar from "react-bootstrap/Navbar";
|
|
|
|
import NavDropdown from "react-bootstrap/NavDropdown";
|
2024-09-06 15:01:44 +02:00
|
|
|
import { BrightnessHigh, BrightnessHighFill, MoonFill } from "react-bootstrap-icons";
|
2024-09-05 22:29:12 +02:00
|
|
|
|
|
|
|
export default function MainNavbar({
|
|
|
|
user,
|
|
|
|
settings,
|
|
|
|
}: {
|
|
|
|
meta: Meta;
|
|
|
|
user?: User;
|
|
|
|
settings: UserSettings;
|
|
|
|
}) {
|
|
|
|
const fetcher = useFetcher();
|
|
|
|
|
|
|
|
const userMenu = user ? (
|
|
|
|
<NavDropdown title={<>@{user.username}</>} align="end">
|
|
|
|
<NavDropdown.Item as={Link} to={`/@${user.username}`}>
|
|
|
|
View profile
|
|
|
|
</NavDropdown.Item>
|
|
|
|
<NavDropdown.Item as={Link} to="/settings">
|
|
|
|
Settings
|
|
|
|
</NavDropdown.Item>
|
|
|
|
<NavDropdown.Divider />
|
|
|
|
<NavDropdown.Item as={Link} to="/auth/logout">
|
|
|
|
Log out
|
|
|
|
</NavDropdown.Item>
|
|
|
|
</NavDropdown>
|
|
|
|
) : (
|
|
|
|
<Nav.Link to="/auth/login" as={Link}>
|
|
|
|
Log in or sign up
|
|
|
|
</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={
|
|
|
|
<>
|
|
|
|
<ThemeIcon /> Theme
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
align="end"
|
|
|
|
>
|
|
|
|
<NavDropdown.Item as="button" name="theme" value="auto" type="submit">
|
|
|
|
Automatic
|
|
|
|
</NavDropdown.Item>
|
|
|
|
<NavDropdown.Item as="button" name="theme" value="dark" type="submit">
|
|
|
|
Dark mode
|
|
|
|
</NavDropdown.Item>
|
|
|
|
<NavDropdown.Item as="button" name="theme" value="light" type="submit">
|
|
|
|
Light mode
|
|
|
|
</NavDropdown.Item>
|
|
|
|
</NavDropdown>
|
|
|
|
</fetcher.Form>
|
|
|
|
</Nav>
|
2024-09-05 22:29:12 +02:00
|
|
|
</Navbar.Collapse>
|
|
|
|
</Navbar>
|
|
|
|
);
|
|
|
|
}
|