|
1 |
| -import { Button, Portal } from '@blueprintjs/core' |
| 1 | +import { Drawer, Menu, MenuDivider } from '@blueprintjs/core' |
| 2 | +import { MenuItem2 } from '@blueprintjs/popover2' |
2 | 3 |
|
3 | 4 | import { useAtomValue, useSetAtom } from 'jotai'
|
4 |
| -import { LINKS } from 'layouts/AppLayout' |
| 5 | +import { useState } from 'react' |
5 | 6 | import { NavLink } from 'react-router-dom'
|
6 | 7 |
|
7 | 8 | import { navAtom, toggleExpandNavAtom } from 'store/nav'
|
8 | 9 |
|
| 10 | +import { NAV_LINKS, SOCIAL_LINKS } from '../../links' |
| 11 | +import { useCurrentSize } from '../../utils/useCurrenSize' |
| 12 | +import { AnnPanel } from '../announcement/AnnPanel' |
| 13 | +import { OperationSetEditorDialog } from '../operation-set/OperationSetEditor' |
| 14 | + |
9 | 15 | export const NavAside = () => {
|
| 16 | + const { isMD } = useCurrentSize() |
10 | 17 | const nav = useAtomValue(navAtom)
|
11 | 18 | const toggleNav = useSetAtom(toggleExpandNavAtom)
|
12 |
| - const navLinks = [...LINKS] |
13 | 19 |
|
14 |
| - if (!nav.expanded) return null |
| 20 | + const [showOperationSetDialog, setShowOperationSetDialog] = useState(false) |
| 21 | + |
| 22 | + if (!isMD) return null |
15 | 23 |
|
16 | 24 | return (
|
17 |
| - <Portal> |
18 |
| - {/* todo: 这里可以重写移动端header 需要去掉top */} |
19 |
| - <div className="fixed inset-0 top-14 z-50 overflow-y-auto backdrop-blur-lg sm:hidden"> |
20 |
| - <div className="px-4 sm:px-6 pt-3 pb-6"> |
21 |
| - <nav className="flex flex-col gap-3"> |
22 |
| - {navLinks.map((link) => ( |
23 |
| - <div className="flex-col w-full" key={link.to}> |
24 |
| - <NavLink |
25 |
| - to={link.to} |
26 |
| - className="text-sm text-zinc-600 dark:text-slate-100 !no-underline" |
| 25 | + <> |
| 26 | + <Drawer |
| 27 | + isOpen={isMD && !!nav.expanded} |
| 28 | + onClose={() => toggleNav()} |
| 29 | + position="left" |
| 30 | + size="100%" |
| 31 | + portalClassName="[&>.bp4-overlay-container]:z-10" |
| 32 | + backdropClassName="bg-transparent" |
| 33 | + className="bg-transparent backdrop-blur-lg overflow-y-auto mt-14 p-2" |
| 34 | + > |
| 35 | + <Menu className="p-0 space-y-2 bg-transparent font-bold"> |
| 36 | + {NAV_LINKS.map((link) => ( |
| 37 | + <NavLink key={link.to} to={link.to} className="block !no-underline"> |
| 38 | + {({ isActive }) => ( |
| 39 | + <MenuItem2 |
| 40 | + key={link.to} |
| 41 | + icon={link.icon} |
| 42 | + active={isActive} |
| 43 | + text={link.label} |
| 44 | + className="p-2 rounded-md" |
| 45 | + tagName="div" |
27 | 46 | onClick={() => toggleNav()}
|
28 |
| - > |
29 |
| - {({ isActive }) => ( |
30 |
| - <Button |
31 |
| - minimal |
32 |
| - icon={link.icon} |
33 |
| - active={isActive} |
34 |
| - className="w-full flex items-center" |
35 |
| - style={{ justifyContent: 'flex-start' }} |
36 |
| - > |
37 |
| - {link.label} |
38 |
| - </Button> |
39 |
| - )} |
40 |
| - </NavLink> |
41 |
| - </div> |
42 |
| - ))} |
43 |
| - </nav> |
| 47 | + /> |
| 48 | + )} |
| 49 | + </NavLink> |
| 50 | + ))} |
| 51 | + <MenuDivider /> |
| 52 | + <MenuItem2 |
| 53 | + icon="folder-new" |
| 54 | + text="创建作业集..." |
| 55 | + className="p-2 rounded-md" |
| 56 | + onClick={() => { |
| 57 | + setShowOperationSetDialog(true) |
| 58 | + toggleNav() |
| 59 | + }} |
| 60 | + /> |
| 61 | + <AnnPanel |
| 62 | + trigger={({ handleClick }) => ( |
| 63 | + <MenuItem2 |
| 64 | + icon="info-sign" |
| 65 | + text="公告" |
| 66 | + className="p-2 rounded-md" |
| 67 | + onClick={handleClick} |
| 68 | + /> |
| 69 | + )} |
| 70 | + /> |
| 71 | + <MenuDivider /> |
| 72 | + </Menu> |
| 73 | + <div className="flex flex-wrap leading-relaxed mt-2 p-2 section-social-links"> |
| 74 | + {SOCIAL_LINKS.map((link) => ( |
| 75 | + <a |
| 76 | + href={link.href} |
| 77 | + target="_blank" |
| 78 | + rel="noopener noreferrer" |
| 79 | + className="flex items-center text-zinc-600 dark:text-slate-100 no-underline" |
| 80 | + > |
| 81 | + {link.icon} |
| 82 | + <span>{link.label}</span> |
| 83 | + </a> |
| 84 | + )).reduce((prev, curr) => ( |
| 85 | + <> |
| 86 | + {prev} |
| 87 | + <div className="mx-2 opacity-50">·</div> |
| 88 | + {curr} |
| 89 | + </> |
| 90 | + ))} |
44 | 91 | </div>
|
45 |
| - </div> |
46 |
| - </Portal> |
| 92 | + </Drawer> |
| 93 | + |
| 94 | + <OperationSetEditorDialog |
| 95 | + isOpen={showOperationSetDialog} |
| 96 | + onClose={() => setShowOperationSetDialog(false)} |
| 97 | + /> |
| 98 | + </> |
47 | 99 | )
|
48 | 100 | }
|
0 commit comments