feat(frontend): race form, start time selects, calendar views, day page
Some checks failed
CI / build-and-test (pull_request) Has been cancelled
Some checks failed
CI / build-and-test (pull_request) Has been cancelled
- Hide org schedule fields when editing a past race; isRaceDateInPast helper - StartTimeSelects (HH:mm:ss) and optional ?date= prefill on new race - Full-card link to edit for races needing result entry; shadow token - List/calendar toggle (sessionStorage); year grid and month focus views - Date hover popover and /races/day/:ymd page with Add button - Docs plan-korrektirovok-starty.md and startTime API note; client 0.4.0 Made-with: Cursor
This commit is contained in:
49
frontend/src/lib/calendarUtils.ts
Normal file
49
frontend/src/lib/calendarUtils.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import type { Race } from "../api";
|
||||
|
||||
export const WEEKDAY_LABELS_SHORT_RU: string[] = ["Пн", "Вт", "Ср", "Чт", "Пт", "Сб", "Вс"];
|
||||
|
||||
/** Monday-based week: Mon=0 … Sun=6 */
|
||||
export function mondayIndexFromDate(d: Date): number {
|
||||
return (d.getDay() + 6) % 7;
|
||||
}
|
||||
|
||||
/** Grid cells for one month: `null` = empty, `1..31` = day of month. Padded to full weeks, at least 6 rows. */
|
||||
export function buildMonthCells(year: number, monthIndex: number): (number | null)[] {
|
||||
const first = new Date(year, monthIndex, 1);
|
||||
const lead = mondayIndexFromDate(first);
|
||||
const dim = new Date(year, monthIndex + 1, 0).getDate();
|
||||
const cells: (number | null)[] = [];
|
||||
for (let i = 0; i < lead; i += 1) {
|
||||
cells.push(null);
|
||||
}
|
||||
for (let day = 1; day <= dim; day += 1) {
|
||||
cells.push(day);
|
||||
}
|
||||
while (cells.length % 7 !== 0) {
|
||||
cells.push(null);
|
||||
}
|
||||
while (cells.length < 42) {
|
||||
cells.push(null);
|
||||
}
|
||||
return cells;
|
||||
}
|
||||
|
||||
export function toYmd(year: number, monthIndex: number, day: number): string {
|
||||
const m = String(monthIndex + 1).padStart(2, "0");
|
||||
const d = String(day).padStart(2, "0");
|
||||
return `${year}-${m}-${d}`;
|
||||
}
|
||||
|
||||
export function groupRacesByYmd(races: Race[]): Map<string, Race[]> {
|
||||
const map = new Map<string, Race[]>();
|
||||
for (const race of races) {
|
||||
const ymd = race.date.slice(0, 10);
|
||||
if (!/^\d{4}-\d{2}-\d{2}$/.test(ymd)) {
|
||||
continue;
|
||||
}
|
||||
const list = map.get(ymd) ?? [];
|
||||
list.push(race);
|
||||
map.set(ymd, list);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
Reference in New Issue
Block a user