add: marketplace

This commit is contained in:
2025-07-19 04:40:46 +05:00
parent c39a8bc43c
commit 6ee1b67315
6 changed files with 1081 additions and 39 deletions

View File

@ -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>
)}