diff --git a/frontend/src/page/share/component/nav-bar.tsx b/frontend/src/page/share/component/nav-bar.tsx new file mode 100644 index 0000000..d83e193 --- /dev/null +++ b/frontend/src/page/share/component/nav-bar.tsx @@ -0,0 +1,81 @@ +import React, {useEffect, useState} from 'react'; +import {createUseStyles} from 'react-jss'; + +const useStyle = createUseStyles({ + nav: { + display: 'flex', + alignItems: 'center', + justifyContent: 'space-between', + padding: '0 24px', + height: '48px', + backgroundColor: '#2c9678', + boxShadow: '0 2px 6px rgba(0,0,0,0.15)', + flexShrink: 0, + }, + brand: { + color: 'white', + fontWeight: 700, + fontSize: '18px', + letterSpacing: '1px', + textDecoration: 'none', + }, + links: { + display: 'flex', + gap: '8px', + alignItems: 'center', + }, + link: { + color: 'rgba(255,255,255,0.9)', + fontSize: '13px', + textDecoration: 'none', + padding: '5px 12px', + borderRadius: '4px', + transition: 'background-color 0.2s', + '&:hover': { + backgroundColor: 'rgba(255,255,255,0.2)', + color: 'white', + }, + }, + divider: { + color: 'rgba(255,255,255,0.4)', + fontSize: '13px', + }, +}); + +export const NavBar: React.FC = () => { + const style = useStyle(); + const [isAdmin, setIsAdmin] = useState(false); + const [hasTokenPerm, setHasTokenPerm] = useState(false); + + useEffect(() => { + fetch('/api/uauth/me').then(async res => { + if (res.ok) { + const json = await res.json(); + const perms: string[] = json.data?.permissions ?? []; + setIsAdmin(perms.includes('user_manage')); + setHasTokenPerm(perms.includes('token_manage')); + } + }).catch(() => {}); + }, []); + + const showLinks = isAdmin || hasTokenPerm; + + return ( + + ); +}; diff --git a/frontend/src/page/share/component/panel-left.tsx b/frontend/src/page/share/component/panel-left.tsx index db1f767..fd44e92 100644 --- a/frontend/src/page/share/component/panel-left.tsx +++ b/frontend/src/page/share/component/panel-left.tsx @@ -1,6 +1,6 @@ import {createUseStyles} from "react-jss"; import {UButton} from "../../../component/button/u-button.tsx"; -import React, {useEffect, useState} from "react"; +import React, {useState} from "react"; import {useStore} from "../../../store/share.ts"; import {message} from "../../../hook/message/u-message.tsx"; import {useFileUpload} from "../../../api/upload.ts"; @@ -60,22 +60,6 @@ const useUploadStyle = createUseStyles({ cursor: 'pointer', '&:hover': {} }, - adminLink: { - display: 'block', - textAlign: 'center', - marginTop: '16px', - color: '#2c9678', - fontSize: '12px', - textDecoration: 'none', - opacity: 0.8, - '&:hover': {opacity: 1, textDecoration: 'underline'}, - }, - navLinks: { - display: 'flex', - justifyContent: 'center', - gap: '16px', - marginTop: '16px', - }, }) const useShowStyle = createUseStyles({ @@ -195,22 +179,9 @@ const PanelLeftUpload: React.FC<{ set_code: (code:string) => void }> = ({set_cod const style = useUploadStyle() const {file, setFile} = useStore() const {uploadFile, progress, loading} = useFileUpload(); - const [isAdmin, setIsAdmin] = useState(false); - const [hasTokenPerm, setHasTokenPerm] = useState(false); - - useEffect(() => { - fetch('/api/uauth/me').then(async res => { - if (res.ok) { - const json = await res.json(); - const perms: string[] = json.data?.permissions ?? []; - setIsAdmin(perms.includes('user_manage')); - setHasTokenPerm(perms.includes('token_manage')); - } - }).catch(() => {}); - }, []); function onFileSelect() { - // @ts-ignore + // @ts-expect-error no types for direct DOM query document.querySelector('#real-file-input').click(); } @@ -254,12 +225,6 @@ const PanelLeftUpload: React.FC<{ set_code: (code:string) => void }> = ({set_cod