Optimize code

This commit is contained in:
2024-01-08 13:43:47 +08:00
parent d526d913b9
commit 88c66bd7a7
12 changed files with 68 additions and 70 deletions

View File

@@ -11,7 +11,7 @@ interface IndicatorProps {
const Indicator: React.FC<IndicatorProps> = ({ total, current, onSwitch }) => {
const handleClick = (index: number) => {
return () => {
onSwitch && onSwitch(index)
onSwitch?.(index)
}
}

View File

@@ -16,7 +16,7 @@ const Item: React.FC<ItemProps> = (props) => {
const showSubmenu = (e: React.MouseEvent) => {
const parentElement = e.currentTarget.parentElement
if (parentElement && parentElement.childElementCount === 2) {
if (parentElement?.childElementCount === 2) {
const parentClientRect = parentElement.getBoundingClientRect()
if (parentClientRect.top <= screen.height / 2) {
setSubmenuTop(parentClientRect.top)
@@ -42,18 +42,16 @@ const Item: React.FC<ItemProps> = (props) => {
}
>
<div className={'icon-box'}>
{props.icon ? (
<Icon className={'icon'} component={props.icon} />
) : undefined}
{props.icon && <Icon className={'icon'} component={props.icon} />}
</div>
<span className={'text'}>{props.text}</span>
</NavLink>
</div>
{props.children ? (
{props.children && (
<Submenu submenuTop={submenuTop} submenuLeft={submenuLeft}>
{props.children}
</Submenu>
) : undefined}
)}
</li>
)
}

View File

@@ -29,7 +29,7 @@ const Sidebar: React.FC<SidebarProps> & {
const switchSidebar = () => {
setLocalStorage('HIDE_SIDEBAR', !hideSidebar ? 'true' : 'false')
setHideSidebar(!hideSidebar)
props.onSidebarSwitch && props.onSidebarSwitch(hideSidebar)
props.onSidebarSwitch?.(hideSidebar)
}
return (