🧹 refactor(PageLayout): remove unused state variables
Removed unused `userState` and `statusState` bindings from `PageLayout.js` while retaining their dispatch functions for authentication and status management. Confirmed correct use of array destructuring to skip the unused toggle function returned by `useSidebarCollapsed`. This change introduces no functional differences and solely improves readability and maintainability.
This commit is contained in:
@@ -15,8 +15,8 @@ import { useLocation } from 'react-router-dom';
|
|||||||
const { Sider, Content, Header } = Layout;
|
const { Sider, Content, Header } = Layout;
|
||||||
|
|
||||||
const PageLayout = () => {
|
const PageLayout = () => {
|
||||||
const [userState, userDispatch] = useContext(UserContext);
|
const [, userDispatch] = useContext(UserContext);
|
||||||
const [statusState, statusDispatch] = useContext(StatusContext);
|
const [, statusDispatch] = useContext(StatusContext);
|
||||||
const isMobile = useIsMobile();
|
const isMobile = useIsMobile();
|
||||||
const [collapsed, , setCollapsed] = useSidebarCollapsed();
|
const [collapsed, , setCollapsed] = useSidebarCollapsed();
|
||||||
const [drawerOpen, setDrawerOpen] = useState(false);
|
const [drawerOpen, setDrawerOpen] = useState(false);
|
||||||
@@ -32,7 +32,6 @@ const PageLayout = () => {
|
|||||||
const isConsoleRoute = location.pathname.startsWith('/console');
|
const isConsoleRoute = location.pathname.startsWith('/console');
|
||||||
const showSider = isConsoleRoute && (!isMobile || drawerOpen);
|
const showSider = isConsoleRoute && (!isMobile || drawerOpen);
|
||||||
|
|
||||||
// Ensure sidebar not collapsed when opening drawer on mobile
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isMobile && drawerOpen && collapsed) {
|
if (isMobile && drawerOpen && collapsed) {
|
||||||
setCollapsed(false);
|
setCollapsed(false);
|
||||||
@@ -76,7 +75,6 @@ const PageLayout = () => {
|
|||||||
linkElement.href = logo;
|
linkElement.href = logo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 从localStorage获取上次使用的语言
|
|
||||||
const savedLang = localStorage.getItem('i18nextLng');
|
const savedLang = localStorage.getItem('i18nextLng');
|
||||||
if (savedLang) {
|
if (savedLang) {
|
||||||
i18n.changeLanguage(savedLang);
|
i18n.changeLanguage(savedLang);
|
||||||
@@ -125,7 +123,6 @@ const PageLayout = () => {
|
|||||||
width: 'var(--sidebar-current-width)',
|
width: 'var(--sidebar-current-width)',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{/* 在移动端点击菜单后关闭侧边栏 */}
|
|
||||||
<SiderBar onNavigate={() => { if (isMobile) setDrawerOpen(false); }} />
|
<SiderBar onNavigate={() => { if (isMobile) setDrawerOpen(false); }} />
|
||||||
</Sider>
|
</Sider>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in New Issue
Block a user