add: marketplace
This commit is contained in:
@ -5,7 +5,6 @@ import ArrowBackRoundedIcon from '@mui/icons-material/ArrowBackRounded';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Tooltip } from '@mui/material';
|
||||
import { fetchCoins } from '../api';
|
||||
import { isPlayerOnline } from '../utils/playerOnlineCheck';
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
@ -34,7 +33,6 @@ export default function TopBar({ onRegister, username }: TopBarProps) {
|
||||
const navigate = useNavigate();
|
||||
const [coins, setCoins] = useState<number>(0);
|
||||
const [value, setValue] = useState(0);
|
||||
const [isOnline, setIsOnline] = useState<boolean>(false);
|
||||
|
||||
const handleChange = (event: React.SyntheticEvent, newValue: number) => {
|
||||
setValue(newValue);
|
||||
@ -78,30 +76,15 @@ export default function TopBar({ onRegister, username }: TopBarProps) {
|
||||
}
|
||||
};
|
||||
|
||||
const checkPlayerOnlineStatus = async () => {
|
||||
if (!username) return;
|
||||
|
||||
try {
|
||||
const online = await isPlayerOnline(username);
|
||||
setIsOnline(online);
|
||||
} catch (error) {
|
||||
console.error('Ошибка при проверке онлайн-статуса:', error);
|
||||
setIsOnline(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (username) {
|
||||
fetchCoinsData();
|
||||
checkPlayerOnlineStatus(); // Проверяем сразу
|
||||
|
||||
// Создаем интервалы для периодического обновления данных
|
||||
const coinsInterval = setInterval(fetchCoinsData, 60000);
|
||||
const onlineStatusInterval = setInterval(checkPlayerOnlineStatus, 30000); // Каждые 30 секунд
|
||||
|
||||
return () => {
|
||||
clearInterval(coinsInterval);
|
||||
clearInterval(onlineStatusInterval);
|
||||
};
|
||||
}
|
||||
}, [username]);
|
||||
@ -184,16 +167,14 @@ export default function TopBar({ onRegister, username }: TopBarProps) {
|
||||
fontSize: '0.7em',
|
||||
}}
|
||||
/>
|
||||
{isOnline && (
|
||||
<Tab
|
||||
label="Рынок"
|
||||
sx={{
|
||||
color: 'white',
|
||||
fontFamily: 'Benzin-Bold',
|
||||
fontSize: '0.7em',
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
<Tab
|
||||
label="Рынок"
|
||||
sx={{
|
||||
color: 'white',
|
||||
fontFamily: 'Benzin-Bold',
|
||||
fontSize: '0.7em',
|
||||
}}
|
||||
/>
|
||||
</Tabs>
|
||||
</Box>
|
||||
)}
|
||||
|
Reference in New Issue
Block a user