Commit df7a8c3b authored by timel's avatar timel

feat: nav link2

parent 7520d5f5
...@@ -32,12 +32,16 @@ ...@@ -32,12 +32,16 @@
font-size: 0.825rem; font-size: 0.825rem;
line-height: var(--header-height); line-height: var(--header-height);
transition: 0.3s; transition: 0.3s;
&:hover { &:not(.disabled):hover {
box-shadow: 0px 2px 0 0 white inset; box-shadow: 0px 2px 0 0 white inset;
} }
&:global(.active) { &:global(.active) {
box-shadow: 0px 2px 0 0 white inset; box-shadow: 0px 2px 0 0 white inset;
} }
&.disabled {
color: hsl(0, 0%, 50%);
cursor: not-allowed;
}
} }
} }
......
import { Avatar } from "antd"; import { Avatar } from "antd";
import { useEffect } from "react"; import React, { useEffect } from "react";
import { import {
type LoaderFunction, type LoaderFunction,
NavLink, NavLink,
...@@ -19,6 +19,7 @@ import { ...@@ -19,6 +19,7 @@ import {
initSqlite, initSqlite,
initWASM, initWASM,
} from "./utils"; } from "./utils";
import classNames from "classnames";
const NeosConfig = useConfig(); const NeosConfig = useConfig();
...@@ -30,6 +31,20 @@ export const loader: LoaderFunction = async () => { ...@@ -30,6 +31,20 @@ export const loader: LoaderFunction = async () => {
return null; return null;
}; };
const HeaderBtn: React.FC<
React.PropsWithChildren<{ to: string; disabled?: boolean }>
> = ({ to, children, disabled = false }) => {
const Element = disabled ? "div" : NavLink;
return (
<Element
to={disabled ? "/" : to}
className={classNames(styles.link, { [styles.disabled]: disabled })}
>
{children}
</Element>
);
};
export const Component = () => { export const Component = () => {
// 捕获SSO登录 // 捕获SSO登录
const location = useLocation(); const location = useLocation();
...@@ -37,7 +52,9 @@ export const Component = () => { ...@@ -37,7 +52,9 @@ export const Component = () => {
location.search && handleSSOLogin(location.search); location.search && handleSSOLogin(location.search);
}, [location.search]); }, [location.search]);
// TODO 根据是否登录,显示内容 // 根据是否登录,显示内容
const logined = Boolean(useSnapshot(accountStore).user);
const { pathname } = useLocation(); const { pathname } = useLocation();
const pathnamesHideHeader = ["/waitroom"]; const pathnamesHideHeader = ["/waitroom"];
return ( return (
...@@ -56,21 +73,19 @@ export const Component = () => { ...@@ -56,21 +73,19 @@ export const Component = () => {
/> />
</a> </a>
<NavLink to="/" className={styles.link}> <HeaderBtn to="/">主页</HeaderBtn>
主页 <HeaderBtn to="/match" disabled={!logined}>
</NavLink>
<NavLink to="/match" className={styles.link}>
匹配 匹配
</NavLink> </HeaderBtn>
<NavLink to="/build" className={styles.link}> <HeaderBtn to="/build" disabled={!logined}>
组卡 组卡
</NavLink> </HeaderBtn>
<span style={{ flexGrow: 1 }} /> <span style={{ flexGrow: 1 }} />
<span className={styles.profile}> <span className={styles.profile}>
<NeosAvatar /> <NeosAvatar />
<NavLink to="/profile" className={styles.link}> <HeaderBtn to="/profile" disabled={!logined}>
个人中心 个人中心
</NavLink> </HeaderBtn>
</span> </span>
</nav> </nav>
)} )}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment