add contests
This commit is contained in:
@@ -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"
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user