fix(frontend): prevent calendar loading layout shift #29

Merged
admin merged 1 commits from fix/calendar-loading-layout-shift into main 2026-04-27 11:03:47 +00:00
2 changed files with 47 additions and 14 deletions

View File

@@ -228,6 +228,25 @@ export function RacesPage(): JSX.Element {
}), }),
[races], [races],
); );
const statusMessage = useMemo(() => {
if (errorMessage && !isLoading) {
return errorMessage;
}
if (isLoading) {
return "Загружаем данные...";
}
if (viewMode === "calendar" && monthFilter === "") {
return "Выберите месяц, чтобы увидеть его крупным планом.";
}
return "";
}, [errorMessage, isLoading, monthFilter, viewMode]);
const statusClassName = [
"races-status__message",
!statusMessage ? "races-status__message--empty" : "",
errorMessage && !isLoading ? "races-status__message--error" : "",
]
.filter(Boolean)
.join(" ");
if (errorMessage && races.length === 0 && !isLoading) { if (errorMessage && races.length === 0 && !isLoading) {
return ( return (
@@ -301,21 +320,16 @@ export function RacesPage(): JSX.Element {
</div> </div>
</section> </section>
{errorMessage && !isLoading ? ( <div className="races-status" aria-live="polite">
<p className="page__subtitle page__subtitle--error" role="alert" style={{ marginTop: "var(--space-4)" }}> <p
{errorMessage} className={statusClassName}
role={errorMessage && !isLoading ? "alert" : undefined}
aria-busy={isLoading || undefined}
aria-hidden={!statusMessage || undefined}
>
{statusMessage || "\u00a0"}
</p> </p>
) : null} </div>
{viewMode === "calendar" && monthFilter === "" ? (
<p className="page__subtitle races-cal__filter-hint">Выберите месяц, чтобы увидеть его крупным планом.</p>
) : null}
{isLoading ? (
<p className="page__subtitle" aria-busy="true">
Загружаем данные...
</p>
) : null}
{viewMode === "list" ? ( {viewMode === "list" ? (
<div className="race-lists"> <div className="race-lists">

View File

@@ -967,6 +967,25 @@ a {
margin-top: var(--space-6); margin-top: var(--space-6);
} }
.races-status {
min-height: calc(var(--line-height-base) * var(--font-size-caption));
margin-top: var(--space-4);
}
.races-status__message {
margin: 0;
color: var(--color-text-muted);
font-size: var(--font-size-caption);
}
.races-status__message--empty {
visibility: hidden;
}
.races-status__message--error {
color: var(--color-danger);
}
.races-cal__filter-hint { .races-cal__filter-hint {
margin-top: var(--space-3); margin-top: var(--space-3);
color: var(--color-text-muted); color: var(--color-text-muted);