Debian Codegraph @

web/src/components/AvatarBox.jsx

raw
1 import * as React from "react";
2 import { Avatar, Box, styled } from "@mui/material";
3 import { useNavigate } from "react-router-dom";
4 import logo from "../img/ntfy-filled.svg";
5 import routes from "./routes";
6 import { fadeNavigate } from "../app/transition";
7
8 const AvatarBoxContainer = styled(Box)`
9 display: flex;
10 flex-grow: 1;
11 justify-content: center;
12 flex-direction: column;
13 align-content: center;
14 align-items: center;
15 height: 100dvh;
16 max-width: min(400px, 90dvw);
17 margin: auto;
18 `;
19 const AvatarBox = (props) => {
20 const navigate = useNavigate();
21 const avatar = <Avatar sx={{ m: 2, width: 64, height: 64, borderRadius: 3 }} src={logo} variant="rounded" />;
22 // Fade back to the app instead of a hard cut. Let modifier-clicks (open in new tab, etc.) through.
23 const handleLogoClick = (ev) => {
24 if (ev.metaKey || ev.ctrlKey || ev.shiftKey || ev.altKey) {
25 return;
26 }
27 ev.preventDefault();
28 fadeNavigate(navigate, routes.app);
29 };
30 return (
31 <AvatarBoxContainer>
32 {/* The logo links back to the app, unless login is forced (no app to go back to without signing in) */}
33 {config.require_login ? (
34 avatar
35 ) : (
36 <Box component="a" href={routes.app} onClick={handleLogoClick} sx={{ cursor: "pointer", lineHeight: 0 }}>
37 {avatar}
38 </Box>
39 )}
40 {props.children}
41 </AvatarBoxContainer>
42 );
43 };
44
45 export default AvatarBox;