-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
74 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,124 +1,60 @@ | ||
import { Code, Group, Navbar, createStyles, getStylesRef } from "@mantine/core"; | ||
import { | ||
IconBook, | ||
IconLogout, | ||
IconPencil, | ||
IconUser, | ||
IconDatabaseImport, | ||
} from "@tabler/icons-react"; | ||
import { signOut } from "next-auth/react"; | ||
import Link from "next/link"; | ||
import { useRouter } from "next/router"; | ||
import { MouseEventHandler } from "react"; | ||
import PJSON from "../package.json"; | ||
|
||
const signouthandler: MouseEventHandler<HTMLAnchorElement> = (event) => { | ||
event.preventDefault(); | ||
signOut(); | ||
}; | ||
|
||
const useStyles = createStyles((theme) => ({ | ||
header: { | ||
paddingBottom: theme.spacing.md, | ||
marginBottom: `calc(${theme.spacing.md} * 1.5)`, | ||
}, | ||
import { signOut } from "next-auth/react"; | ||
|
||
link: { | ||
...theme.fn.focusStyles(), | ||
const NavBar = () => { | ||
const navBarStyle = { | ||
width: "100%", | ||
height: "64px", | ||
display: "flex", | ||
alignItems: "center", | ||
textDecoration: "none", | ||
fontSize: theme.fontSizes.sm, | ||
color: | ||
theme.colorScheme === "dark" | ||
? theme.colors.dark[1] | ||
: theme.colors.gray[7], | ||
padding: `${theme.spacing.xs} ${theme.spacing.sm}`, | ||
borderRadius: theme.radius.sm, | ||
fontWeight: 500, | ||
|
||
"&:hover": { | ||
backgroundColor: | ||
theme.colorScheme === "dark" | ||
? theme.colors.dark[6] | ||
: theme.colors.gray[0], | ||
color: theme.colorScheme === "dark" ? theme.white : theme.black, | ||
|
||
[`& .${getStylesRef("icon")}`]: { | ||
color: theme.colorScheme === "dark" ? theme.white : theme.black, | ||
}, | ||
}, | ||
}, | ||
|
||
linkIcon: { | ||
ref: getStylesRef("icon"), | ||
color: | ||
theme.colorScheme === "dark" | ||
? theme.colors.dark[2] | ||
: theme.colors.gray[6], | ||
marginRight: theme.spacing.sm, | ||
}, | ||
|
||
linkActive: { | ||
"&, &:hover": { | ||
backgroundColor: theme.fn.variant({ | ||
variant: "light", | ||
color: theme.primaryColor, | ||
}).background, | ||
color: theme.fn.variant({ variant: "light", color: theme.primaryColor }) | ||
.color, | ||
[`& .${getStylesRef("icon")}`]: { | ||
color: theme.fn.variant({ variant: "light", color: theme.primaryColor }) | ||
.color, | ||
}, | ||
}, | ||
}, | ||
})); | ||
|
||
const data = [ | ||
{ link: "/study", label: "Study", icon: IconBook }, | ||
{ link: "/cards", label: "Edit Cards", icon: IconPencil }, | ||
{ link: "/import", label: "Import Cards", icon: IconDatabaseImport }, | ||
{ link: "/user", label: "User", icon: IconUser }, | ||
]; | ||
|
||
export default function NavbarSimple() { | ||
const { classes, cx } = useStyles(); | ||
const router = useRouter(); | ||
const links = data.map((item) => { | ||
const isActive = router.pathname === item.link; | ||
return ( | ||
<Link | ||
className={cx(classes.link, { | ||
[classes.linkActive]: isActive, | ||
})} | ||
href={item.link} | ||
key={item.label} | ||
> | ||
<item.icon className={classes.linkIcon} stroke={1.5} /> | ||
<span>{item.label}</span> | ||
</Link> | ||
); | ||
}); | ||
backgroundColor: "#333", | ||
color: "white", | ||
padding: "0 16px", | ||
}; | ||
|
||
const linkStyle = { | ||
margin: "0 16px", | ||
color: "lightgray", | ||
"text-decoration": "none", | ||
"font-weight": "bold", | ||
}; | ||
|
||
const logoutButtonStyle = { | ||
...linkStyle, | ||
margin: undefined, | ||
marginLeft: "auto", | ||
cursor: "pointer", | ||
}; | ||
|
||
const links = [ | ||
{ path: "/study", name: "Study" }, | ||
{ path: "/import", name: "Import" }, | ||
{ path: "/cards", name: "Edit" }, | ||
{ path: "/user", name: "Settings" }, | ||
]; | ||
|
||
return ( | ||
<Navbar width={{ sm: 300 }} p="md"> | ||
<Navbar.Section grow> | ||
<Group className={classes.header} position="apart"> | ||
<span style={{ fontSize: "24px", marginRight: "10px" }}> | ||
<span role="img" aria-label="Koala"> | ||
🐨 | ||
</span> | ||
</span> | ||
<span style={{ fontSize: "24px", fontWeight: "bold" }}>KoalaSRS</span> | ||
<Code sx={{ fontWeight: 700 }}>v{PJSON.version}</Code> | ||
</Group> | ||
{links} | ||
<a href="#" className={classes.link} onClick={signouthandler}> | ||
<IconLogout className={classes.linkIcon} stroke={1.5} /> | ||
<span>Logout</span> | ||
</a> | ||
</Navbar.Section> | ||
</Navbar> | ||
<div style={navBarStyle}> | ||
<Link href={"/"} role="img" aria-label="koala" style={linkStyle}> | ||
🐨 | ||
</Link> | ||
{links.map((link, index) => ( | ||
<Link key={index} href={link.path} style={linkStyle}> | ||
{link.name} | ||
</Link> | ||
))} | ||
<div | ||
style={logoutButtonStyle} | ||
onClick={(event) => { | ||
event.preventDefault(); | ||
signOut(); | ||
location.assign("/"); | ||
}} | ||
> | ||
Log Out | ||
</div> | ||
</div> | ||
); | ||
} | ||
}; | ||
|
||
export default NavBar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters