/
minimus
/
simple-view
Обзор
Документация
Войти
/
minimus
/
simple-view
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
develop
js-src/admin/components/header/AppHeader.tsx
64 строки
2 KB
minimus
feat: footer, header, loader
28 июл 2026, 12:42
28 июл 2026, 12:42
2d42178
Код
Авторство
О чём код?
import { AppBar, Box, Toolbar, Typography } from '@mui/material'; import React, { FC, useCallback, useEffect, useEffectEvent, useState } from 'react'; import { useLocation } from 'react-router-dom'; import { useShallow } from 'zustand/react/shallow'; import { useMainStore } from '../../data/stories/main/mainStore'; import AppMenu from './AppMenu'; const AppHeader: FC = () => { const { localeStrings, loadState } = useMainStore(useShallow((state) => state)); const { appHeader: { galleries = '', editor = '', items = '', settings = '' } = {} } = localeStrings ?? {}; const location = useLocation(); const { pathname } = location; const [title, setTitle] = useState<string>(''); const pageName = useCallback( (path: string) => { if (loadState === 'success') { if (path === '/' || path === '/galleries') { return galleries; } if (path === '/settings') { return settings; } if (/\/galleries\/(?:\d+|new)$/i.test(path)) { return editor; } if (/\/galleries\/\d+\/(?:\d+|new)$/i.test(path)) { return items; } return 'WTF'; } return '...'; }, [editor, galleries, items, settings, loadState], ); const updateTitle = useEffectEvent(() => { // eslint-disable-next-line react-x/set-state-in-effect setTitle(pageName(pathname)); }); useEffect(() => { updateTitle(); }, [pathname, loadState]); return ( <Box sx={{ flexGrow: 1 }}> <AppBar position="static"> <Toolbar> <AppMenu /> <Typography variant="h6" sx={{ flexGrow: 1 }}> {title} </Typography> </Toolbar> </AppBar> </Box> ); }; export default AppHeader;