import { Box, Button, Tab, Tabs, Typography } from '@mui/material'; import CloseRoundedIcon from '@mui/icons-material/CloseRounded'; import { useLocation, useNavigate } from 'react-router-dom'; import ArrowBackRoundedIcon from '@mui/icons-material/ArrowBackRounded'; import { useEffect, useState } from 'react'; import { Tooltip } from '@mui/material'; import { fetchCoins } from '../api'; declare global { interface Window { electron: { ipcRenderer: { invoke(channel: string, ...args: unknown[]): Promise; on(channel: string, func: (...args: unknown[]) => void): void; removeAllListeners(channel: string): void; }; }; } } // Определяем пропсы interface TopBarProps { onRegister?: () => void; // Опционально, если нужен обработчик регистрации username?: string; } export default function TopBar({ onRegister, username }: TopBarProps) { // Получаем текущий путь const location = useLocation(); const isLoginPage = location.pathname === '/login'; const isLaunchPage = location.pathname.startsWith('/launch'); const isVersionsExplorerPage = location.pathname.startsWith('/'); const navigate = useNavigate(); const [coins, setCoins] = useState(0); const [value, setValue] = useState(0); const handleChange = (event: React.SyntheticEvent, newValue: number) => { setValue(newValue); if (newValue === 0) { navigate('/'); } else if (newValue === 1) { navigate('/profile'); } else if (newValue === 2) { navigate('/shop'); } else if (newValue === 3) { navigate('/marketplace'); } }; const handleLaunchPage = () => { navigate('/'); }; const getPageTitle = () => { if (isLoginPage) { return 'Вход'; } if (isLaunchPage) { return 'Запуск'; } if (isVersionsExplorerPage) { return 'Версии'; } return 'Неизвестная страница'; }; // Функция для получения количества монет const fetchCoinsData = async () => { if (!username) return; try { const coinsData = await fetchCoins(username); setCoins(coinsData.coins); } catch (error) { console.error('Ошибка при получении количества монет:', error); } }; useEffect(() => { if (username) { fetchCoinsData(); // Создаем интервалы для периодического обновления данных const coinsInterval = setInterval(fetchCoinsData, 60000); return () => { clearInterval(coinsInterval); }; } }, [username]); return ( {/* Левая часть */} {isLaunchPage && ( )} {!isLaunchPage && ( )} {/* Центр */} {getPageTitle()} {/* Правая часть со всеми кнопками */} {/* Кнопка регистрации, если на странице логина */} {username && ( P {coins} )} {isLoginPage && ( )} {/* Кнопки управления окном */} ); }