add contests

This commit is contained in:
Виталий Лавшонок
2025-12-05 23:42:18 +03:00
parent 358c7def78
commit fd34761745
36 changed files with 2518 additions and 710 deletions

View File

@@ -4,31 +4,28 @@ import { cn } from '../../../lib/cn';
import { useAppDispatch, useAppSelector } from '../../../redux/hooks';
import ContestsBlock from './ContestsBlock';
import { setMenuActivePage } from '../../../redux/slices/store';
import { fetchContests, fetchMyContests, fetchParticipatingContests } from '../../../redux/slices/contests';
import {
fetchContests,
fetchMyContests,
fetchParticipatingContests,
} from '../../../redux/slices/contests';
import ModalCreateContest from './ModalCreate';
import Filters from './Filter';
const Contests = () => {
const dispatch = useAppDispatch();
const now = new Date();
const [modalActive, setModalActive] = useState<boolean>(false);
// Берём данные из Redux
const contests = useAppSelector(
(state) => state.contests.fetchContests.contests,
const { contests, status } = useAppSelector(
(state) => state.contests.fetchContests,
);
const status = useAppSelector(
(state) => state.contests.fetchContests.status,
);
const error = useAppSelector((state) => state.contests.fetchContests.error);
// При загрузке страницы — выставляем активную вкладку и подгружаем контесты
useEffect(() => {
dispatch(setMenuActivePage('contests'));
dispatch(fetchContests({}));
dispatch(fetchParticipatingContests({pageSize:100}));
dispatch(fetchParticipatingContests({ pageSize: 100 }));
dispatch(fetchMyContests());
}, []);
@@ -58,31 +55,24 @@ const Contests = () => {
Загрузка контестов...
</div>
)}
{status == 'failed' && (
<div className="text-red-500 p-4">Ошибка: {error}</div>
)}
{status == 'successful' && (
<>
<ContestsBlock
className="mb-[20px]"
title="Текущие"
contests={contests.filter((contest) => {
const endTime = new Date(
contest.endsAt ?? new Date().toDateString(),
).getTime();
return endTime >= now.getTime();
})}
contests={contests.filter(
(c) => c.scheduleType != 'AlwaysOpen',
)}
type="upcoming"
/>
<ContestsBlock
className="mb-[20px]"
title=рошедшие"
contests={contests.filter((contest) => {
const endTime = new Date(
contest.endsAt ?? new Date().toDateString(),
).getTime();
return endTime < now.getTime();
})}
title=остоянные"
contests={contests.filter(
(c) => c.scheduleType == 'AlwaysOpen',
)}
type="past"
/>
</>
)}