2022-02-25 18:46:22 +01:00
|
|
|
import AppBar from "@mui/material/AppBar";
|
|
|
|
import Navigation from "./Navigation";
|
|
|
|
import Toolbar from "@mui/material/Toolbar";
|
|
|
|
import IconButton from "@mui/material/IconButton";
|
|
|
|
import MenuIcon from "@mui/icons-material/Menu";
|
|
|
|
import Typography from "@mui/material/Typography";
|
|
|
|
import * as React from "react";
|
2023-05-23 21:13:01 +02:00
|
|
|
import { useState } from "react";
|
2022-02-28 22:56:38 +01:00
|
|
|
import Box from "@mui/material/Box";
|
2023-05-23 21:13:01 +02:00
|
|
|
import { topicDisplayName } from "../app/utils";
|
2022-12-28 21:51:09 +01:00
|
|
|
import db from "../app/db";
|
2023-05-23 21:13:01 +02:00
|
|
|
import { useLocation, useNavigate } from "react-router-dom";
|
|
|
|
import MenuItem from "@mui/material/MenuItem";
|
2022-03-06 04:33:34 +01:00
|
|
|
import MoreVertIcon from "@mui/icons-material/MoreVert";
|
2023-05-23 21:13:01 +02:00
|
|
|
import NotificationsIcon from "@mui/icons-material/Notifications";
|
|
|
|
import NotificationsOffIcon from "@mui/icons-material/NotificationsOff";
|
2022-03-10 05:28:55 +01:00
|
|
|
import routes from "./routes";
|
2022-03-06 04:33:34 +01:00
|
|
|
import subscriptionManager from "../app/SubscriptionManager";
|
2022-03-10 21:37:50 +01:00
|
|
|
import logo from "../img/ntfy.svg";
|
2023-05-23 21:13:01 +02:00
|
|
|
import { useTranslation } from "react-i18next";
|
2022-12-02 21:37:48 +01:00
|
|
|
import session from "../app/Session";
|
2023-05-23 21:13:01 +02:00
|
|
|
import AccountCircleIcon from "@mui/icons-material/AccountCircle";
|
2022-12-02 21:37:48 +01:00
|
|
|
import Button from "@mui/material/Button";
|
2022-12-15 05:43:43 +01:00
|
|
|
import Divider from "@mui/material/Divider";
|
2023-05-23 21:13:01 +02:00
|
|
|
import { Logout, Person, Settings } from "@mui/icons-material";
|
2022-12-15 05:43:43 +01:00
|
|
|
import ListItemIcon from "@mui/material/ListItemIcon";
|
2023-02-01 03:39:30 +01:00
|
|
|
import accountApi from "../app/AccountApi";
|
2022-12-31 15:31:46 +01:00
|
|
|
import PopupMenu from "./PopupMenu";
|
2023-02-11 03:19:44 +01:00
|
|
|
import { SubscriptionPopup } from "./SubscriptionPopup";
|
2022-02-25 18:46:22 +01:00
|
|
|
|
|
|
|
const ActionBar = (props) => {
|
2023-05-23 21:13:01 +02:00
|
|
|
const { t } = useTranslation();
|
|
|
|
const location = useLocation();
|
|
|
|
let title = "ntfy";
|
|
|
|
if (props.selected) {
|
|
|
|
title = topicDisplayName(props.selected);
|
|
|
|
} else if (location.pathname === routes.settings) {
|
|
|
|
title = t("action_bar_settings");
|
|
|
|
} else if (location.pathname === routes.account) {
|
|
|
|
title = t("action_bar_account");
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<AppBar
|
|
|
|
position="fixed"
|
|
|
|
sx={{
|
|
|
|
width: "100%",
|
|
|
|
zIndex: { sm: 1250 }, // > Navigation (1200), but < Dialog (1300)
|
|
|
|
ml: { sm: `${Navigation.width}px` },
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Toolbar
|
|
|
|
sx={{
|
|
|
|
pr: "24px",
|
2023-05-24 01:29:47 +02:00
|
|
|
background: "linear-gradient(150deg, rgba(51,133,116,1) 0%, rgba(86,189,168,1) 100%)",
|
2023-05-23 21:13:01 +02:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
<IconButton
|
|
|
|
color="inherit"
|
|
|
|
edge="start"
|
|
|
|
aria-label={t("action_bar_show_menu")}
|
|
|
|
onClick={props.onMobileDrawerToggle}
|
|
|
|
sx={{ mr: 2, display: { sm: "none" } }}
|
|
|
|
>
|
|
|
|
<MenuIcon />
|
|
|
|
</IconButton>
|
|
|
|
<Box
|
|
|
|
component="img"
|
|
|
|
src={logo}
|
|
|
|
alt={t("action_bar_logo_alt")}
|
|
|
|
sx={{
|
|
|
|
display: { xs: "none", sm: "block" },
|
|
|
|
marginRight: "10px",
|
|
|
|
height: "28px",
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<Typography variant="h6" noWrap component="div" sx={{ flexGrow: 1 }}>
|
|
|
|
{title}
|
|
|
|
</Typography>
|
2023-05-24 01:29:47 +02:00
|
|
|
{props.selected && <SettingsIcons subscription={props.selected} onUnsubscribe={props.onUnsubscribe} />}
|
2023-05-23 21:13:01 +02:00
|
|
|
<ProfileIcon />
|
|
|
|
</Toolbar>
|
|
|
|
</AppBar>
|
|
|
|
);
|
2022-02-25 18:46:22 +01:00
|
|
|
};
|
|
|
|
|
2022-03-08 22:56:41 +01:00
|
|
|
const SettingsIcons = (props) => {
|
2023-05-23 21:13:01 +02:00
|
|
|
const { t } = useTranslation();
|
|
|
|
const [anchorEl, setAnchorEl] = useState(null);
|
|
|
|
const subscription = props.subscription;
|
2022-03-06 04:33:34 +01:00
|
|
|
|
2023-05-23 21:13:01 +02:00
|
|
|
const handleToggleMute = async () => {
|
|
|
|
const mutedUntil = subscription.mutedUntil ? 0 : 1; // Make this a timestamp in the future
|
|
|
|
await subscriptionManager.setMutedUntil(subscription.id, mutedUntil);
|
|
|
|
};
|
2022-03-08 22:56:41 +01:00
|
|
|
|
2023-05-23 21:13:01 +02:00
|
|
|
return (
|
|
|
|
<>
|
2023-05-24 01:29:47 +02:00
|
|
|
<IconButton color="inherit" size="large" edge="end" onClick={handleToggleMute} aria-label={t("action_bar_toggle_mute")}>
|
|
|
|
{subscription.mutedUntil ? <NotificationsOffIcon /> : <NotificationsIcon />}
|
2023-05-23 21:13:01 +02:00
|
|
|
</IconButton>
|
2023-05-24 02:16:29 +02:00
|
|
|
<IconButton
|
|
|
|
color="inherit"
|
|
|
|
size="large"
|
|
|
|
edge="end"
|
|
|
|
onClick={(ev) => setAnchorEl(ev.currentTarget)}
|
|
|
|
aria-label={t("action_bar_toggle_action_menu")}
|
|
|
|
>
|
2023-05-23 21:13:01 +02:00
|
|
|
<MoreVertIcon />
|
|
|
|
</IconButton>
|
2023-05-24 01:29:47 +02:00
|
|
|
<SubscriptionPopup subscription={subscription} anchor={anchorEl} placement="right" onClose={() => setAnchorEl(null)} />
|
2023-05-23 21:13:01 +02:00
|
|
|
</>
|
|
|
|
);
|
2022-03-06 04:33:34 +01:00
|
|
|
};
|
|
|
|
|
2022-12-29 08:32:05 +01:00
|
|
|
const ProfileIcon = () => {
|
2023-05-23 21:13:01 +02:00
|
|
|
const { t } = useTranslation();
|
|
|
|
const [anchorEl, setAnchorEl] = useState(null);
|
|
|
|
const open = Boolean(anchorEl);
|
|
|
|
const navigate = useNavigate();
|
2022-12-02 21:37:48 +01:00
|
|
|
|
2023-05-23 21:13:01 +02:00
|
|
|
const handleClick = (event) => {
|
|
|
|
setAnchorEl(event.currentTarget);
|
|
|
|
};
|
2022-12-29 08:32:05 +01:00
|
|
|
|
2023-05-23 21:13:01 +02:00
|
|
|
const handleClose = () => {
|
|
|
|
setAnchorEl(null);
|
|
|
|
};
|
2022-12-29 08:32:05 +01:00
|
|
|
|
2023-05-23 21:13:01 +02:00
|
|
|
const handleLogout = async () => {
|
|
|
|
try {
|
|
|
|
await accountApi.logout();
|
|
|
|
await db.delete();
|
|
|
|
} finally {
|
|
|
|
session.resetAndRedirect(routes.app);
|
|
|
|
}
|
|
|
|
};
|
2022-12-29 08:32:05 +01:00
|
|
|
|
2023-05-23 21:13:01 +02:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{session.exists() && (
|
2023-05-24 01:29:47 +02:00
|
|
|
<IconButton color="inherit" size="large" edge="end" onClick={handleClick} aria-label={t("action_bar_profile_title")}>
|
2023-05-23 21:13:01 +02:00
|
|
|
<AccountCircleIcon />
|
|
|
|
</IconButton>
|
|
|
|
)}
|
|
|
|
{!session.exists() && config.enable_login && (
|
2023-05-24 01:29:47 +02:00
|
|
|
<Button color="inherit" variant="text" onClick={() => navigate(routes.login)} sx={{ m: 1 }} aria-label={t("action_bar_sign_in")}>
|
2023-05-23 21:13:01 +02:00
|
|
|
{t("action_bar_sign_in")}
|
|
|
|
</Button>
|
|
|
|
)}
|
|
|
|
{!session.exists() && config.enable_signup && (
|
2023-05-24 01:29:47 +02:00
|
|
|
<Button color="inherit" variant="outlined" onClick={() => navigate(routes.signup)} aria-label={t("action_bar_sign_up")}>
|
2023-05-23 21:13:01 +02:00
|
|
|
{t("action_bar_sign_up")}
|
|
|
|
</Button>
|
|
|
|
)}
|
2023-05-24 01:29:47 +02:00
|
|
|
<PopupMenu horizontal="right" anchorEl={anchorEl} open={open} onClose={handleClose}>
|
2023-05-23 21:13:01 +02:00
|
|
|
<MenuItem onClick={() => navigate(routes.account)}>
|
|
|
|
<ListItemIcon>
|
|
|
|
<Person />
|
|
|
|
</ListItemIcon>
|
|
|
|
<b>{session.username()}</b>
|
|
|
|
</MenuItem>
|
|
|
|
<Divider />
|
|
|
|
<MenuItem onClick={() => navigate(routes.settings)}>
|
|
|
|
<ListItemIcon>
|
|
|
|
<Settings fontSize="small" />
|
|
|
|
</ListItemIcon>
|
|
|
|
{t("action_bar_profile_settings")}
|
|
|
|
</MenuItem>
|
|
|
|
<MenuItem onClick={handleLogout}>
|
|
|
|
<ListItemIcon>
|
|
|
|
<Logout fontSize="small" />
|
|
|
|
</ListItemIcon>
|
|
|
|
{t("action_bar_profile_logout")}
|
|
|
|
</MenuItem>
|
|
|
|
</PopupMenu>
|
|
|
|
</>
|
|
|
|
);
|
2022-12-02 21:37:48 +01:00
|
|
|
};
|
|
|
|
|
2022-02-25 18:46:22 +01:00
|
|
|
export default ActionBar;
|