feat: align docs with code, finish_place, registered status, UI filters, tests, CI
Some checks failed
CI / build-and-test (pull_request) Has been cancelled
Some checks failed
CI / build-and-test (pull_request) Has been cancelled
- Add PLAN.md and sync backend docs, .env.example, API doc (404 details) - Document mock DB and PORT/API_PORT in docs/backend.md; README monorepo + frontend/.env.example - Migration 002: finish_place column, status registered; mapper and mock DB updated - Frontend: registered status, finishPlace, calendar year/month filters, pace sparkline - Extract createApp for tests; supertest + tsx; GitHub Actions CI Made-with: Cursor
This commit is contained in:
@@ -1,8 +1,41 @@
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import type { Race } from "../api";
|
||||
import type { Race, RacesQuery } from "../api";
|
||||
import { ApiError, getRaces } from "../api";
|
||||
import { formatDistance, formatRaceDate, getRaceStatusLabel, splitRacesByDate } from "../lib";
|
||||
import {
|
||||
formatDistance,
|
||||
formatRaceDate,
|
||||
getRaceStatusClassName,
|
||||
getRaceStatusLabel,
|
||||
splitRacesByDate,
|
||||
} from "../lib";
|
||||
|
||||
const MONTH_OPTIONS: { value: string; label: string }[] = [
|
||||
{ value: "", label: "Все месяцы" },
|
||||
{ value: "1", label: "Январь" },
|
||||
{ value: "2", label: "Февраль" },
|
||||
{ value: "3", label: "Март" },
|
||||
{ value: "4", label: "Апрель" },
|
||||
{ value: "5", label: "Май" },
|
||||
{ value: "6", label: "Июнь" },
|
||||
{ value: "7", label: "Июль" },
|
||||
{ value: "8", label: "Август" },
|
||||
{ value: "9", label: "Сентябрь" },
|
||||
{ value: "10", label: "Октябрь" },
|
||||
{ value: "11", label: "Ноябрь" },
|
||||
{ value: "12", label: "Декабрь" },
|
||||
];
|
||||
|
||||
function yearSelectOptions(): number[] {
|
||||
const current = new Date().getFullYear();
|
||||
const start = current - 2;
|
||||
const end = current + 4;
|
||||
const years: number[] = [];
|
||||
for (let y = start; y <= end; y += 1) {
|
||||
years.push(y);
|
||||
}
|
||||
return years;
|
||||
}
|
||||
|
||||
function getErrorMessage(error: unknown): string {
|
||||
if (error instanceof ApiError) {
|
||||
@@ -31,15 +64,7 @@ function RaceList(props: { title: string; races: Race[] }): JSX.Element {
|
||||
{formatRaceDate(race.date)} · {formatDistance(race.distanceKm)}
|
||||
</p>
|
||||
</div>
|
||||
<span
|
||||
className={
|
||||
race.status === "completed"
|
||||
? "race-card__status race-card__status--completed"
|
||||
: "race-card__status race-card__status--planned"
|
||||
}
|
||||
>
|
||||
{getRaceStatusLabel(race.status)}
|
||||
</span>
|
||||
<span className={getRaceStatusClassName(race.status)}>{getRaceStatusLabel(race.status)}</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
@@ -54,13 +79,33 @@ export function RacesPage(): JSX.Element {
|
||||
const [races, setRaces] = useState<Race[]>([]);
|
||||
const [isLoading, setIsLoading] = useState<boolean>(true);
|
||||
const [errorMessage, setErrorMessage] = useState<string | null>(null);
|
||||
const [yearFilter, setYearFilter] = useState<string>("");
|
||||
const [monthFilter, setMonthFilter] = useState<string>("");
|
||||
|
||||
const listQuery = useMemo((): RacesQuery | undefined => {
|
||||
const q: RacesQuery = {};
|
||||
if (yearFilter !== "") {
|
||||
const y = parseInt(yearFilter, 10);
|
||||
if (!Number.isNaN(y)) {
|
||||
q.year = y;
|
||||
}
|
||||
}
|
||||
if (monthFilter !== "") {
|
||||
const m = parseInt(monthFilter, 10);
|
||||
if (!Number.isNaN(m)) {
|
||||
q.month = m;
|
||||
}
|
||||
}
|
||||
return Object.keys(q).length > 0 ? q : undefined;
|
||||
}, [yearFilter, monthFilter]);
|
||||
|
||||
useEffect(() => {
|
||||
let isMounted = true;
|
||||
|
||||
async function loadRaces(): Promise<void> {
|
||||
setIsLoading(true);
|
||||
try {
|
||||
const items = await getRaces();
|
||||
const items = await getRaces(listQuery);
|
||||
if (!isMounted) {
|
||||
return;
|
||||
}
|
||||
@@ -82,20 +127,11 @@ export function RacesPage(): JSX.Element {
|
||||
return () => {
|
||||
isMounted = false;
|
||||
};
|
||||
}, []);
|
||||
}, [listQuery]);
|
||||
|
||||
const { upcoming, past } = useMemo(() => splitRacesByDate(races), [races]);
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<section className="page page--races" aria-busy="true">
|
||||
<h1 className="page__title">Календарь стартов</h1>
|
||||
<p className="page__subtitle">Загружаем данные...</p>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
if (errorMessage) {
|
||||
if (errorMessage && races.length === 0 && !isLoading) {
|
||||
return (
|
||||
<section className="page page--races" role="alert">
|
||||
<h1 className="page__title">Календарь стартов</h1>
|
||||
@@ -109,6 +145,48 @@ export function RacesPage(): JSX.Element {
|
||||
<h1 className="page__title">Календарь стартов</h1>
|
||||
<p className="page__subtitle">Будущие и прошедшие старты в одном месте.</p>
|
||||
|
||||
<div className="races-filter" role="search" aria-label="Фильтр по дате">
|
||||
<label className="races-filter__field">
|
||||
<span className="races-filter__label">Год</span>
|
||||
<select
|
||||
className="races-filter__select"
|
||||
value={yearFilter}
|
||||
onChange={(event) => {
|
||||
setYearFilter(event.target.value);
|
||||
}}
|
||||
>
|
||||
<option value="">Все года</option>
|
||||
{yearSelectOptions().map((y) => (
|
||||
<option key={y} value={String(y)}>
|
||||
{y}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<label className="races-filter__field">
|
||||
<span className="races-filter__label">Месяц</span>
|
||||
<select
|
||||
className="races-filter__select"
|
||||
value={monthFilter}
|
||||
onChange={(event) => {
|
||||
setMonthFilter(event.target.value);
|
||||
}}
|
||||
>
|
||||
{MONTH_OPTIONS.map((opt) => (
|
||||
<option key={opt.value || "all"} value={opt.value}>
|
||||
{opt.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
{isLoading ? (
|
||||
<p className="page__subtitle" aria-busy="true">
|
||||
Загружаем данные...
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
<div className="race-lists">
|
||||
<RaceList title="Будущие" races={upcoming} />
|
||||
<RaceList title="Прошедшие" races={past} />
|
||||
|
||||
Reference in New Issue
Block a user