mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-29 16:10:07 +00:00
fix(atlas): share the wish form and tour figures, mark the people reads
- lint:dup: the add-a-wish form state and the tour figures of the hub were written twice, once per view; they live in useWishAddForm and tourHubFigures now, and both views read them. - lint:tx: AtlasPeopleService.profile only writes through the region cache refreshes of the Atlas reads it calls, each complete on its own, so it is marked @txStandalone.
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import type { TourActivityStatsResponse, TourActivitySummary } from '@trek/shared';
|
||||
import type { DistanceUnit } from '../../../types';
|
||||
import { distanceReading, heightReading } from './tourActivityReading';
|
||||
import { splitMeasure } from './tourActivityStatsModel';
|
||||
|
||||
/**
|
||||
* What the tours page of the Atlas hub shows above its lists, for the desktop
|
||||
* and the phone view alike: the headline distance (or the tour count when no
|
||||
* distance is known), the climbs, the types scaled to the longest, and the
|
||||
* tours left out of the sums.
|
||||
*/
|
||||
export function tourHubFigures(
|
||||
summary: TourActivitySummary,
|
||||
data: TourActivityStatsResponse | null,
|
||||
unit: DistanceUnit
|
||||
) {
|
||||
const totals = summary.totals;
|
||||
const distance = distanceReading(totals, unit);
|
||||
return {
|
||||
hero: distance ? splitMeasure(distance.text) : { value: String(totals.count), unit: '' },
|
||||
ascent: heightReading(totals.ascentM, unit),
|
||||
descent: heightReading(totals.descentM, unit),
|
||||
types: summary.types,
|
||||
maxKm: Math.max(1e-9, ...summary.types.map((x) => x.distanceKm.value ?? 0)),
|
||||
uncounted: data?.uncounted ?? { unassigned: 0, undated: 0 },
|
||||
};
|
||||
}
|
||||
@@ -7,14 +7,13 @@ import {
|
||||
} from '../../../../components/Atlas/tourActivity/tourActivityParts';
|
||||
import {
|
||||
distanceReading,
|
||||
heightReading,
|
||||
periodLabel,
|
||||
typeIcon,
|
||||
typeLabel,
|
||||
useDistanceUnit,
|
||||
} from '../../../../components/Atlas/tourActivity/tourActivityReading';
|
||||
import { TourActivityStatsDialog } from '../../../../components/Atlas/tourActivity/TourActivityStatsDialog';
|
||||
import { splitMeasure } from '../../../../components/Atlas/tourActivity/tourActivityStatsModel';
|
||||
import { tourHubFigures } from '../../../../components/Atlas/tourActivity/tourHubFigures';
|
||||
import { useTourActivityStats } from '../../../../components/Atlas/tourActivity/useTourActivityStats';
|
||||
import type { AtlasGlobeState } from '../../../../pages/atlas/useAtlasGlobe';
|
||||
import MChip from '../../../components/MChip';
|
||||
@@ -74,13 +73,7 @@ export default function MHubTours({ s }: { s: AtlasGlobeState }): React.ReactEle
|
||||
);
|
||||
}
|
||||
|
||||
const distance = distanceReading(totals, unit);
|
||||
const hero = distance ? splitMeasure(distance.text) : { value: String(totals.count), unit: '' };
|
||||
const ascent = heightReading(totals.ascentM, unit);
|
||||
const descent = heightReading(totals.descentM, unit);
|
||||
const types = summary.types;
|
||||
const maxKm = Math.max(1e-9, ...types.map((x) => x.distanceKm.value ?? 0));
|
||||
const uncounted = stats.data?.uncounted ?? { unassigned: 0, undated: 0 };
|
||||
const { hero, ascent, descent, types, maxKm, uncounted } = tourHubFigures(summary, stats.data, unit);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { getIntlLanguage } from '@trek/shared';
|
||||
import {
|
||||
CalendarCheck,
|
||||
CalendarClock,
|
||||
@@ -22,7 +21,7 @@ import CountryFlag from '../../../../components/shared/CountryFlag';
|
||||
import { splitWishes, visitedOn, whenLabeller, wishCountry } from '../../../../pages/atlas/atlasHubModel';
|
||||
import type { BucketItem } from '../../../../pages/atlas/atlasModel';
|
||||
import type { AtlasGlobeState } from '../../../../pages/atlas/useAtlasGlobe';
|
||||
import { useGlobePlaceSearch } from '../../../../pages/atlas/useGlobePlaceSearch';
|
||||
import { useWishAddForm } from '../../../../pages/atlas/useWishAddForm';
|
||||
import MIconBtn from '../../../components/MIconBtn';
|
||||
import MProgress from '../../../components/MProgress';
|
||||
import MSheet from '../../../components/MSheet';
|
||||
@@ -189,21 +188,8 @@ function WishRow({ s, item, when }: { s: AtlasGlobeState; item: BucketItem; when
|
||||
|
||||
/** Adding a wish on the phone: where, when and a note, as one sheet with the save at its foot. */
|
||||
function AddWishSheet({ s }: { s: AtlasGlobeState }): React.ReactElement {
|
||||
const b = s.bucketState;
|
||||
const lang = getIntlLanguage(s.language);
|
||||
const [query, setQuery] = React.useState('');
|
||||
const { placeHits, placesLoading } = useGlobePlaceSearch(query, s.placeLang);
|
||||
const picked = !!b.bucketForm.name;
|
||||
const thisYear = new Date().getFullYear();
|
||||
const year = b.bucketPoiYear;
|
||||
const month = b.bucketPoiMonth;
|
||||
const months = Array.from({ length: 12 }, (_, i) => new Date(2000, i).toLocaleString(lang, { month: 'short' }));
|
||||
const takeName = () => {
|
||||
const name = query.trim();
|
||||
if (!name) return;
|
||||
b.setBucketForm({ ...b.bucketForm, name, lat: '', lng: '', address: undefined });
|
||||
setQuery('');
|
||||
};
|
||||
const { b, query, setQuery, placeHits, placesLoading, picked, thisYear, year, month, months, takeName } =
|
||||
useWishAddForm(s);
|
||||
const label = (text: string) => (
|
||||
<div className="px-1 text-caption font-bold uppercase tracking-wide text-m-muted">{text}</div>
|
||||
);
|
||||
|
||||
@@ -8,13 +8,12 @@ import {
|
||||
} from '../../components/Atlas/tourActivity/tourActivityParts';
|
||||
import {
|
||||
distanceReading,
|
||||
heightReading,
|
||||
typeIcon,
|
||||
typeLabel,
|
||||
useDistanceUnit,
|
||||
} from '../../components/Atlas/tourActivity/tourActivityReading';
|
||||
import { TourActivityStatsDialog } from '../../components/Atlas/tourActivity/TourActivityStatsDialog';
|
||||
import { splitMeasure } from '../../components/Atlas/tourActivity/tourActivityStatsModel';
|
||||
import { tourHubFigures } from '../../components/Atlas/tourActivity/tourHubFigures';
|
||||
import { useTourActivityStats } from '../../components/Atlas/tourActivity/useTourActivityStats';
|
||||
import { fs } from '../../components/shared/DialogShell';
|
||||
import { InfoDot } from '../../components/Tours/tourParts';
|
||||
@@ -60,13 +59,7 @@ export default function AtlasGlobeTours({ s }: { s: AtlasGlobeState }): React.Re
|
||||
);
|
||||
}
|
||||
|
||||
const distance = distanceReading(totals, unit);
|
||||
const hero = distance ? splitMeasure(distance.text) : { value: String(totals.count), unit: '' };
|
||||
const ascent = heightReading(totals.ascentM, unit);
|
||||
const descent = heightReading(totals.descentM, unit);
|
||||
const types = summary.types;
|
||||
const maxKm = Math.max(1e-9, ...types.map((x) => x.distanceKm.value ?? 0));
|
||||
const uncounted = stats.data?.uncounted ?? { unassigned: 0, undated: 0 };
|
||||
const { hero, ascent, descent, types, maxKm, uncounted } = tourHubFigures(summary, stats.data, unit);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-5">
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import { getIntlLanguage } from '@trek/shared';
|
||||
import { ChevronLeft, ChevronRight, Loader2, MapPin, PenLine, Search, Sparkles, Star, X } from 'lucide-react';
|
||||
import React from 'react';
|
||||
import { fs } from '../../components/shared/DialogShell';
|
||||
import { HUB_CARD, HUB_FIELD, HUB_INSET, HubGhost, HubGlow, HubIconButton, HubPrimary } from './atlasHubKit';
|
||||
import type { AtlasGlobeState } from './useAtlasGlobe';
|
||||
import { useGlobePlaceSearch } from './useGlobePlaceSearch';
|
||||
import { useWishAddForm } from './useWishAddForm';
|
||||
|
||||
function StepLabel({ n, children }: { n: number; children: React.ReactNode }): React.ReactElement {
|
||||
return (
|
||||
@@ -26,22 +25,8 @@ function StepLabel({ n, children }: { n: number; children: React.ReactNode }): R
|
||||
* note survives picking a place; cancel clears everything.
|
||||
*/
|
||||
export default function AtlasGlobeWishAdd({ s }: { s: AtlasGlobeState }): React.ReactElement {
|
||||
const b = s.bucketState;
|
||||
const lang = getIntlLanguage(s.language);
|
||||
const [query, setQuery] = React.useState('');
|
||||
const { placeHits, placesLoading } = useGlobePlaceSearch(query, s.placeLang);
|
||||
const picked = !!b.bucketForm.name;
|
||||
const thisYear = new Date().getFullYear();
|
||||
const year = b.bucketPoiYear;
|
||||
const month = b.bucketPoiMonth;
|
||||
const months = Array.from({ length: 12 }, (_, i) => new Date(2000, i).toLocaleString(lang, { month: 'short' }));
|
||||
|
||||
const takeName = () => {
|
||||
const name = query.trim();
|
||||
if (!name) return;
|
||||
b.setBucketForm({ ...b.bucketForm, name, lat: '', lng: '', address: undefined });
|
||||
setQuery('');
|
||||
};
|
||||
const { b, query, setQuery, placeHits, placesLoading, picked, thisYear, year, month, months, takeName } =
|
||||
useWishAddForm(s);
|
||||
|
||||
return (
|
||||
<div className={`${HUB_CARD} relative flex flex-col gap-5 overflow-hidden p-5`}>
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { getIntlLanguage } from '@trek/shared';
|
||||
import { useState } from 'react';
|
||||
import type { AtlasGlobeState } from './useAtlasGlobe';
|
||||
import { useGlobePlaceSearch } from './useGlobePlaceSearch';
|
||||
|
||||
/**
|
||||
* The add-a-wish form of the Atlas hub, for the desktop card and the phone
|
||||
* sheet alike: the place search, the year and month picked, the month names in
|
||||
* the reader's language, and taking what was typed as a plain name.
|
||||
*/
|
||||
export function useWishAddForm(s: AtlasGlobeState) {
|
||||
const b = s.bucketState;
|
||||
const lang = getIntlLanguage(s.language);
|
||||
const [query, setQuery] = useState('');
|
||||
const { placeHits, placesLoading } = useGlobePlaceSearch(query, s.placeLang);
|
||||
const months = Array.from({ length: 12 }, (_, i) => new Date(2000, i).toLocaleString(lang, { month: 'short' }));
|
||||
|
||||
const takeName = () => {
|
||||
const name = query.trim();
|
||||
if (!name) return;
|
||||
b.setBucketForm({ ...b.bucketForm, name, lat: '', lng: '', address: undefined });
|
||||
setQuery('');
|
||||
};
|
||||
|
||||
return {
|
||||
b,
|
||||
query,
|
||||
setQuery,
|
||||
placeHits,
|
||||
placesLoading,
|
||||
picked: !!b.bucketForm.name,
|
||||
thisYear: new Date().getFullYear(),
|
||||
year: b.bucketPoiYear,
|
||||
month: b.bucketPoiMonth,
|
||||
months,
|
||||
takeName,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user