Merge pull request 'fix: use next race image as dashboard hero background' (#34) from fix/dashboard-hero-race-background into main
Some checks failed
CI / build-and-test (push) Has been cancelled
Some checks failed
CI / build-and-test (push) Has been cancelled
Reviewed-on: #34 fix: use next race image as dashboard hero background Set the dashboard hero background from the nearest upcoming race visual, using the existing race visual fallback chain. Add a BEM modifier for the image-backed hero state and bump the frontend patch version.
This commit was merged in pull request #34.
This commit is contained in:
4
frontend/package-lock.json
generated
4
frontend/package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "calendar-run-frontend",
|
"name": "calendar-run-frontend",
|
||||||
"version": "0.6.0",
|
"version": "0.6.1",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "calendar-run-frontend",
|
"name": "calendar-run-frontend",
|
||||||
"version": "0.6.0",
|
"version": "0.6.1",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"react": "^18.3.1",
|
"react": "^18.3.1",
|
||||||
"react-dom": "^18.3.1",
|
"react-dom": "^18.3.1",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "calendar-run-frontend",
|
"name": "calendar-run-frontend",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.6.0",
|
"version": "0.6.1",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import type { CSSProperties } from "react";
|
||||||
import { useEffect, useMemo, useState } from "react";
|
import { useEffect, useMemo, useState } from "react";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
import type { Race } from "../api";
|
import type { Race } from "../api";
|
||||||
@@ -7,6 +8,7 @@ import {
|
|||||||
formatDistance,
|
formatDistance,
|
||||||
formatRaceDate,
|
formatRaceDate,
|
||||||
getRaceCountdownLabel,
|
getRaceCountdownLabel,
|
||||||
|
getRaceVisual,
|
||||||
getPaceLabel,
|
getPaceLabel,
|
||||||
isCloseDistance,
|
isCloseDistance,
|
||||||
parseFinishTimeToSeconds,
|
parseFinishTimeToSeconds,
|
||||||
@@ -16,6 +18,10 @@ import {
|
|||||||
|
|
||||||
const PR_DISTANCES = [5, 10, 21.1, 42.2] as const;
|
const PR_DISTANCES = [5, 10, 21.1, 42.2] as const;
|
||||||
|
|
||||||
|
type DashboardHeroStyle = CSSProperties & {
|
||||||
|
"--dashboard-hero-image"?: string;
|
||||||
|
};
|
||||||
|
|
||||||
function getErrorMessage(error: unknown): string {
|
function getErrorMessage(error: unknown): string {
|
||||||
if (error instanceof ApiError) {
|
if (error instanceof ApiError) {
|
||||||
return error.message;
|
return error.message;
|
||||||
@@ -23,6 +29,10 @@ function getErrorMessage(error: unknown): string {
|
|||||||
return "Не удалось загрузить данные обзора.";
|
return "Не удалось загрузить данные обзора.";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toCssUrl(value: string): string {
|
||||||
|
return `url(${JSON.stringify(value)})`;
|
||||||
|
}
|
||||||
|
|
||||||
export function DashboardPage(): JSX.Element {
|
export function DashboardPage(): JSX.Element {
|
||||||
const [races, setRaces] = useState<Race[]>([]);
|
const [races, setRaces] = useState<Race[]>([]);
|
||||||
const [isLoading, setIsLoading] = useState<boolean>(true);
|
const [isLoading, setIsLoading] = useState<boolean>(true);
|
||||||
@@ -136,6 +146,10 @@ export function DashboardPage(): JSX.Element {
|
|||||||
dashboardMetrics.seasonTotal > 0
|
dashboardMetrics.seasonTotal > 0
|
||||||
? Math.round((dashboardMetrics.seasonCompletedCount / dashboardMetrics.seasonTotal) * 100)
|
? Math.round((dashboardMetrics.seasonCompletedCount / dashboardMetrics.seasonTotal) * 100)
|
||||||
: 0;
|
: 0;
|
||||||
|
const dashboardHeroVisual = dashboardMetrics.nextRace ? getRaceVisual(dashboardMetrics.nextRace) : null;
|
||||||
|
const dashboardHeroStyle: DashboardHeroStyle | undefined = dashboardHeroVisual
|
||||||
|
? { "--dashboard-hero-image": toCssUrl(dashboardHeroVisual.imageSrc) }
|
||||||
|
: undefined;
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return (
|
return (
|
||||||
@@ -157,7 +171,11 @@ export function DashboardPage(): JSX.Element {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<section className="page page--dashboard">
|
<section className="page page--dashboard">
|
||||||
<section className="dashboard-hero" aria-label="Обзор сезона">
|
<section
|
||||||
|
className={`dashboard-hero${dashboardHeroVisual ? " dashboard-hero--with-image" : ""}`}
|
||||||
|
style={dashboardHeroStyle}
|
||||||
|
aria-label="Обзор сезона"
|
||||||
|
>
|
||||||
<div className="dashboard-hero__content">
|
<div className="dashboard-hero__content">
|
||||||
<p className="dashboard-hero__eyebrow">Календарь сезона</p>
|
<p className="dashboard-hero__eyebrow">Календарь сезона</p>
|
||||||
<h1 className="dashboard-hero__title">Беговой штаб</h1>
|
<h1 className="dashboard-hero__title">Беговой штаб</h1>
|
||||||
|
|||||||
@@ -1355,6 +1355,13 @@ body {
|
|||||||
url("/images/runner-hero.jpg") center / cover;
|
url("/images/runner-hero.jpg") center / cover;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.dashboard-hero--with-image {
|
||||||
|
background:
|
||||||
|
linear-gradient(90deg, rgba(7, 25, 39, 0.94) 0%, rgba(7, 25, 39, 0.68) 48%, rgba(7, 25, 39, 0.2) 100%),
|
||||||
|
var(--dashboard-hero-image) center / cover,
|
||||||
|
url("/images/runner-hero.jpg") center / cover;
|
||||||
|
}
|
||||||
|
|
||||||
.dashboard-hero__content,
|
.dashboard-hero__content,
|
||||||
.dashboard-hero__panel {
|
.dashboard-hero__panel {
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|||||||
Reference in New Issue
Block a user