mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 08:30:05 +00:00
fix(atlas): clear the client gates of the globe Atlas
Client lint, checks and tests were red on the globe Atlas: - The views own the globe and sky refs and hand them into useAtlasGlobe, so reading its state while rendering no longer counts as reading refs. - Helpers that shared a file with components move to their own modules (badge tiers, medal label, Dawarich notes, hub tabs, period label). - The place search derives its loading state, the search resets its active row on input, and the two silenced hook dependencies are named. - placeLabels, the hover chip and the overview figures are split up. - Raw text sizes become type tiers, the badge unlock docks on --z-overlay. - The stats card test follows the GlobeStat props; baselines lowered to the counts the run reported.
This commit is contained in:
@@ -18,18 +18,10 @@ import { Tooltip } from '../../shared/Tooltip';
|
||||
import { FigureBadge } from '../../Tours/paddle/FigureBadge';
|
||||
import { TourDayRowPill } from '../../Tours/TourDayRowFacts';
|
||||
import { tourDayRowIcon } from '../../Tours/tourDayRowIcon';
|
||||
import { typeIcon, typeLabel, type Translate } from './tourActivityReading';
|
||||
import { periodYear, type ActivityPeriod, type ActivityType } from './tourActivityStatsModel';
|
||||
import { periodLabel, typeIcon, typeLabel } from './tourActivityReading';
|
||||
import { type ActivityType } from './tourActivityStatsModel';
|
||||
import type { TourActivityStats } from './useTourActivityStats';
|
||||
|
||||
/** What a period is called in the filter. */
|
||||
export function periodLabel(period: ActivityPeriod, t: Translate): string {
|
||||
if (period === 'all') return t('tours.stats.period.all');
|
||||
if (period === 'thisYear') return t('tours.stats.period.thisYear');
|
||||
if (period === 'last12') return t('tours.stats.period.last12');
|
||||
return String(periodYear(period));
|
||||
}
|
||||
|
||||
/** The period and type filters, as head band pills or quiet ones in a panel. */
|
||||
export function ActivityFilters({ stats, quiet = false }: { stats: TourActivityStats; quiet?: boolean }) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
@@ -4,7 +4,7 @@ import { useSettingsStore } from '../../../store/settingsStore';
|
||||
import type { DistanceUnit } from '../../../types';
|
||||
import { formatDistance, formatElevation } from '../../../utils/units';
|
||||
import { tourDayRowIcon } from '../../Tours/tourDayRowIcon';
|
||||
import { sumReading, type ActivityType } from './tourActivityStatsModel';
|
||||
import { periodYear, sumReading, type ActivityPeriod, type ActivityType } from './tourActivityStatsModel';
|
||||
|
||||
export type Translate = (key: string, params?: Record<string, unknown>) => string;
|
||||
|
||||
@@ -37,3 +37,11 @@ export function heightReading(sum: TourActivityTotals['ascentM'], unit: Distance
|
||||
export function partialHint(sum: TourActivityTotals['distanceKm'], t: Translate): string {
|
||||
return t('tours.scope.partialBody', { known: sum.known, of: sum.of });
|
||||
}
|
||||
|
||||
/** What a period is called in the filter. */
|
||||
export function periodLabel(period: ActivityPeriod, t: Translate): string {
|
||||
if (period === 'all') return t('tours.stats.period.all');
|
||||
if (period === 'thisYear') return t('tours.stats.period.thisYear');
|
||||
if (period === 'last12') return t('tours.stats.period.last12');
|
||||
return String(periodYear(period));
|
||||
}
|
||||
|
||||
@@ -85,18 +85,20 @@ const AtlasGlobe = forwardRef<AtlasGlobeHandle, AtlasGlobeProps>(function AtlasG
|
||||
};
|
||||
}, []);
|
||||
|
||||
const { dark, paint, paintKey } = props;
|
||||
useEffect(() => {
|
||||
engineRef.current?.setTheme(globeTheme(props.dark));
|
||||
}, [props.dark]);
|
||||
engineRef.current?.setTheme(globeTheme(dark));
|
||||
}, [dark]);
|
||||
|
||||
// paint changes with everything it reads; paintKey also with the regions that
|
||||
// arrived since, which paint reads from the engine.
|
||||
useEffect(() => {
|
||||
const e = engineRef.current;
|
||||
if (e && ready) {
|
||||
props.paint(e);
|
||||
if (e && ready && paintKey !== undefined) {
|
||||
paint(e);
|
||||
e.kick();
|
||||
}
|
||||
// paintKey stands for everything paint() reads.
|
||||
}, [props.paintKey, ready]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
}, [paint, paintKey, ready]);
|
||||
|
||||
useEffect(() => {
|
||||
engineRef.current?.setInsetBottom(props.insetBottom ?? 0);
|
||||
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
type LucideIcon,
|
||||
} from 'lucide-react';
|
||||
import React from 'react';
|
||||
import { TIERS } from './badgeTiers';
|
||||
|
||||
/**
|
||||
* A badge as a hexagonal glass medal: a tinted glass body, a ring in the tier's
|
||||
@@ -29,13 +30,6 @@ import React from 'react';
|
||||
* surfaces, so the colours are literal here.
|
||||
*/
|
||||
|
||||
export const TIERS: Record<BadgeTier, [string, string]> = {
|
||||
bronze: ['#f5b06b', '#a55a1e'], // theme-lint-disable: medal metal
|
||||
silver: ['#eef2f7', '#8a97ab'], // theme-lint-disable: medal metal
|
||||
gold: ['#fde68a', '#c98a0e'], // theme-lint-disable: medal metal
|
||||
aurora: ['#5eead4', '#a78bfa'], // theme-lint-disable: medal metal
|
||||
};
|
||||
|
||||
const HEX = '46,3 89,27 89,77 46,101 3,77 3,27';
|
||||
const INNER = '46,12 80,31 80,73 46,92 12,73 12,31';
|
||||
const INK = '#e0f2fe'; // theme-lint-disable: medal line art
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import React from 'react';
|
||||
import DawarichIcon from '../shared/DawarichIcon';
|
||||
|
||||
/** Dawarich's mark at an icon's size, round like the symbols beside it. */
|
||||
export default function DawarichMark({ size = 16 }: { size?: number }): React.ReactElement {
|
||||
return (
|
||||
<span className="flex flex-none overflow-hidden rounded-full" style={{ width: size + 2, height: size + 2 }}>
|
||||
<DawarichIcon size={size + 2} />
|
||||
</span>
|
||||
);
|
||||
}
|
||||
@@ -53,7 +53,7 @@ html:not(.dark) .ag-bar {
|
||||
|
||||
.atlas-globe-label {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
left: 0; /* rtl-lint-disable: placed by a measured x on the canvas, physical on purpose */
|
||||
top: 0;
|
||||
white-space: nowrap;
|
||||
font-weight: 500;
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import type { BadgeTier } from '@trek/shared';
|
||||
|
||||
/** The two tones of each tier's metal, light and deep; medal paint, not UI surfaces. */
|
||||
export const TIERS: Record<BadgeTier, [string, string]> = {
|
||||
bronze: ['#f5b06b', '#a55a1e'], // theme-lint-disable: medal metal
|
||||
silver: ['#eef2f7', '#8a97ab'], // theme-lint-disable: medal metal
|
||||
gold: ['#fde68a', '#c98a0e'], // theme-lint-disable: medal metal
|
||||
aurora: ['#5eead4', '#a78bfa'], // theme-lint-disable: medal metal
|
||||
};
|
||||
@@ -51,55 +51,9 @@ export function placeLabels(
|
||||
const minArea = minAreaFor(zoom);
|
||||
const regionA = engine.regionAlpha;
|
||||
|
||||
// From the region label zoom on, every country in view with regions names them,
|
||||
// and its own name gives way (Kansas, not "United States" above it). The
|
||||
// regions nearest the middle of the view come first, the country under the
|
||||
// middle ahead of all; the collision check below keeps it from being a wall.
|
||||
const regionsOn = zoom >= (width < NARROW_WIDTH ? REGION_LABEL_ZOOM_PHONE : REGION_LABEL_ZOOM_WIDE);
|
||||
const focus = regionsOn ? centreCountry(engine) : null;
|
||||
const named = new Set<string>();
|
||||
const cx = width / 2;
|
||||
const cy = height / 2;
|
||||
if (regionsOn) {
|
||||
for (const [a2, idx] of engine.regionIndex) {
|
||||
for (const f of idx.features) {
|
||||
if (!f.anchor) continue;
|
||||
const p = engine.project(f.anchor[0], f.anchor[1]);
|
||||
if (p.visible < 0.1 || p.x < 0 || p.x > width || p.y < 0 || p.y > height) continue;
|
||||
named.add(a2);
|
||||
const near = 1 - Math.min(1, Math.hypot(p.x - cx, p.y - cy) / Math.hypot(cx, cy));
|
||||
cands.push({
|
||||
key: `${a2}:${f.code ?? f.name}`,
|
||||
text: f.nameEn ?? f.name ?? '',
|
||||
x: p.x,
|
||||
y: p.y,
|
||||
rank: (a2 === focus ? 2e7 : 1e7) + near * 1e6,
|
||||
region: true,
|
||||
fade: regionA,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const c of m.countries) {
|
||||
if (!c.a2 || !c.anchor) continue;
|
||||
if (named.has(c.a2)) continue;
|
||||
// Countries the user has been to are named earlier than the rest.
|
||||
const mine = labelRegionsOf ? labelRegionsOf(c.a2) : false;
|
||||
if (c.area < minArea * (mine ? 0.3 : 1)) continue;
|
||||
const p = engine.project(c.anchor[0], c.anchor[1]);
|
||||
if (p.visible < 0.12 || p.x < -40 || p.x > width + 40 || p.y < -20 || p.y > height + 20) continue;
|
||||
const text = labelFor(c.a2);
|
||||
if (!text) continue;
|
||||
cands.push({
|
||||
key: c.a2,
|
||||
text,
|
||||
x: p.x,
|
||||
y: p.y,
|
||||
rank: c.area * (mine ? 4 : 1) * (1 - regionA * 0.7),
|
||||
region: false,
|
||||
fade: Math.min(1, p.visible * 4) * (1 - regionA * 0.55),
|
||||
});
|
||||
}
|
||||
const named = regionsOn ? regionCandidates(engine, cands) : new Set<string>();
|
||||
countryCandidates(engine, cands, named, minArea, regionA, labelFor, labelRegionsOf);
|
||||
cands.sort((a, b) => b.rank - a.rank);
|
||||
let regionCount = 0;
|
||||
|
||||
@@ -139,6 +93,73 @@ export function placeLabels(
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* From the region label zoom on, every country in view with regions names
|
||||
* them, and its own name gives way (Kansas, not "United States" above it).
|
||||
* The regions nearest the middle of the view come first, the country under the
|
||||
* middle ahead of all; the collision check keeps it from being a wall.
|
||||
* Returns the countries whose regions were named.
|
||||
*/
|
||||
function regionCandidates(engine: GlobeEngine, cands: Candidate[]): Set<string> {
|
||||
const { width, height } = engine.vp;
|
||||
const focus = centreCountry(engine);
|
||||
const named = new Set<string>();
|
||||
const cx = width / 2;
|
||||
const cy = height / 2;
|
||||
for (const [a2, idx] of engine.regionIndex) {
|
||||
for (const f of idx.features) {
|
||||
if (!f.anchor) continue;
|
||||
const p = engine.project(f.anchor[0], f.anchor[1]);
|
||||
if (p.visible < 0.1 || p.x < 0 || p.x > width || p.y < 0 || p.y > height) continue;
|
||||
named.add(a2);
|
||||
const near = 1 - Math.min(1, Math.hypot(p.x - cx, p.y - cy) / Math.hypot(cx, cy));
|
||||
cands.push({
|
||||
key: `${a2}:${f.code ?? f.name}`,
|
||||
text: f.nameEn ?? f.name ?? '',
|
||||
x: p.x,
|
||||
y: p.y,
|
||||
rank: (a2 === focus ? 2e7 : 1e7) + near * 1e6,
|
||||
region: true,
|
||||
fade: engine.regionAlpha,
|
||||
});
|
||||
}
|
||||
}
|
||||
return named;
|
||||
}
|
||||
|
||||
/** Country names, the large ones first; the user's own countries are named earlier than the rest. */
|
||||
function countryCandidates(
|
||||
engine: GlobeEngine,
|
||||
cands: Candidate[],
|
||||
named: Set<string>,
|
||||
minArea: number,
|
||||
regionA: number,
|
||||
labelFor: (a2: string) => string | null,
|
||||
labelRegionsOf?: (a2: string) => boolean
|
||||
): void {
|
||||
const m = engine.manifest;
|
||||
if (!m) return;
|
||||
const { width, height } = engine.vp;
|
||||
for (const c of m.countries) {
|
||||
if (!c.a2 || !c.anchor || named.has(c.a2)) continue;
|
||||
const mine = labelRegionsOf ? labelRegionsOf(c.a2) : false;
|
||||
if (c.area < minArea * (mine ? 0.3 : 1)) continue;
|
||||
const p = engine.project(c.anchor[0], c.anchor[1]);
|
||||
if (p.visible < 0.12 || p.x < -40 || p.x > width + 40 || p.y < -20 || p.y > height + 20) continue;
|
||||
const text = labelFor(c.a2);
|
||||
if (!text) continue;
|
||||
cands.push({
|
||||
key: c.a2,
|
||||
text,
|
||||
x: p.x,
|
||||
y: p.y,
|
||||
rank: c.area * (mine ? 4 : 1) * (1 - regionA * 0.7),
|
||||
region: false,
|
||||
fade: Math.min(1, p.visible * 4) * (1 - regionA * 0.55),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/** The country whose label anchor sits nearest the middle of the view. */
|
||||
function centreCountry(engine: GlobeEngine): string | null {
|
||||
const under = engine.focusCountry();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { DawarichAtlasSuggestions, DawarichBucketScan } from '@trek/shared';
|
||||
import { DAWARICH_BUCKET_MATCH_MIN_MINUTES, DAWARICH_BUCKET_MATCH_RADIUS_M } from '@trek/shared';
|
||||
import { useState } from 'react';
|
||||
import { useTranslation } from '../../i18n';
|
||||
import { DawarichOfflineError, dawarichRepo } from '../../repo/dawarichRepo';
|
||||
@@ -180,3 +181,25 @@ export function useDawarichAtlas({
|
||||
}
|
||||
|
||||
export type DawarichAtlasState = ReturnType<typeof useDawarichAtlas>;
|
||||
|
||||
/** What Dawarich offers for one question, built once for the desktop tab; the phone builds its own rows. */
|
||||
export function dawarichNotes(
|
||||
d: DawarichAtlasState,
|
||||
t: (key: string, params?: Record<string, string | number>) => string
|
||||
): string[] {
|
||||
if (d.tab === 'wishes') {
|
||||
return [
|
||||
d.scan && d.scan.skippedWithoutCoordinates > 0
|
||||
? t('dawarich.bucket.skipped', { count: d.scan.skippedWithoutCoordinates })
|
||||
: null,
|
||||
d.scan?.truncated ? t('dawarich.bucket.truncated') : null,
|
||||
t('dawarich.bucket.rule', { meters: DAWARICH_BUCKET_MATCH_RADIUS_M, count: DAWARICH_BUCKET_MATCH_MIN_MINUTES }),
|
||||
].filter((n): n is string => !!n);
|
||||
}
|
||||
return [
|
||||
d.countries && d.countries.unresolved.length > 0
|
||||
? t('dawarich.atlas.unresolved', { names: d.countries.unresolved.join(', ') })
|
||||
: null,
|
||||
d.countries ? t('dawarich.atlas.window') : null,
|
||||
].filter((n): n is string => !!n);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user