mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-05 10:24:05 +00:00
feat(atlas): the globe Atlas with its hub, on desktop and phone
The Atlas page is now the globe. Everything the classic map offered carries over: visited countries and regions, planned countries, the wishlist with places and target dates, Dawarich, tours, plugin layers and the place search. New: - regions on the globe, with how much of a country has been seen (#2675, #316, #487) - flight arcs (#1369, #2642) - a hub with statistics, badges, wishlist, Dawarich, tours and travellers - an instance ranking, traveller profiles and a compare overlay - a timeline that plays back how the map grew - phone layouts of their own: sheets, chips and swipe actions The classic Leaflet Atlas and its phone screen are removed.
This commit is contained in:
@@ -3,7 +3,7 @@ import { useTranslation } from '../../../i18n'
|
||||
import { useIsDark } from '../../../hooks/useIsDark'
|
||||
import {
|
||||
Puzzle, ListChecks, Wallet, FileText, CalendarDays, Globe, Briefcase, Image, Terminal, Link2, Compass, BookOpen,
|
||||
Sparkles, Luggage, Plane, Bookmark, Users, Mountain, CarFront, Radar,
|
||||
Sparkles, Luggage, Plane, Bookmark, Users, Mountain, CarFront, Radar, Trophy,
|
||||
} from 'lucide-react'
|
||||
import DawarichIcon from '../../../components/shared/DawarichIcon'
|
||||
import AirTrailIcon from '../../../components/shared/AirTrailIcon'
|
||||
@@ -80,6 +80,8 @@ export default function MAdminAddonManager({ bagTrackingEnabled, onToggleBagTrac
|
||||
wandererOffered,
|
||||
toggleToursWanderer,
|
||||
mapSwitches,
|
||||
atlasCompare,
|
||||
toggleAtlasCompare,
|
||||
} = useAddonManager()
|
||||
|
||||
if (loading) {
|
||||
@@ -125,6 +127,15 @@ export default function MAdminAddonManager({ bagTrackingEnabled, onToggleBagTrac
|
||||
onToggle={onToggleBagTracking}
|
||||
/>
|
||||
)}
|
||||
{addon.id === 'atlas' && addon.enabled && (
|
||||
<MSubRow
|
||||
icon={Trophy}
|
||||
title={t('admin.atlasCompare.title')}
|
||||
subtitle={t('admin.atlasCompare.subtitle')}
|
||||
enabled={atlasCompare}
|
||||
onToggle={() => void toggleAtlasCompare()}
|
||||
/>
|
||||
)}
|
||||
{addon.id === 'documents' && addon.enabled && <MProviderShelf options={documentProviderOptions} />}
|
||||
{addon.id === 'tours' && addon.enabled && (
|
||||
<>
|
||||
|
||||
@@ -1,266 +1,6 @@
|
||||
import { useEffect, useMemo, useRef, useState } from 'react'
|
||||
import { useSearchParams } from 'react-router'
|
||||
import { CalendarClock, X } from 'lucide-react'
|
||||
import { useAtlas } from '../../../pages/atlas/useAtlas'
|
||||
import MIconBtn from '../../components/MIconBtn'
|
||||
import MSheet from '../../components/MSheet'
|
||||
import MChip from '../../components/MChip'
|
||||
import MAtlasStatsCard from './MAtlasStatsCard'
|
||||
import MAtlasSearch from './MAtlasSearch'
|
||||
import MAtlasCountryPopup from './MAtlasCountryPopup'
|
||||
import MAtlasBucketSheet from './MAtlasBucketSheet'
|
||||
import DawarichIcon from '../../../components/shared/DawarichIcon'
|
||||
import DawarichAtlasDialog from '../../../components/Dawarich/DawarichAtlasDialog'
|
||||
import { useAddonStore } from '../../../store/addonStore'
|
||||
import { countryStatus } from '../../../pages/atlas/atlasModel'
|
||||
import AtlasCountryPlaces from '../../../components/Atlas/AtlasCountryPlaces'
|
||||
import MSkeleton from '../../components/MSkeleton'
|
||||
import MAtlasGlobe from './MAtlasGlobe'
|
||||
|
||||
/** The atlas header's buttons: one shape, equal widths, the phone shell's glass. */
|
||||
const HEADER_BUTTON = 'flex h-[38px] min-w-0 flex-1 items-center justify-center gap-2 rounded-full border px-3 text-[0.78125rem] font-bold transition-transform active:scale-[.97]'
|
||||
const HEADER_IDLE = 'border-[color:var(--m-gbr)] bg-[color:var(--m-glass)] text-m-ink shadow-[0_5px_12px_-8px_rgba(0,0,0,.18)] backdrop-blur-[24px] backdrop-saturate-[1.7]'
|
||||
|
||||
const removeBtnCls = 'mt-4 w-full rounded-full bg-[rgba(214,39,59,.12)] py-[11px] text-center text-[0.8125rem] font-bold text-[color:var(--m-st-danger)]' // theme-lint-disable — fixed status-danger tint
|
||||
|
||||
/**
|
||||
* Mobile atlas screen: the interactive world map fills the viewport, the
|
||||
* five-column stats card floats above the bottom nav and the search overlay
|
||||
* flies the map to a country. All map/data logic comes from the shared
|
||||
* useAtlas hook — this file is presentation and wiring only.
|
||||
*/
|
||||
/** The phone Atlas: the globe, its hub sheet and its dialogs. */
|
||||
export default function MAtlas() {
|
||||
const rootRef = useRef<HTMLDivElement>(null)
|
||||
const headerRef = useRef<HTMLDivElement>(null)
|
||||
// The map runs under the rail (m-bleed) and the header: the camera keeps clear
|
||||
// of both. The rail's share is the root's own negative margin, resolved by the
|
||||
// browser; the header's is how far down it reaches.
|
||||
const atlas = useAtlas({
|
||||
chromeInsets: () => {
|
||||
const root = rootRef.current
|
||||
if (!root) return { top: 0, start: 0 }
|
||||
const start = Math.max(0, -parseFloat(getComputedStyle(root).marginInlineStart) || 0)
|
||||
const header = headerRef.current?.getBoundingClientRect()
|
||||
const top = header ? Math.max(0, header.bottom - root.getBoundingClientRect().top) : 0
|
||||
return { top, start }
|
||||
},
|
||||
})
|
||||
const {
|
||||
t,
|
||||
navigate,
|
||||
resolveName,
|
||||
loading,
|
||||
mapRef,
|
||||
regionTooltipRef,
|
||||
stats,
|
||||
countries,
|
||||
visitedCountries,
|
||||
showPlanned,
|
||||
togglePlanned,
|
||||
bucketList,
|
||||
selectedCountry,
|
||||
countryDetail,
|
||||
handleUnmarkCountry,
|
||||
select_country_from_search,
|
||||
atlas_country_options,
|
||||
} = atlas
|
||||
const plannedCount = stats.totalCountriesPlanned || 0
|
||||
const [searchOpen, setSearchOpen] = useState(false)
|
||||
const [bucketOpen, setBucketOpen] = useState(false)
|
||||
const [dawarichOpen, setDawarichOpen] = useState(false)
|
||||
const dawarichEnabled = useAddonStore(state => state.isEnabled)('dawarich')
|
||||
const [detailOpen, setDetailOpen] = useState(false)
|
||||
|
||||
// The dock FAB is the search button on this screen (demo Z. 1099) and hands
|
||||
// off via ?search=1, mirroring the ?create= contract of the other pages.
|
||||
const [searchParams, setSearchParams] = useSearchParams()
|
||||
useEffect(() => {
|
||||
if (searchParams.get('search') == null) return
|
||||
const next = new URLSearchParams(searchParams)
|
||||
next.delete('search')
|
||||
setSearchParams(next, { replace: true })
|
||||
setSearchOpen(true)
|
||||
}, [searchParams, setSearchParams])
|
||||
|
||||
// A search fly-to on a visited country loads its detail — surface it as a sheet.
|
||||
useEffect(() => {
|
||||
if (selectedCountry && countryDetail) setDetailOpen(true)
|
||||
}, [selectedCountry, countryDetail])
|
||||
|
||||
// Suggestions for the empty search field: recently visited countries first,
|
||||
// then countries already on the bucket list.
|
||||
const suggestions = useMemo(() => {
|
||||
const seen = new Set<string>()
|
||||
const list: { code: string; label: string }[] = []
|
||||
// Visited first, planned after — this list answers "where have I been", so a country
|
||||
// you only booked a flight to shouldn't outrank one you actually saw.
|
||||
const visited = [...countries].sort((a, b) => {
|
||||
const rank = (c: typeof a) => (countryStatus(c) === 'visited' ? 0 : 1)
|
||||
return rank(a) - rank(b) || (b.lastVisit || '').localeCompare(a.lastVisit || '')
|
||||
})
|
||||
for (const c of visited) {
|
||||
if (seen.has(c.code)) continue
|
||||
seen.add(c.code)
|
||||
list.push({ code: c.code, label: resolveName(c.code) })
|
||||
}
|
||||
for (const item of bucketList) {
|
||||
const code = item.country_code
|
||||
if (!code || code.length !== 2 || seen.has(code)) continue
|
||||
seen.add(code)
|
||||
list.push({ code, label: resolveName(code) })
|
||||
}
|
||||
return list.slice(0, 5)
|
||||
}, [countries, bucketList, resolveName])
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="relative h-dvh">
|
||||
<MSkeleton variant="map" className="absolute inset-0" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
// h-dvh, not h-full: the shell stopped providing a definite height (#1809)
|
||||
// and a map on a percentage of an auto-height parent collapses to zero.
|
||||
<div ref={rootRef} className="m-bleed relative h-dvh overflow-hidden">
|
||||
<div ref={mapRef} className="absolute inset-0 z-[1] bg-[color:var(--m-mapb)] [&_.leaflet-control-zoom]:hidden" />
|
||||
{/* Region hover tooltip — positioned imperatively by useAtlas. */}
|
||||
<div
|
||||
ref={regionTooltipRef}
|
||||
style={{ display: 'none' }}
|
||||
className="pointer-events-none fixed z-[80] min-w-[120px] rounded-[10px] border border-[color:var(--m-shbr)] bg-[color:var(--m-sheetop)] px-[14px] py-[10px] text-[0.75rem] text-m-ink shadow-[0_4px_16px_rgba(0,0,0,.18)]"
|
||||
/>
|
||||
|
||||
{/* Full-width bucket-list button. The bottom nav makes a back button
|
||||
redundant on this main-nav screen, so the header spans the width. */}
|
||||
<div ref={headerRef} className="m-bar-x absolute top-[var(--m-safe-top,12px)] z-[5] flex items-center gap-2 wide:mx-auto wide:max-w-[720px]">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setBucketOpen(true)}
|
||||
className={`${HEADER_BUTTON} ${HEADER_IDLE}`}
|
||||
>
|
||||
{t('atlas.bucketTab')}
|
||||
</button>
|
||||
{/* Dawarich answers two questions about this map, so it opens from the
|
||||
map — not from inside the wishlist sheet, where it was one card deep
|
||||
and looked like part of the list it is only asking about. Renders
|
||||
nothing when the addon is off. */}
|
||||
{dawarichEnabled && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setDawarichOpen(true)}
|
||||
aria-label={t('dawarich.title')}
|
||||
className={`${HEADER_BUTTON} ${HEADER_IDLE}`}
|
||||
>
|
||||
<span className="flex h-[22px] w-[22px] flex-none overflow-hidden rounded-full">
|
||||
<DawarichIcon size={22} />
|
||||
</span>
|
||||
<span className="truncate">{t('dawarich.title')}</span>
|
||||
</button>
|
||||
)}
|
||||
{/* Only worth the space once there is something planned to reveal. A
|
||||
button of the same shape as its neighbours, filled while the planned
|
||||
countries show, rather than a label with a switch in a pill of its own. */}
|
||||
{plannedCount > 0 && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => togglePlanned()}
|
||||
aria-pressed={showPlanned}
|
||||
aria-label={t('atlas.showPlanned')}
|
||||
className={`${HEADER_BUTTON} ${showPlanned ? 'border-transparent bg-m-act text-m-actfg' : HEADER_IDLE}`}
|
||||
>
|
||||
<CalendarClock size={15} strokeWidth={2.2} className="flex-none" aria-hidden="true" />
|
||||
<span className="truncate">{t('atlas.planned')}</span>
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{dawarichOpen && (
|
||||
<DawarichAtlasDialog
|
||||
isOpen
|
||||
onClose={() => setDawarichOpen(false)}
|
||||
onChanged={atlas.reloadAfterDawarich}
|
||||
/>
|
||||
)}
|
||||
|
||||
<MAtlasStatsCard stats={stats} />
|
||||
|
||||
<MAtlasSearch
|
||||
open={searchOpen}
|
||||
onClose={() => setSearchOpen(false)}
|
||||
options={atlas_country_options}
|
||||
suggestions={suggestions}
|
||||
isVisited={(code) => visitedCountries.some((c) => c.code === code)}
|
||||
isPlanned={(code) => countries.some((c) => c.code === code && countryStatus(c) !== 'visited')}
|
||||
isOnBucketList={(code) => bucketList.some((b) => b.country_code === code)}
|
||||
onSelect={(code) => {
|
||||
setSearchOpen(false)
|
||||
select_country_from_search(code)
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* Country detail sheet (visited country with trips/places). */}
|
||||
<MSheet
|
||||
open={detailOpen}
|
||||
onClose={() => setDetailOpen(false)}
|
||||
variant="card"
|
||||
ariaLabel={selectedCountry ? resolveName(selectedCountry) : undefined}
|
||||
>
|
||||
{selectedCountry && countryDetail && (
|
||||
<div className="p-5">
|
||||
<div className="flex items-center gap-3">
|
||||
<img
|
||||
src={`https://flagcdn.com/w80/${selectedCountry.toLowerCase()}.png`}
|
||||
alt=""
|
||||
className="h-[30px] w-[42px] flex-none rounded-[6px] object-cover shadow-[0_1px_3px_rgba(0,0,0,.25)]"
|
||||
/>
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="truncate text-[1.0625rem] font-extrabold text-m-ink">{resolveName(selectedCountry)}</div>
|
||||
<div className="mt-[4px] flex flex-wrap gap-1">
|
||||
{[[countryDetail.places.length, t('atlas.places', { count: countryDetail.places.length })], [countryDetail.trips.length, t('atlas.trips', { count: countryDetail.trips.length })]].map(([n, label]) => (
|
||||
<span key={label} className="rounded-full bg-[color:var(--m-ic)] px-2 py-[1px] font-geist text-[0.625rem] font-bold tabular-nums text-m-muted">
|
||||
{n} {label}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
<MIconBtn variant="neutral" size={34} onClick={() => setDetailOpen(false)} ariaLabel={t('common.close')}>
|
||||
<X size={16} strokeWidth={2.2} />
|
||||
</MIconBtn>
|
||||
</div>
|
||||
{countryDetail.trips.length > 0 && (
|
||||
<div className="mt-4 flex flex-wrap gap-[6px]">
|
||||
{countryDetail.trips.slice(0, 6).map((trip) => (
|
||||
<MChip key={trip.id} onClick={() => navigate(`/trips/${trip.id}`)}>
|
||||
{trip.title}
|
||||
</MChip>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{/* Every place counted for the country, by trip (#2174). */}
|
||||
{countryDetail.places.length > 0 && (
|
||||
<div className="mt-4 max-h-[46vh] overflow-y-auto">
|
||||
<AtlasCountryPlaces variant="mobile" detail={countryDetail} onOpenTrip={id => navigate(`/trips/${id}`)} />
|
||||
</div>
|
||||
)}
|
||||
{countryDetail.manually_marked && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setDetailOpen(false)
|
||||
handleUnmarkCountry(selectedCountry)
|
||||
}}
|
||||
className={removeBtnCls}
|
||||
>
|
||||
{t('atlas.unmark')}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</MSheet>
|
||||
|
||||
<MAtlasBucketSheet atlas={atlas} open={bucketOpen} onClose={() => setBucketOpen(false)} />
|
||||
<MAtlasCountryPopup atlas={atlas} />
|
||||
</div>
|
||||
)
|
||||
return <MAtlasGlobe />
|
||||
}
|
||||
|
||||
@@ -1,304 +0,0 @@
|
||||
import { useState } from 'react'
|
||||
import { Calendar, ChevronDown, ChevronLeft, ChevronRight, MapPin, Plus, Search, Star, Trash2, X } from 'lucide-react'
|
||||
import MSheet from '../../components/MSheet'
|
||||
import MIconBtn from '../../components/MIconBtn'
|
||||
import { A2_TO_A3 } from '../../../pages/atlas/atlasModel'
|
||||
import type { BucketItem } from '../../../pages/atlas/atlasModel'
|
||||
import type { AtlasController } from './atlasController'
|
||||
import { getIntlLanguage } from '@trek/shared'
|
||||
import { TileHeader } from '../trip/sheets/MTripSheetUi'
|
||||
|
||||
interface MAtlasBucketSheetProps {
|
||||
atlas: AtlasController
|
||||
open: boolean
|
||||
onClose: () => void
|
||||
}
|
||||
|
||||
const inputCls =
|
||||
'w-full rounded-[14px] border border-[color:var(--m-inbr)] bg-[color:var(--m-inner)] px-[14px] py-[11px] text-[0.84375rem] font-medium text-m-ink outline-none placeholder:text-m-faint'
|
||||
|
||||
function itemCountryA2(item: BucketItem): string | null {
|
||||
const code = item.country_code
|
||||
if (!code) return null
|
||||
if (code.length === 2) return code
|
||||
return Object.entries(A2_TO_A3).find(([, v]) => v === code)?.[0] ?? null
|
||||
}
|
||||
|
||||
/**
|
||||
* Bucket-list sheet, entered via the chip on the stats card. Lists every
|
||||
* bucket item with country, target month, coordinates and notes, and carries
|
||||
* the full add flow (POI search or free name, notes, target month).
|
||||
*/
|
||||
export default function MAtlasBucketSheet({ atlas, open, onClose }: MAtlasBucketSheetProps) {
|
||||
const {
|
||||
t,
|
||||
language,
|
||||
resolveName,
|
||||
bucketList,
|
||||
showBucketAdd,
|
||||
setShowBucketAdd,
|
||||
bucketForm,
|
||||
setBucketForm,
|
||||
bucketSearch,
|
||||
setBucketSearch,
|
||||
bucketSearchResults,
|
||||
setBucketSearchResults,
|
||||
bucketSearching,
|
||||
handleBucketPoiSearch,
|
||||
handleAddBucketItem,
|
||||
handleDeleteBucketItem,
|
||||
} = atlas
|
||||
|
||||
const resetForm = (): void => {
|
||||
setShowBucketAdd(false)
|
||||
setBucketForm({ name: '', notes: '', lat: '', lng: '', target_date: '' })
|
||||
setBucketSearch('')
|
||||
setBucketSearchResults([])
|
||||
}
|
||||
|
||||
const close = (): void => {
|
||||
resetForm()
|
||||
onClose()
|
||||
}
|
||||
|
||||
// Own POI pick instead of the hook's handleSelectBucketPoi: keeps the notes
|
||||
// and target month the user may already have typed into the form.
|
||||
const pickPoi = (result: { name?: string; lat?: number; lng?: number }): void => {
|
||||
setBucketForm({ ...bucketForm, name: result.name || bucketSearch, lat: String(result.lat ?? ''), lng: String(result.lng ?? '') })
|
||||
setBucketSearchResults([])
|
||||
setBucketSearch('')
|
||||
}
|
||||
|
||||
const fmtTarget = (targetDate: string): string => {
|
||||
const [y, m] = targetDate.split('-')
|
||||
return m ? new Date(Number(y), Number(m) - 1).toLocaleDateString(getIntlLanguage(language), { month: 'short', year: 'numeric' }) : y
|
||||
}
|
||||
|
||||
const itemSub = (item: BucketItem): string => {
|
||||
const a2 = itemCountryA2(item)
|
||||
return [
|
||||
a2 ? resolveName(a2) : null,
|
||||
item.target_date ? fmtTarget(item.target_date) : null,
|
||||
item.lat != null && item.lng != null ? `${item.lat.toFixed(2)}, ${item.lng.toFixed(2)}` : null,
|
||||
item.notes || null,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(' · ')
|
||||
}
|
||||
|
||||
return (
|
||||
<MSheet open={open} onClose={close} variant="bottom" material="glass" ariaLabel={t('atlas.bucketTab')}>
|
||||
<div className="flex min-h-0 flex-col px-[18px] pb-4 pt-4">
|
||||
<div className="mb-3">
|
||||
<TileHeader
|
||||
icon={<Star size={19} strokeWidth={1.8} className="text-[color:var(--m-st-pending)]" />}
|
||||
title={t('atlas.bucketTab')}
|
||||
sub={bucketList.length > 0 ? String(bucketList.length) : undefined}
|
||||
onClose={close}
|
||||
closeLabel={t('common.close')}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="min-h-0 flex-1 space-y-2 overflow-y-auto">
|
||||
{bucketList.length === 0 && !showBucketAdd && (
|
||||
<div className="px-4 py-8 text-center">
|
||||
<div className="text-[0.84375rem] font-semibold text-m-muted">{t('atlas.bucketEmpty')}</div>
|
||||
<div className="mt-1 font-geist text-[0.6875rem] text-m-faint">{t('atlas.bucketEmptyHint')}</div>
|
||||
</div>
|
||||
)}
|
||||
{bucketList.map((item) => {
|
||||
const a2 = itemCountryA2(item)
|
||||
const sub = itemSub(item)
|
||||
return (
|
||||
<div key={item.id} className="flex items-center gap-3 rounded-[18px] bg-[color:var(--m-ic)] px-[14px] py-[11px]">
|
||||
{a2 ? (
|
||||
<img
|
||||
src={`https://flagcdn.com/w40/${a2.toLowerCase()}.png`}
|
||||
alt=""
|
||||
className="h-[17px] w-6 flex-none rounded-[3px] object-cover shadow-[0_1px_3px_rgba(0,0,0,.25)]"
|
||||
/>
|
||||
) : (
|
||||
<Star size={16} strokeWidth={2.2} className="flex-none text-[color:var(--m-st-pending)]" />
|
||||
)}
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="truncate text-[0.84375rem] font-semibold text-m-ink">{item.name}</div>
|
||||
{sub && <div className="mt-[1px] truncate font-geist text-[0.6875rem] text-m-muted">{sub}</div>}
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => handleDeleteBucketItem(item.id)}
|
||||
aria-label={t('atlas.unmark')}
|
||||
className="flex h-[30px] w-[30px] flex-none items-center justify-center rounded-full text-m-faint active:bg-[color:var(--m-ic)]"
|
||||
>
|
||||
<Trash2 size={15} strokeWidth={2} />
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
|
||||
{showBucketAdd ? (
|
||||
<div className="space-y-2 pt-3">
|
||||
<div className="relative">
|
||||
<div className="flex gap-2">
|
||||
<input
|
||||
autoFocus
|
||||
value={bucketForm.name || bucketSearch}
|
||||
onChange={(e) => {
|
||||
const v = e.target.value
|
||||
if (bucketForm.name) setBucketForm({ ...bucketForm, name: v })
|
||||
else setBucketSearch(v)
|
||||
}}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key !== 'Enter') return
|
||||
if (bucketForm.name) void handleAddBucketItem()
|
||||
else void handleBucketPoiSearch()
|
||||
}}
|
||||
placeholder={t('atlas.bucketNamePlaceholder')}
|
||||
className={`${inputCls} min-w-0 flex-1`}
|
||||
/>
|
||||
{bucketForm.name ? (
|
||||
<MIconBtn
|
||||
variant="neutral"
|
||||
size={40}
|
||||
onClick={() => {
|
||||
setBucketForm({ ...bucketForm, name: '', lat: '', lng: '' })
|
||||
setBucketSearch('')
|
||||
}}
|
||||
ariaLabel={t('common.cancel')}
|
||||
>
|
||||
<X size={15} strokeWidth={2.2} />
|
||||
</MIconBtn>
|
||||
) : (
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleBucketPoiSearch}
|
||||
disabled={bucketSearching}
|
||||
aria-label={t('common.search')}
|
||||
className="flex h-10 w-10 flex-none items-center justify-center rounded-[14px] bg-m-act text-m-actfg disabled:opacity-50"
|
||||
>
|
||||
<Search size={16} strokeWidth={2.2} />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
{bucketSearchResults.length > 0 && (
|
||||
<div className="absolute bottom-full inset-x-0 z-10 mb-2 max-h-40 divide-y divide-[color:var(--m-rowbr)] overflow-y-auto rounded-[16px] border border-[color:var(--m-shbr)] bg-[color:var(--m-sheetop)] shadow-[0_12px_30px_-14px_rgba(0,0,0,.4)]">
|
||||
{bucketSearchResults.slice(0, 6).map((result, i) => (
|
||||
<button key={i} type="button" onClick={() => pickPoi(result)} className="flex w-full flex-col px-[14px] py-[9px] text-start active:bg-[color:var(--m-ic)]">
|
||||
<span className="text-[0.8125rem] font-semibold text-m-ink">{result.name}</span>
|
||||
{result.address && <span className="font-geist text-[0.625rem] text-m-faint">{result.address}</span>}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{bucketForm.lat && bucketForm.lng && (
|
||||
<div className="flex items-center gap-1 px-1 font-geist text-[0.625rem] text-m-faint">
|
||||
<MapPin size={10} strokeWidth={2.2} />
|
||||
{Number(bucketForm.lat).toFixed(4)}, {Number(bucketForm.lng).toFixed(4)}
|
||||
</div>
|
||||
)}
|
||||
<input
|
||||
value={bucketForm.notes}
|
||||
onChange={(e) => setBucketForm({ ...bucketForm, notes: e.target.value })}
|
||||
placeholder={t('atlas.bucketNotesPlaceholder')}
|
||||
className={inputCls}
|
||||
/>
|
||||
<MMonthYearField
|
||||
value={bucketForm.target_date}
|
||||
onChange={(v) => setBucketForm({ ...bucketForm, target_date: v })}
|
||||
placeholder={t('atlas.bucketWhen')}
|
||||
language={language}
|
||||
t={t}
|
||||
/>
|
||||
<div className="flex gap-2 pt-1">
|
||||
<button type="button" onClick={resetForm} className="flex-1 rounded-full bg-[color:var(--m-ic)] py-[11px] text-[0.8125rem] font-bold text-m-ink">
|
||||
{t('common.cancel')}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleAddBucketItem}
|
||||
disabled={!bucketForm.name.trim()}
|
||||
className="flex-1 rounded-full bg-m-act py-[11px] text-[0.8125rem] font-bold text-m-actfg disabled:opacity-50"
|
||||
>
|
||||
{t('common.add')}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setShowBucketAdd(true)}
|
||||
className="mt-3 flex w-full flex-none items-center justify-center gap-[6px] rounded-full border border-dashed border-[color:var(--m-rowbr)] py-[10px] font-geist text-[0.75rem] font-semibold text-m-muted"
|
||||
>
|
||||
<Plus size={13} strokeWidth={2.4} />
|
||||
{t('atlas.addPoi')}
|
||||
</button>
|
||||
)}
|
||||
|
||||
</div>
|
||||
</MSheet>
|
||||
)
|
||||
}
|
||||
|
||||
/** Custom month/year picker replacing the native <input type="month">: a year
|
||||
* stepper over a 12-month grid, opening upward so it clears the docked sheet. */
|
||||
function MMonthYearField({ value, onChange, placeholder, language, t }: {
|
||||
value: string
|
||||
onChange: (v: string) => void
|
||||
placeholder: string
|
||||
language: string
|
||||
t: AtlasController['t']
|
||||
}) {
|
||||
const [open, setOpen] = useState(false)
|
||||
const selYear = value ? Number(value.split('-')[0]) : null
|
||||
const selMonth = value ? Number(value.split('-')[1]) : null
|
||||
const [year, setYear] = useState(selYear ?? new Date().getFullYear())
|
||||
|
||||
const display = selYear
|
||||
? new Date(selYear, (selMonth ?? 1) - 1).toLocaleDateString(getIntlLanguage(language), { month: 'long', year: 'numeric' })
|
||||
: ''
|
||||
|
||||
return (
|
||||
<div className="relative">
|
||||
<button type="button" onClick={() => setOpen(o => !o)} aria-expanded={open} className={`${inputCls} flex items-center gap-2 text-start`}>
|
||||
<Calendar size={15} strokeWidth={2.2} className="flex-none text-m-muted" />
|
||||
<span className={`min-w-0 flex-1 truncate ${display ? '' : 'text-m-faint'}`}>{display || placeholder}</span>
|
||||
<ChevronDown size={15} strokeWidth={2} className={`flex-none text-m-faint transition-transform ${open ? 'rotate-180' : ''}`} />
|
||||
</button>
|
||||
{open && (
|
||||
<div className="absolute bottom-full inset-x-0 z-10 mb-2 rounded-[16px] border border-[color:var(--m-shbr)] bg-[color:var(--m-sheetop)] p-3 shadow-[0_12px_30px_-14px_rgba(0,0,0,.4)]">
|
||||
<div className="mb-[10px] flex items-center justify-between">
|
||||
<button type="button" onClick={() => setYear(y => y - 1)} aria-label={t('mobileVacay.prevYear')} className="flex h-8 w-8 flex-none items-center justify-center rounded-full bg-[color:var(--m-ic)] text-m-muted">
|
||||
<ChevronLeft size={16} strokeWidth={2.2} />
|
||||
</button>
|
||||
<span className="text-[0.9375rem] font-extrabold tabular-nums text-m-ink">{year}</span>
|
||||
<button type="button" onClick={() => setYear(y => y + 1)} aria-label={t('mobileVacay.nextYear')} className="flex h-8 w-8 flex-none items-center justify-center rounded-full bg-[color:var(--m-ic)] text-m-muted">
|
||||
<ChevronRight size={16} strokeWidth={2.2} />
|
||||
</button>
|
||||
</div>
|
||||
<div className="grid grid-cols-4 gap-[6px]">
|
||||
{Array.from({ length: 12 }, (_, m) => {
|
||||
const on = selYear === year && selMonth === m + 1
|
||||
return (
|
||||
<button
|
||||
key={m}
|
||||
type="button"
|
||||
onClick={() => { onChange(`${year}-${String(m + 1).padStart(2, '0')}`); setOpen(false) }}
|
||||
className={`rounded-[10px] py-2 text-[0.71875rem] font-bold capitalize ${on ? 'bg-m-act text-m-actfg' : 'bg-[color:var(--m-ic)] text-m-ink'}`}
|
||||
>
|
||||
{new Date(2000, m, 1).toLocaleDateString(getIntlLanguage(language), { month: 'short' })}
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
{value && (
|
||||
<button type="button" onClick={() => { onChange(''); setOpen(false) }} className="mt-[10px] w-full rounded-[10px] py-[7px] text-[0.6875rem] font-bold text-m-muted">
|
||||
{t('common.reset')}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import { http, HttpResponse } from 'msw'
|
||||
import { render, screen, fireEvent, waitFor } from '../../../../tests/helpers/render'
|
||||
import { server } from '../../../../tests/helpers/msw/server'
|
||||
import MAtlasCountryPopup from './MAtlasCountryPopup'
|
||||
import type { AtlasController } from './atlasController'
|
||||
|
||||
const bucketItem = (id: number, name: string, countryCode: string | null) => ({
|
||||
id, name, country_code: countryCode, lat: null, lng: null, notes: null, target_date: null,
|
||||
@@ -12,7 +11,7 @@ const bucketItem = (id: number, name: string, countryCode: string | null) => ({
|
||||
|
||||
// Only the slice of the atlas hook this sheet reads. `t` echoes the key back so
|
||||
// the assertions name the contract, not a locale string.
|
||||
function makeAtlas(overrides: Record<string, unknown> = {}): AtlasController {
|
||||
function makeAtlas(overrides: Record<string, unknown> = {}): React.ComponentProps<typeof MAtlasCountryPopup>['atlas'] {
|
||||
return {
|
||||
t: (key: string) => key,
|
||||
confirmAction: { code: 'FR', name: 'France', type: 'choose' },
|
||||
@@ -25,7 +24,7 @@ function makeAtlas(overrides: Record<string, unknown> = {}): AtlasController {
|
||||
bucketList: [],
|
||||
handleDeleteBucketItem: vi.fn().mockResolvedValue(undefined),
|
||||
...overrides,
|
||||
} as unknown as AtlasController
|
||||
} as unknown as React.ComponentProps<typeof MAtlasCountryPopup>['atlas']
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { ChevronRight, MapPin, Star, Trash2 } from 'lucide-react'
|
||||
import type { LucideIcon } from 'lucide-react'
|
||||
import MSheet from '../../components/MSheet'
|
||||
import type { AtlasController } from './atlasController'
|
||||
import { useAtlasCountryActions } from '../../../pages/atlas/useAtlasCountryActions'
|
||||
import { type AtlasCountryActionsOptions, useAtlasCountryActions } from '../../../pages/atlas/useAtlasCountryActions'
|
||||
|
||||
const markTint = 'bg-[rgba(47,163,122,.16)] text-[color:var(--m-st-confirmed)]' // theme-lint-disable — fixed tint from the design's option rows
|
||||
const bucketTint = 'bg-[rgba(232,161,58,.16)] text-[color:var(--m-st-pending)]' // theme-lint-disable — fixed tint from the design's option rows
|
||||
@@ -44,7 +43,8 @@ function OptionRow({ icon: Icon, tint, title, hint, onClick }: OptionRowProps) {
|
||||
}
|
||||
|
||||
interface MAtlasCountryPopupProps {
|
||||
atlas: AtlasController
|
||||
/** The country actions' state and setters, and what confirming a mark or unmark runs. */
|
||||
atlas: AtlasCountryActionsOptions & { executeConfirmAction: () => void | Promise<void> }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
import { Briefcase, CalendarClock, X } from 'lucide-react';
|
||||
import React from 'react';
|
||||
import { useNavigate } from 'react-router';
|
||||
import AtlasCountryPlaces from '../../../components/Atlas/AtlasCountryPlaces';
|
||||
import CountryFlag from '../../../components/shared/CountryFlag';
|
||||
import { countryStatus } from '../../../pages/atlas/atlasModel';
|
||||
import type { AtlasGlobeState } from '../../../pages/atlas/useAtlasGlobe';
|
||||
import MIconBtn from '../../components/MIconBtn';
|
||||
import MProgress from '../../components/MProgress';
|
||||
import MSheet from '../../components/MSheet';
|
||||
import MAtlasCountryPopup from './MAtlasCountryPopup';
|
||||
import { M_CARD } from './hub/mHubKit';
|
||||
|
||||
/**
|
||||
* The globe's country and region sheets on the phone: the action card (mark,
|
||||
* wish, take off) and a country's own sheet with its trips and places.
|
||||
*/
|
||||
export default function MAtlasCountrySheets({ s }: { s: AtlasGlobeState }): React.ReactElement {
|
||||
return (
|
||||
<>
|
||||
<MAtlasCountryPopup
|
||||
atlas={{
|
||||
t: s.t,
|
||||
confirmAction: s.confirmAction,
|
||||
setConfirmAction: (v) => {
|
||||
s.setConfirmAction(v);
|
||||
if (typeof v !== 'function' && v === null) s.closeDialogs();
|
||||
},
|
||||
executeConfirmAction: s.executeConfirmAction,
|
||||
setData: s.setData,
|
||||
visitedRegions: s.regions,
|
||||
setVisitedRegions: s.setRegions,
|
||||
bucketList: s.bucket,
|
||||
setBucketList: s.setBucket,
|
||||
handleDeleteBucketItem: s.handleDeleteBucketItem,
|
||||
}}
|
||||
/>
|
||||
<MSheet
|
||||
open={!!s.detail}
|
||||
onClose={s.closeDialogs}
|
||||
variant="bottom"
|
||||
ariaLabel={s.detail ? s.resolveName(s.detail.a2) : ''}
|
||||
>
|
||||
{s.detail && <CountrySheet s={s} />}
|
||||
</MSheet>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function CountrySheet({ s }: { s: AtlasGlobeState }): React.ReactElement | null {
|
||||
const navigate = useNavigate();
|
||||
const d = s.detail;
|
||||
if (!d) return null;
|
||||
const row = s.data?.countries.find((c) => c.code === d.a2);
|
||||
const progress = s.progress;
|
||||
const placedTrips = new Set((d.data?.places ?? []).map((p) => p.trip_id));
|
||||
const tripsWithoutPlaces = (d.data?.trips ?? []).filter((trip) => !placedTrips.has(trip.id));
|
||||
const openTrip = (id: number) => navigate(`/trips/${id}`);
|
||||
return (
|
||||
<div className="flex min-h-0 flex-col overflow-y-auto px-5 pb-6 pt-5">
|
||||
<div className="flex items-center gap-3">
|
||||
<CountryFlag code={d.a2} size={30} />
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="truncate text-title font-bold text-m-ink">{s.resolveName(d.a2)}</div>
|
||||
{row && (
|
||||
<div className="text-caption text-m-muted">
|
||||
{row.tripCount} {s.t('atlas.trips', { count: row.tripCount })}, {row.placeCount}{' '}
|
||||
{s.t('atlas.places', { count: row.placeCount })}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<MIconBtn variant="neutral" size={34} ariaLabel={s.t('common.close')} onClick={s.closeDialogs}>
|
||||
<X size={17} />
|
||||
</MIconBtn>
|
||||
</div>
|
||||
|
||||
{row && countryStatus(row) !== 'visited' && (
|
||||
<span className="mt-3 inline-flex items-center gap-1.5 self-start rounded-full bg-[color:var(--m-ic)] px-2.5 py-1 text-caption font-semibold text-m-muted">
|
||||
<CalendarClock size={12} /> {s.t('atlas.planned')}
|
||||
</span>
|
||||
)}
|
||||
|
||||
{progress && progress.total > 0 && (
|
||||
<div className={`${M_CARD} mt-4 px-4 py-3.5`}>
|
||||
<div className="flex items-baseline justify-between">
|
||||
<span className="text-caption text-m-muted">{s.t('atlas.regions')}</span>
|
||||
<span className="text-body font-bold tabular-nums text-m-ink">
|
||||
{progress.visited} / {progress.total}
|
||||
</span>
|
||||
</div>
|
||||
<MProgress value={(progress.visited / Math.max(1, progress.total)) * 100} height={6} className="mt-2" />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{tripsWithoutPlaces.length > 0 && (
|
||||
<div className="-mx-5 mt-4 flex gap-2 overflow-x-auto px-5">
|
||||
{tripsWithoutPlaces.map((trip) => (
|
||||
<button
|
||||
key={trip.id}
|
||||
type="button"
|
||||
onClick={() => openTrip(trip.id)}
|
||||
className="inline-flex flex-none items-center gap-1.5 rounded-full bg-[color:var(--m-ic)] px-3 py-2 text-caption font-semibold text-m-ink"
|
||||
>
|
||||
<Briefcase size={13} className="text-m-muted" /> {trip.title}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="mt-4">
|
||||
{d.data ? (
|
||||
<AtlasCountryPlaces variant="mobile" detail={d.data} onOpenTrip={openTrip} />
|
||||
) : (
|
||||
<div className="flex justify-center py-8">
|
||||
<div className="size-6 animate-spin rounded-full border-2 border-[color:var(--m-rowbr)] border-t-[color:var(--m-ink)]" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{d.data?.manually_marked && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={s.askUnmarkDetail}
|
||||
className="mt-5 w-full rounded-[16px] bg-[color:var(--m-ic)] py-3 text-body font-semibold"
|
||||
style={{ color: 'var(--m-st-danger)' }}
|
||||
>
|
||||
{s.t('atlas.unmark')}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
import { Globe2, Layers, X } from 'lucide-react';
|
||||
import React from 'react';
|
||||
import { useNavigate, useSearchParams } from 'react-router';
|
||||
import AtlasGlobe from '../../../components/AtlasGlobe/AtlasGlobe';
|
||||
import type { GlobeEngine } from '../../../components/AtlasGlobe/GlobeEngine';
|
||||
import GlobePins, { type GlobePinsHandle } from '../../../components/AtlasGlobe/GlobePins';
|
||||
import GlobeSky from '../../../components/AtlasGlobe/GlobeSky';
|
||||
import '../../../components/AtlasGlobe/atlasGlobe.css';
|
||||
import { segmentStyle } from '../../../components/Map/mapControlShadow';
|
||||
import AtlasBadgeUnlock from '../../../pages/atlas/AtlasBadgeUnlock';
|
||||
import AtlasGlobeSearch from '../../../pages/atlas/AtlasGlobeSearch';
|
||||
import AtlasGlobeStatus from '../../../pages/atlas/AtlasGlobeStatus';
|
||||
import AtlasGlobeTimeline from '../../../pages/atlas/AtlasGlobeTimeline';
|
||||
import { COMPARE_COLORS, compareCounts } from '../../../pages/atlas/atlasGlobePaint';
|
||||
import { countryStatus } from '../../../pages/atlas/atlasModel';
|
||||
import type { AtlasGlobeState } from '../../../pages/atlas/useAtlasGlobe';
|
||||
import { useAtlasGlobe } from '../../../pages/atlas/useAtlasGlobe';
|
||||
import { useGlobeStats } from '../../../pages/atlas/useGlobeStats';
|
||||
import MAtlasCountrySheets from './MAtlasCountrySheets';
|
||||
import MAtlasLayersSheet from './MAtlasLayersSheet';
|
||||
import MAtlasStatsCard from './MAtlasStatsCard';
|
||||
import MAtlasHub from './hub/MAtlasHub';
|
||||
|
||||
/**
|
||||
* The globe Atlas on the phone: the globe fills the screen under the shell,
|
||||
* search on top, the numbers as a row of cards above the bottom nav, and the
|
||||
* same dialogs as the desktop. State and data come from useAtlasGlobe.
|
||||
*/
|
||||
export default function MAtlasGlobe(): React.ReactElement {
|
||||
const s = useAtlasGlobe();
|
||||
const stats = useGlobeStats(s);
|
||||
const navigate = useNavigate();
|
||||
const [layersOpen, setLayersOpen] = React.useState(false);
|
||||
const pinsRef = React.useRef<GlobePinsHandle>(null);
|
||||
// The dock's search button hands over with ?search=1, as on every screen: take
|
||||
// it off the address and put the cursor into the search.
|
||||
const [searchParams, setSearchParams] = useSearchParams();
|
||||
const [focusSearch, setFocusSearch] = React.useState(0);
|
||||
React.useEffect(() => {
|
||||
if (searchParams.get('search') == null) return;
|
||||
const next = new URLSearchParams(searchParams);
|
||||
next.delete('search');
|
||||
setSearchParams(next, { replace: true });
|
||||
setFocusSearch((n) => n + 1);
|
||||
}, [searchParams, setSearchParams]);
|
||||
const onFrame = React.useCallback(
|
||||
(e: GlobeEngine) => {
|
||||
s.skyRef.current?.layout(e);
|
||||
pinsRef.current?.layout(e);
|
||||
},
|
||||
[s.skyRef]
|
||||
);
|
||||
|
||||
return (
|
||||
// h-dvh, as the classic phone Atlas: the shell gives no definite height (#1809).
|
||||
<div className="atlas-globe m-bleed relative h-dvh overflow-hidden">
|
||||
<AtlasGlobe
|
||||
ref={s.globeRef}
|
||||
fetchJson={s.fetchJson}
|
||||
dark
|
||||
labelFor={s.labelFor}
|
||||
labelRegionsOf={s.labelRegionsOf}
|
||||
paint={s.paint}
|
||||
paintKey={s.paintKey}
|
||||
onSelect={s.onSelect}
|
||||
onReady={s.onReady}
|
||||
onFrame={onFrame}
|
||||
onError={(err) => s.setError(err instanceof Error ? err.message : String(err))}
|
||||
insetBottom={170}
|
||||
/>
|
||||
<div className="pointer-events-none absolute inset-0">
|
||||
<GlobeSky ref={s.skyRef} dark />
|
||||
</div>
|
||||
<div className="pointer-events-none absolute inset-0 overflow-hidden">
|
||||
<GlobePins ref={pinsRef} pins={s.pins} />
|
||||
</div>
|
||||
|
||||
<AtlasGlobeStatus s={s} />
|
||||
<AtlasGlobeSearch
|
||||
s={s}
|
||||
focusSignal={focusSearch}
|
||||
className={`end-[102px] start-3 top-[var(--m-safe-top,12px)]`}
|
||||
/>
|
||||
<div
|
||||
className="ag-liquid pointer-events-auto absolute end-3 top-[var(--m-safe-top,12px)] flex h-11 items-center rounded-full p-1"
|
||||
style={{ gap: 2 }}
|
||||
>
|
||||
{/* The hub on the phone: one button for statistics, badges, wishes, tours
|
||||
and travellers; a new badge flies into it. */}
|
||||
<button
|
||||
type="button"
|
||||
className={s.passportOpen ? 'bg-accent text-accent-text' : 'text-content-secondary'}
|
||||
style={segmentStyle(s.passportOpen)}
|
||||
onClick={() => s.openPassport(s.passportTab)}
|
||||
aria-label={s.t('atlas.globe.hub')}
|
||||
data-atlas-badges-btn
|
||||
>
|
||||
<Globe2 size={16} />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={layersOpen ? 'bg-accent text-accent-text' : 'text-content-secondary'}
|
||||
style={segmentStyle(layersOpen)}
|
||||
onClick={() => setLayersOpen(true)}
|
||||
aria-label={s.t('atlas.globe.layers')}
|
||||
>
|
||||
<Layers size={16} />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<MAtlasStatsCard stats={stats} />
|
||||
|
||||
<AtlasGlobeTimeline s={s} className="end-3 start-3 top-[calc(var(--m-safe-top,12px)+56px)]" />
|
||||
<AtlasBadgeUnlock s={s} />
|
||||
<MAtlasLayersSheet s={s} open={layersOpen} onClose={() => setLayersOpen(false)} />
|
||||
<MAtlasCountrySheets s={s} />
|
||||
<MAtlasHub s={s} />
|
||||
<MCompareBar s={s} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The overlay with another traveller on the phone: who, the three counts with
|
||||
* their colours, the gaps switch and the way out, as one card above the numbers.
|
||||
*/
|
||||
function MCompareBar({ s }: { s: AtlasGlobeState }): React.ReactElement | null {
|
||||
const p = s.compareWith;
|
||||
if (!p) return null;
|
||||
const mine = (s.data?.countries ?? []).filter((c) => countryStatus(c) === 'visited').map((c) => c.code);
|
||||
const c = compareCounts(mine, p.codes);
|
||||
const keys: Array<[string, number, string]> = [
|
||||
[COMPARE_COLORS.both, c.both, s.t('atlas.globe.together')],
|
||||
[COMPARE_COLORS.theirs, c.theirsOnly, s.t('atlas.globe.onlyThem', { name: p.username })],
|
||||
[COMPARE_COLORS.mine, c.mineOnly, s.t('atlas.globe.onlyYou')],
|
||||
];
|
||||
return (
|
||||
<div className="ag-liquid pointer-events-auto absolute inset-x-3 bottom-[calc(var(--bottom-nav-h,84px)+92px)] z-30 flex flex-col gap-2 rounded-[20px] px-3.5 py-3">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="min-w-0 flex-1 truncate text-body font-semibold">
|
||||
{s.t('atlas.globe.compareWith', { name: p.username })}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => s.setGaps(!s.gaps)}
|
||||
aria-pressed={s.gaps}
|
||||
className={`rounded-full px-3 py-1.5 text-caption font-semibold ${s.gaps ? 'bg-accent text-accent-text' : 'bg-surface-tertiary text-content-secondary'}`}
|
||||
>
|
||||
{s.t('atlas.globe.gaps')}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={s.stopCompare}
|
||||
aria-label={s.t('common.close')}
|
||||
className="grid size-8 place-items-center rounded-full text-content-muted"
|
||||
>
|
||||
<X size={15} />
|
||||
</button>
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-x-4 gap-y-1">
|
||||
{keys.map(([color, n, label]) => (
|
||||
<span key={label} className="inline-flex items-center gap-1.5 text-caption">
|
||||
<i className="inline-block size-2.5 rounded-full" style={{ background: color }} />
|
||||
<b className="tabular-nums">{n}</b>
|
||||
<span className="text-content-muted">{label}</span>
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
import { CalendarClock, Plane, Puzzle, X } from 'lucide-react';
|
||||
import React from 'react';
|
||||
import type { GlobeColorMode } from '../../../pages/atlas/atlasGlobePaint';
|
||||
import type { AtlasGlobeState } from '../../../pages/atlas/useAtlasGlobe';
|
||||
import MIconBtn from '../../components/MIconBtn';
|
||||
import MSegmented from '../../components/MSegmented';
|
||||
import MSheet from '../../components/MSheet';
|
||||
import MToggle from '../../components/MToggle';
|
||||
import { M_CARD } from './hub/mHubKit';
|
||||
|
||||
/**
|
||||
* What the globe shows, on the phone: the switches as rows of one card and
|
||||
* the colouring as a segmented control, in a sheet from the bottom.
|
||||
*/
|
||||
export default function MAtlasLayersSheet({
|
||||
s,
|
||||
open,
|
||||
onClose,
|
||||
}: {
|
||||
s: AtlasGlobeState;
|
||||
open: boolean;
|
||||
onClose: () => void;
|
||||
}): React.ReactElement {
|
||||
const rows: Array<{
|
||||
key: string;
|
||||
Icon: React.ComponentType<{ size?: number }>;
|
||||
label: string;
|
||||
on: boolean;
|
||||
toggle: () => void;
|
||||
}> = [
|
||||
{
|
||||
key: 'planned',
|
||||
Icon: CalendarClock,
|
||||
label: s.t('atlas.showPlanned'),
|
||||
on: s.showPlanned,
|
||||
toggle: () => s.setShowPlanned(!s.showPlanned),
|
||||
},
|
||||
...(s.flights?.routes.length
|
||||
? [
|
||||
{
|
||||
key: 'flights',
|
||||
Icon: Plane,
|
||||
label: s.t('atlas.globe.flights'),
|
||||
on: s.showFlights,
|
||||
toggle: () => s.setShowFlights(!s.showFlights),
|
||||
},
|
||||
]
|
||||
: []),
|
||||
...s.pluginLayers.map((l) => {
|
||||
const key = `${l.pluginId}:${l.id}`;
|
||||
return {
|
||||
key,
|
||||
Icon: Puzzle,
|
||||
label: l.name || l.id,
|
||||
on: !s.hiddenPluginLayers.has(key),
|
||||
toggle: () => s.togglePluginLayer(key),
|
||||
};
|
||||
}),
|
||||
];
|
||||
const modes: Array<{ value: GlobeColorMode; label: string }> = [
|
||||
{ value: 'country', label: s.t('atlas.globe.colorCountry') },
|
||||
{ value: 'status', label: s.t('atlas.globe.colorStatus') },
|
||||
{ value: 'year', label: s.t('atlas.globe.colorYear') },
|
||||
];
|
||||
return (
|
||||
<MSheet open={open} onClose={onClose} variant="bottom" ariaLabel={s.t('atlas.globe.layers')}>
|
||||
<div className="flex min-h-0 flex-col gap-5 overflow-y-auto px-5 pb-6 pt-5">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="min-w-0 flex-1 text-title font-bold text-m-ink">{s.t('atlas.globe.layers')}</div>
|
||||
<MIconBtn variant="neutral" size={34} ariaLabel={s.t('common.close')} onClick={onClose}>
|
||||
<X size={17} />
|
||||
</MIconBtn>
|
||||
</div>
|
||||
<div className={`${M_CARD} flex flex-col p-1.5`}>
|
||||
{rows.map(({ key, Icon, label, on, toggle }, i) => (
|
||||
<div
|
||||
key={key}
|
||||
className={`flex items-center gap-3 px-3 py-3 ${i > 0 ? 'border-t border-[color:var(--m-rowbr)]' : ''}`}
|
||||
>
|
||||
<span className="grid size-9 flex-none place-items-center rounded-full bg-[color:var(--m-ic)] text-m-muted">
|
||||
<Icon size={16} />
|
||||
</span>
|
||||
<span className="min-w-0 flex-1 truncate text-body font-semibold text-m-ink">{label}</span>
|
||||
<MToggle checked={on} onChange={toggle} ariaLabel={label} />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<div className="flex flex-col gap-2">
|
||||
<div className="px-1 text-caption font-bold uppercase tracking-wide text-m-muted">
|
||||
{s.t('atlas.globe.colorBy')}
|
||||
</div>
|
||||
<MSegmented value={s.colorMode} onChange={s.setColorMode} options={modes} />
|
||||
</div>
|
||||
</div>
|
||||
</MSheet>
|
||||
);
|
||||
}
|
||||
@@ -1,120 +0,0 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { ChevronRight, Search } from 'lucide-react'
|
||||
import { useTranslation } from '../../../i18n'
|
||||
|
||||
interface CountryOption {
|
||||
code: string
|
||||
label: string
|
||||
}
|
||||
|
||||
interface MAtlasSearchProps {
|
||||
open: boolean
|
||||
onClose: () => void
|
||||
/** All searchable countries (code + localized label). */
|
||||
options: CountryOption[]
|
||||
/** Shown while the query is empty: recently visited + bucket countries. */
|
||||
suggestions: CountryOption[]
|
||||
isVisited: (code: string) => boolean
|
||||
/** Countries that only appear via a trip which hasn't started yet (#1048). */
|
||||
isPlanned: (code: string) => boolean
|
||||
isOnBucketList: (code: string) => boolean
|
||||
onSelect: (code: string) => void
|
||||
}
|
||||
|
||||
const statusCls = 'flex-none font-geist text-[0.625rem] font-bold uppercase tracking-[.04em] text-m-faint'
|
||||
|
||||
/**
|
||||
* Full-screen country search on a blurred scrim. Typing filters the country
|
||||
* list; while empty the suggestion list (visited + bucket countries) fills
|
||||
* the result card. Selecting a row flies the map to the country.
|
||||
*/
|
||||
export default function MAtlasSearch({
|
||||
open,
|
||||
onClose,
|
||||
options,
|
||||
suggestions,
|
||||
isVisited,
|
||||
isPlanned,
|
||||
isOnBucketList,
|
||||
onSelect,
|
||||
}: MAtlasSearchProps) {
|
||||
const { t } = useTranslation()
|
||||
const [query, setQuery] = useState('')
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) setQuery('')
|
||||
}, [open])
|
||||
|
||||
if (!open) return null
|
||||
|
||||
const q = query.trim().toLowerCase()
|
||||
const rows = q ? options.filter((o) => o.label.toLowerCase().includes(q)).slice(0, 6) : suggestions
|
||||
|
||||
const scrimCls = 'm-fade-in fixed inset-0 z-[70] flex flex-col bg-[rgba(16,16,19,.28)] px-[18px] pt-[calc(var(--m-safe-top,12px)+12px)] backdrop-blur-[22px] backdrop-saturate-[1.6] wide:pt-[calc(var(--m-safe-top,12px)+72px)] wide:[&>*]:mx-auto wide:[&>*]:w-full wide:[&>*]:max-w-[640px]' // theme-lint-disable — fixed scrim value from the design
|
||||
|
||||
return (
|
||||
<div
|
||||
className={scrimCls}
|
||||
// presentation, not role="button": the scrim wraps the whole search
|
||||
// overlay, so making it a button puts a full-screen tab stop around its
|
||||
// own contents — and screen readers would read the entire panel as the
|
||||
// button's label. Clicking it is a mouse shortcut for the Cancel control
|
||||
// inside, which is already in the tab order. Same treatment as the other
|
||||
// backdrops in this sweep.
|
||||
role="presentation"
|
||||
onClick={onClose}
|
||||
>
|
||||
<div className="flex items-center gap-[10px]" role="presentation" onClick={(e) => e.stopPropagation()}>
|
||||
<label className="flex min-w-0 flex-1 items-center gap-[10px] rounded-[18px] border border-[color:var(--m-gbr)] bg-[color:var(--m-sheetop)] px-4 py-[14px] shadow-[0_12px_30px_-14px_rgba(0,0,0,.4)]">
|
||||
<Search size={18} strokeWidth={2.2} className="flex-none text-m-muted" />
|
||||
<input
|
||||
autoFocus
|
||||
value={query}
|
||||
onChange={(e) => setQuery(e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Escape') onClose()
|
||||
if (e.key === 'Enter' && rows.length > 0) onSelect(rows[0].code)
|
||||
}}
|
||||
enterKeyHint="search" placeholder={t('atlas.searchCountry')}
|
||||
className="min-w-0 flex-1 bg-transparent font-geist text-[0.9375rem] font-semibold text-m-ink outline-none placeholder:font-normal placeholder:text-m-faint"
|
||||
/>
|
||||
</label>
|
||||
<button type="button" onClick={onClose} className="flex-none px-1 font-geist text-[0.9375rem] font-semibold text-white">
|
||||
{t('common.cancel')}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{rows.length > 0 && (
|
||||
<div
|
||||
className="m-pop-in mt-[14px] divide-y divide-[color:var(--m-rowbr)] overflow-hidden rounded-[20px] border border-[color:var(--m-gbr)] bg-[color:var(--m-sheetop)] shadow-[0_20px_44px_-18px_rgba(0,0,0,.4)]"
|
||||
role="presentation"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
{rows.map((r) => (
|
||||
<button
|
||||
key={r.code}
|
||||
type="button"
|
||||
onClick={() => onSelect(r.code)}
|
||||
className="flex w-full items-center gap-3 px-4 py-[14px] text-start active:bg-[color:var(--m-ic)]"
|
||||
>
|
||||
<img
|
||||
src={`https://flagcdn.com/w40/${r.code.toLowerCase()}.png`}
|
||||
alt=""
|
||||
className="h-6 w-[34px] flex-none rounded-[5px] object-cover shadow-[0_1px_3px_rgba(0,0,0,.25)]"
|
||||
/>
|
||||
<span className="min-w-0 flex-1 truncate text-[0.9375rem] font-extrabold text-m-ink">{r.label}</span>
|
||||
{isVisited(r.code) ? (
|
||||
<span className={statusCls}>{t('mobileAtlas.visited')}</span>
|
||||
) : isPlanned(r.code) ? (
|
||||
<span className={statusCls}>{t('mobileAtlas.planned')}</span>
|
||||
) : isOnBucketList(r.code) ? (
|
||||
<span className={statusCls}>{t('atlas.bucketTab')}</span>
|
||||
) : null}
|
||||
<ChevronRight size={17} strokeWidth={2} className="flex-none text-m-faint" />
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,41 +1,24 @@
|
||||
import { useTranslation } from '../../../i18n'
|
||||
import type { AtlasStats } from '../../../pages/atlas/atlasModel'
|
||||
import type { GlobeStat } from '../../../components/AtlasGlobe/GlobeStatsBar'
|
||||
|
||||
interface MAtlasStatsCardProps {
|
||||
stats: AtlasStats
|
||||
}
|
||||
/** The five figures the phone card has room for, in this order when they exist. */
|
||||
const PHONE_KEYS = ['countries', 'continents', 'regions', 'badges', 'wishlist']
|
||||
|
||||
/**
|
||||
* Floating stats card above the bottom nav: five stat columns straight from the
|
||||
* design. The bucket-list entry now lives in the full-width top header, so this
|
||||
* card is stats only.
|
||||
* Floating stats card above the bottom nav, in the same liquid glass as the
|
||||
* search on top: five columns, a large number over
|
||||
* a small caps label, as the phone Atlas has always shown them. Each column
|
||||
* opens what it counts (the hub's numbers, badges or wishlist).
|
||||
*/
|
||||
export default function MAtlasStatsCard({ stats }: MAtlasStatsCardProps) {
|
||||
const { t } = useTranslation()
|
||||
const cols: [number, string][] = [
|
||||
[stats.totalCountries, t('atlas.countries', { count: stats.totalCountries })],
|
||||
[stats.totalTrips, t('atlas.trips', { count: stats.totalTrips })],
|
||||
[stats.totalPlaces, t('atlas.places', { count: stats.totalPlaces })],
|
||||
[stats.totalCities || 0, t('atlas.cities', { count: stats.totalCities || 0 })],
|
||||
[stats.totalDays, t('atlas.days', { count: stats.totalDays })],
|
||||
]
|
||||
// All five columns are spoken for, so the planned count rides along with the country
|
||||
// number as a superscript rather than claiming a sixth column.
|
||||
const planned = stats.totalCountriesPlanned || 0
|
||||
|
||||
export default function MAtlasStatsCard({ stats }: { stats: GlobeStat[] }) {
|
||||
const cols = PHONE_KEYS.map((k) => stats.find((st) => st.key === k)).filter((st): st is GlobeStat => !!st)
|
||||
return (
|
||||
<div className="m-bar-x absolute bottom-[calc(var(--bottom-nav-h,84px)+16px)] z-[5] wide:mx-auto wide:max-w-[720px]">
|
||||
<div className="flex w-full rounded-[22px] border border-[color:var(--m-shbr)] bg-[color:var(--m-sheet)] px-3 py-[14px] shadow-[0_18px_44px_-20px_rgba(0,0,0,.4)]">
|
||||
{cols.map(([n, l], i) => (
|
||||
<div key={l} className="flex-1 text-center">
|
||||
<div className="text-[1.375rem] font-extrabold leading-none tabular-nums text-m-ink">
|
||||
{n}
|
||||
{i === 0 && planned > 0 && (
|
||||
<span className="align-super text-[0.6875rem] font-bold text-m-faint">+{planned}</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="mt-1 font-geist text-[0.53125rem] font-bold uppercase tracking-[.06em] text-m-faint">{l}</div>
|
||||
</div>
|
||||
<div className="ag-liquid flex w-full rounded-[22px] px-2 py-[12px]">
|
||||
{cols.map((st) => (
|
||||
<button key={st.key} type="button" onClick={st.onClick} className="min-w-0 flex-1 rounded-[14px] px-0.5 py-0.5 text-center active:bg-surface-hover">
|
||||
<div className="text-[1.375rem] font-extrabold leading-none tabular-nums text-content">{st.value}</div>
|
||||
<div className="mt-1 truncate font-geist text-[0.53125rem] font-bold uppercase tracking-[.06em] text-content-muted">{st.label}</div>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
import { useAtlas } from '../../../pages/atlas/useAtlas'
|
||||
|
||||
/**
|
||||
* Full surface of the shared atlas hook. The mobile screen calls useAtlas()
|
||||
* once and hands the controller down to its sheets, so map state, bucket list
|
||||
* and the mark/unmark flows stay in a single instance.
|
||||
*/
|
||||
export type AtlasController = ReturnType<typeof useAtlas>
|
||||
@@ -0,0 +1,80 @@
|
||||
import { X } from 'lucide-react';
|
||||
import React from 'react';
|
||||
import { useHubTabs } from '../../../../pages/atlas/AtlasHubRail';
|
||||
import type { AtlasGlobeState } from '../../../../pages/atlas/useAtlasGlobe';
|
||||
import MChip from '../../../components/MChip';
|
||||
import MChipStrip from '../../../components/MChipStrip';
|
||||
import MIconBtn from '../../../components/MIconBtn';
|
||||
import MSheet from '../../../components/MSheet';
|
||||
import MHubBadges from './MHubBadges';
|
||||
import MHubDawarich from './MHubDawarich';
|
||||
import MHubOverview from './MHubOverview';
|
||||
import MHubTours from './MHubTours';
|
||||
import MHubTravellers from './MHubTravellers';
|
||||
import MHubWishlist from './MHubWishlist';
|
||||
|
||||
/**
|
||||
* The Atlas hub on the phone: a sheet that rises over the globe, with the tabs
|
||||
* as a strip of chips under the title and each tab laid out for a narrow
|
||||
* screen. Badge details, a traveller's profile and a new wish open as sheets
|
||||
* of their own on top.
|
||||
*/
|
||||
export default function MAtlasHub({ s }: { s: AtlasGlobeState }): React.ReactElement {
|
||||
const tabs = useHubTabs(s);
|
||||
const tab = s.passportTab;
|
||||
const close = () => s.setPassportOpen(false);
|
||||
const earned = s.badges.filter((b) => b.earned).length;
|
||||
return (
|
||||
<MSheet
|
||||
open={s.passportOpen}
|
||||
onClose={close}
|
||||
variant="bottom"
|
||||
ariaLabel={s.t('atlas.globe.hub')}
|
||||
className="h-full"
|
||||
>
|
||||
<div className="flex min-h-0 flex-1 flex-col">
|
||||
<div className="flex items-start gap-3 px-5 pb-3 pt-5">
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="text-title font-bold leading-tight text-m-ink">{s.t('atlas.globe.hub')}</div>
|
||||
<div className="text-caption text-m-muted">
|
||||
{s.t('atlas.globe.collected', { earned, total: s.badges.length })}
|
||||
</div>
|
||||
</div>
|
||||
<MIconBtn variant="neutral" size={34} ariaLabel={s.t('common.close')} onClick={close}>
|
||||
<X size={17} />
|
||||
</MIconBtn>
|
||||
</div>
|
||||
<MChipStrip label={s.t('atlas.globe.hub')} className="gap-2 px-5 pb-3">
|
||||
{tabs.map(({ tab: k, label, Icon }) => (
|
||||
<MChip
|
||||
key={k}
|
||||
pressable
|
||||
active={tab === k}
|
||||
onClick={() => {
|
||||
s.setPassportTab(k);
|
||||
s.setProfileId(null);
|
||||
}}
|
||||
>
|
||||
<Icon size={13} strokeWidth={2.2} /> {label}
|
||||
</MChip>
|
||||
))}
|
||||
</MChipStrip>
|
||||
<div className="min-h-0 flex-1 overflow-y-auto overscroll-contain px-4 pb-8 pt-1">
|
||||
{tab === 'overview' ? (
|
||||
<MHubOverview s={s} />
|
||||
) : tab === 'badges' ? (
|
||||
<MHubBadges s={s} />
|
||||
) : tab === 'wishlist' ? (
|
||||
<MHubWishlist s={s} />
|
||||
) : tab === 'dawarich' ? (
|
||||
<MHubDawarich s={s} />
|
||||
) : tab === 'tours' ? (
|
||||
<MHubTours s={s} />
|
||||
) : (
|
||||
<MHubTravellers s={s} />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</MSheet>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
import { BADGE_CATEGORIES, type Badge } from '@trek/shared';
|
||||
import { CalendarCheck, CheckCircle2, Hourglass, Target, Users, X } from 'lucide-react';
|
||||
import React from 'react';
|
||||
import BadgeMedal, { TIERS } from '../../../../components/AtlasGlobe/BadgeMedal';
|
||||
import CountryFlag from '../../../../components/shared/CountryFlag';
|
||||
import { medalLabel } from '../../../../pages/atlas/AtlasGlobeBadges';
|
||||
import { badgeHolders, badgeLadder, formatNum } from '../../../../pages/atlas/atlasHubModel';
|
||||
import type { AtlasGlobeState } from '../../../../pages/atlas/useAtlasGlobe';
|
||||
import MIconBtn from '../../../components/MIconBtn';
|
||||
import MProgress from '../../../components/MProgress';
|
||||
import MSheet from '../../../components/MSheet';
|
||||
import { M_CARD, M_INNER, MHubSection, MHubTiles, type MHubTileData } from './mHubKit';
|
||||
|
||||
function titleOf(s: AtlasGlobeState, b: Badge): string {
|
||||
const params: Record<string, string | number> = { ...(b.params ?? {}) };
|
||||
if (typeof params.country === 'string') params.country = s.resolveName(params.country) || params.country;
|
||||
return s.t(b.titleKey, params);
|
||||
}
|
||||
|
||||
/** Badges on the phone: every category as a three-column grid; a tap opens the badge's own sheet. */
|
||||
export default function MHubBadges({ s }: { s: AtlasGlobeState }): React.ReactElement {
|
||||
const [openId, setOpenId] = React.useState<string | null>(null);
|
||||
const open = openId ? (s.badges.find((b) => b.id === openId) ?? null) : null;
|
||||
return (
|
||||
<div className="flex flex-col gap-5">
|
||||
{BADGE_CATEGORIES.map((cat) => {
|
||||
const list = s.badges.filter((b) => b.category === cat);
|
||||
if (!list.length) return null;
|
||||
return (
|
||||
<MHubSection
|
||||
key={cat}
|
||||
title={s.t(`atlas.badgeCat.${cat}`)}
|
||||
meta={`${list.filter((b) => b.earned).length} / ${list.length}`}
|
||||
>
|
||||
<div className={`${M_CARD} grid grid-cols-3 gap-1 p-2`}>
|
||||
{list.map((b) => (
|
||||
<button
|
||||
key={b.id}
|
||||
type="button"
|
||||
onClick={() => setOpenId(b.id)}
|
||||
className="flex flex-col items-center gap-1.5 rounded-[16px] px-1 pb-2.5 pt-2 text-center active:bg-[color:var(--m-ic)]"
|
||||
>
|
||||
<BadgeMedal
|
||||
id={`m-${b.id}`}
|
||||
motif={b.motif}
|
||||
tier={b.tier}
|
||||
earned={b.earned}
|
||||
size={78}
|
||||
progress={b.target ? b.current / b.target : 0}
|
||||
label={medalLabel(b)}
|
||||
/>
|
||||
<span className="line-clamp-2 text-caption font-semibold leading-tight text-m-ink">
|
||||
{titleOf(s, b)}
|
||||
</span>
|
||||
<span className="text-[0.6875rem] tabular-nums text-m-muted">
|
||||
{b.earned ? (b.year ?? '') : `${formatNum(b.current)} / ${formatNum(b.target)}`}
|
||||
</span>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</MHubSection>
|
||||
);
|
||||
})}
|
||||
<MSheet open={!!open} onClose={() => setOpenId(null)} variant="bottom" ariaLabel={open ? titleOf(s, open) : ''}>
|
||||
{open && <BadgeSheet s={s} b={open} onClose={() => setOpenId(null)} onOpen={setOpenId} />}
|
||||
</MSheet>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function BadgeSheet({
|
||||
s,
|
||||
b,
|
||||
onClose,
|
||||
onOpen,
|
||||
}: {
|
||||
s: AtlasGlobeState;
|
||||
b: Badge;
|
||||
onClose: () => void;
|
||||
onOpen: (id: string) => void;
|
||||
}): React.ReactElement {
|
||||
const share = b.target ? Math.min(1, b.current / b.target) : 0;
|
||||
const metal = TIERS[b.tier][0];
|
||||
const { loadPeople, compareEnabled } = s;
|
||||
React.useEffect(() => {
|
||||
if (compareEnabled) loadPeople();
|
||||
}, [compareEnabled, loadPeople]);
|
||||
const ladder = badgeLadder(s.badges, b);
|
||||
const holders = compareEnabled ? badgeHolders(s.people, b) : null;
|
||||
const tiles: MHubTileData[] = [
|
||||
{ Icon: Target, value: `${formatNum(b.current)} / ${formatNum(b.target)}`, label: s.t('atlas.globe.progress') },
|
||||
b.earned
|
||||
? { Icon: CalendarCheck, value: b.year ?? '✓', label: s.t('atlas.globe.reached') }
|
||||
: { Icon: Hourglass, value: formatNum(Math.max(0, b.target - b.current)), label: s.t('atlas.globe.toGo') },
|
||||
];
|
||||
if (holders)
|
||||
tiles.push({ Icon: Users, value: `${holders.holders} / ${holders.of}`, label: s.t('atlas.globe.holders') });
|
||||
return (
|
||||
<div className="flex min-h-0 flex-col overflow-y-auto px-5 pb-8 pt-4">
|
||||
<div className="flex justify-end">
|
||||
<MIconBtn variant="neutral" size={34} ariaLabel={s.t('common.close')} onClick={onClose}>
|
||||
<X size={17} />
|
||||
</MIconBtn>
|
||||
</div>
|
||||
<div className="relative -mt-4 flex flex-col items-center gap-3 text-center">
|
||||
<div
|
||||
aria-hidden="true"
|
||||
className="pointer-events-none absolute top-0 size-56 rounded-full opacity-60"
|
||||
style={{
|
||||
background: `radial-gradient(circle, color-mix(in srgb, ${metal} 30%, transparent), transparent 70%)`,
|
||||
}}
|
||||
/>
|
||||
<div className="relative">
|
||||
<BadgeMedal
|
||||
id={`ms-${b.id}`}
|
||||
motif={b.motif}
|
||||
tier={b.tier}
|
||||
earned={b.earned}
|
||||
size={150}
|
||||
progress={share}
|
||||
label={medalLabel(b)}
|
||||
/>
|
||||
</div>
|
||||
<div className="relative flex flex-wrap justify-center gap-1.5">
|
||||
<span className="rounded-full bg-[color:var(--m-ic)] px-2.5 py-1 text-caption font-semibold text-m-muted">
|
||||
{s.t(`atlas.badgeCat.${b.category}`)}
|
||||
</span>
|
||||
<span className="inline-flex items-center gap-1.5 rounded-full bg-[color:var(--m-ic)] px-2.5 py-1 text-caption font-semibold text-m-ink">
|
||||
<span className="size-2 rounded-full" style={{ background: metal }} /> {s.t(`atlas.badgeTier.${b.tier}`)}
|
||||
</span>
|
||||
{b.earned && (
|
||||
<span
|
||||
className="inline-flex items-center gap-1 rounded-full bg-[color:var(--m-ic)] px-2.5 py-1 text-caption font-semibold"
|
||||
style={{ color: 'var(--m-st-confirmed)' }}
|
||||
>
|
||||
<CheckCircle2 size={12} /> {s.t('atlas.globe.reached')}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="relative text-title font-bold leading-tight text-m-ink">{titleOf(s, b)}</div>
|
||||
</div>
|
||||
|
||||
<div className={`${M_CARD} mt-5 flex flex-col gap-2 px-4 py-4`}>
|
||||
<span className="self-start rounded-full bg-[color:var(--m-ic)] px-2.5 py-1 text-caption font-semibold text-m-muted">
|
||||
{s.t('atlas.globe.howTo')}
|
||||
</span>
|
||||
<p className="m-0 text-body text-m-ink">
|
||||
{s.t(b.descKey, {
|
||||
...(b.params ?? {}),
|
||||
country: b.country ? s.resolveName(b.country) || b.country : '',
|
||||
count: b.target,
|
||||
})}
|
||||
</p>
|
||||
{!b.earned && <MProgress value={share * 100} height={6} color={metal} className="mt-1" />}
|
||||
</div>
|
||||
|
||||
<div className="mt-3">
|
||||
<MHubTiles tiles={tiles} cols={tiles.length === 3 ? 3 : 2} />
|
||||
</div>
|
||||
|
||||
{b.earned && b.country && (
|
||||
<div className={`${M_CARD} mt-3 flex items-center gap-3 px-4 py-3`}>
|
||||
<span className={`${M_INNER} grid size-10 flex-none place-items-center rounded-full`}>
|
||||
<CountryFlag code={b.country} size={20} />
|
||||
</span>
|
||||
<span className="min-w-0">
|
||||
<span className="block text-caption text-m-muted">{s.t('atlas.globe.madeBy')}</span>
|
||||
<span className="block truncate text-body font-bold text-m-ink">
|
||||
{s.resolveName(b.country) || b.country}
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{ladder.length > 1 && (
|
||||
<div className="mt-5">
|
||||
<MHubSection
|
||||
title={s.t('atlas.globe.stages')}
|
||||
meta={`${ladder.filter((x) => x.earned).length} / ${ladder.length}`}
|
||||
>
|
||||
<div className="-mx-5 flex gap-2 overflow-x-auto px-5 pb-1">
|
||||
{ladder.map((x) => (
|
||||
<button
|
||||
key={x.id}
|
||||
type="button"
|
||||
onClick={() => onOpen(x.id)}
|
||||
aria-current={x.id === b.id}
|
||||
className={`flex w-[78px] flex-none flex-col items-center gap-1 rounded-[16px] px-1 py-2 ${x.id === b.id ? 'bg-[color:var(--m-ic)]' : ''}`}
|
||||
>
|
||||
<BadgeMedal
|
||||
id={`ml-${x.id}`}
|
||||
motif={x.motif}
|
||||
tier={x.tier}
|
||||
earned={x.earned}
|
||||
size={56}
|
||||
progress={x.target ? x.current / x.target : 0}
|
||||
label={medalLabel(x)}
|
||||
/>
|
||||
<span className="w-full truncate text-[0.6875rem] font-semibold text-m-muted">{titleOf(s, x)}</span>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</MHubSection>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
import { Check, Globe2, Info, Loader2, RefreshCw, Star } from 'lucide-react';
|
||||
import React from 'react';
|
||||
import { cityLine, countryLabel, formatDistance } from '../../../../components/Dawarich/dawarichAtlasModel';
|
||||
import { formatDuration } from '../../../../components/Dawarich/dawarichSuggestionModel';
|
||||
import { useDawarichAtlas } from '../../../../components/Dawarich/useDawarichAtlas';
|
||||
import CountryFlag from '../../../../components/shared/CountryFlag';
|
||||
import { dawarichNotes } from '../../../../pages/atlas/AtlasGlobeDawarich';
|
||||
import type { AtlasGlobeState } from '../../../../pages/atlas/useAtlasGlobe';
|
||||
import MSegmented from '../../../components/MSegmented';
|
||||
import { M_CARD, M_INNER, MHubAction, MHubEmpty } from './mHubKit';
|
||||
|
||||
/**
|
||||
* Dawarich on the phone, inside the hub sheet: the two questions as a
|
||||
* segmented control, each offer as one tappable row with its facts on a single
|
||||
* line, and one full-width button that writes what is ticked.
|
||||
*/
|
||||
export default function MHubDawarich({ s }: { s: AtlasGlobeState }): React.ReactElement {
|
||||
const d = useDawarichAtlas({ initialTab: s.dawarichSub, onChanged: () => void s.reload() });
|
||||
const { setTab } = d;
|
||||
React.useEffect(() => setTab(s.dawarichSub), [s.dawarichSub, setTab]);
|
||||
const t = s.t;
|
||||
const wishes = d.tab === 'wishes';
|
||||
const day = (iso: string) => new Date(iso).toLocaleDateString(s.language, { day: 'numeric', month: 'short' });
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
<MSegmented
|
||||
value={d.tab}
|
||||
onChange={d.setTab}
|
||||
options={[
|
||||
{
|
||||
value: 'wishes',
|
||||
label: `${t('dawarich.atlas.tab.wishes')}${d.openMatches.length ? ` ${d.openMatches.length}` : ''}`,
|
||||
},
|
||||
{
|
||||
value: 'countries',
|
||||
label: `${t('dawarich.atlas.tab.countries')}${d.offered.length ? ` ${d.offered.length}` : ''}`,
|
||||
},
|
||||
]}
|
||||
/>
|
||||
|
||||
{d.busy ? (
|
||||
<div className={`${M_CARD} flex items-center justify-center gap-2.5 px-4 py-8 text-body text-m-muted`}>
|
||||
<Loader2 size={17} className="animate-spin" />{' '}
|
||||
{t(wishes ? 'dawarich.bucket.scanning' : 'dawarich.atlas.loading')}
|
||||
</div>
|
||||
) : !d.loaded ? (
|
||||
<MHubEmpty
|
||||
Icon={wishes ? Star : Globe2}
|
||||
title={t(wishes ? 'dawarich.bucket.title' : 'dawarich.atlas.title')}
|
||||
hint={t(wishes ? 'dawarich.bucket.description' : 'dawarich.atlas.description')}
|
||||
action={
|
||||
<MHubAction Icon={RefreshCw} onClick={d.run}>
|
||||
{t(wishes ? 'dawarich.bucket.scan' : 'dawarich.atlas.load')}
|
||||
</MHubAction>
|
||||
}
|
||||
/>
|
||||
) : !d.anything ? (
|
||||
<MHubEmpty
|
||||
Icon={wishes ? Star : Globe2}
|
||||
title={t(wishes ? 'dawarich.bucket.noMatches' : 'dawarich.atlas.empty')}
|
||||
action={
|
||||
<MHubAction Icon={RefreshCw} onClick={d.run}>
|
||||
{t('dawarich.again')}
|
||||
</MHubAction>
|
||||
}
|
||||
/>
|
||||
) : (
|
||||
<>
|
||||
<div className={`${M_CARD} flex flex-col gap-1 p-1.5`}>
|
||||
{wishes
|
||||
? d.matches.map((m) => (
|
||||
<Pick
|
||||
key={m.itemId}
|
||||
name={m.name}
|
||||
checked={d.picked.has(m.itemId)}
|
||||
disabled={m.alreadyVisited}
|
||||
onToggle={() => d.togglePicked(m.itemId)}
|
||||
leading={<Star size={15} style={{ color: 'var(--m-st-pending)' }} />}
|
||||
line={
|
||||
m.alreadyVisited
|
||||
? t('dawarich.bucket.alreadyVisited')
|
||||
: m.match
|
||||
? `${day(m.match.at)}, ${formatDuration(m.match.minutes, t)}, ${formatDistance(m.match.distanceMeters, t)}`
|
||||
: t('dawarich.bucket.noMatches')
|
||||
}
|
||||
/>
|
||||
))
|
||||
: d.offered.map((c) => (
|
||||
<Pick
|
||||
key={c.countryCode}
|
||||
name={countryLabel(c.countryCode, c.sourceName, s.language)}
|
||||
checked={d.pickedCountries.has(c.countryCode)}
|
||||
onToggle={() => d.togglePickedCountry(c.countryCode)}
|
||||
leading={<CountryFlag code={c.countryCode} size={18} />}
|
||||
line={c.cities.length ? cityLine(c.cities) : ''}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={d.run}
|
||||
aria-label={t('dawarich.again')}
|
||||
className="grid size-[50px] flex-none place-items-center rounded-[16px] bg-[color:var(--m-ic)] text-m-ink"
|
||||
>
|
||||
<RefreshCw size={18} />
|
||||
</button>
|
||||
<div className="min-w-0 flex-1">
|
||||
<MHubAction Icon={Check} disabled={d.selected === 0 || d.writing} onClick={d.confirm}>
|
||||
{wishes
|
||||
? t('dawarich.bucket.confirm', { count: d.selected })
|
||||
: t('dawarich.atlas.accept', { count: d.selected })}
|
||||
</MHubAction>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{d.loaded &&
|
||||
dawarichNotes(d, t).map((note) => (
|
||||
<p key={note} className="m-0 flex items-start gap-1.5 px-1 text-caption text-m-faint">
|
||||
<Info size={12} className="mt-0.5 flex-none" /> {note}
|
||||
</p>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** One offer: the whole row ticks it; the facts sit on one line under the name. */
|
||||
function Pick({
|
||||
name,
|
||||
line,
|
||||
checked,
|
||||
disabled = false,
|
||||
onToggle,
|
||||
leading,
|
||||
}: {
|
||||
name: string;
|
||||
line: string;
|
||||
checked: boolean;
|
||||
disabled?: boolean;
|
||||
onToggle: () => void;
|
||||
leading: React.ReactNode;
|
||||
}): React.ReactElement {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
role="checkbox"
|
||||
aria-checked={checked}
|
||||
aria-label={name}
|
||||
disabled={disabled}
|
||||
onClick={onToggle}
|
||||
className={`${M_INNER} flex w-full items-center gap-3 px-3 py-3 text-start ${disabled ? 'opacity-60' : ''}`}
|
||||
>
|
||||
<span className="grid size-10 flex-none place-items-center rounded-full bg-[color:var(--m-ic)]">{leading}</span>
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="block truncate text-body font-semibold text-m-ink">{name}</span>
|
||||
{line && <span className="block truncate text-caption text-m-muted">{line}</span>}
|
||||
</span>
|
||||
<span
|
||||
className={`grid size-6 flex-none place-items-center rounded-full border-2 ${checked || disabled ? 'border-[color:var(--m-act)] bg-m-act text-m-actfg' : 'border-[color:var(--m-checkbr)]'}`}
|
||||
>
|
||||
{(checked || disabled) && <Check size={13} strokeWidth={3} />}
|
||||
</span>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
import { Briefcase, Building2, CalendarDays, ChevronRight, Flame, Map as MapIcon, MapPin, Plane } from 'lucide-react';
|
||||
import React from 'react';
|
||||
import { useNavigate } from 'react-router';
|
||||
import { continentCounts, WORLD_COUNTRIES } from '../../../../pages/atlas/atlasHubModel';
|
||||
import type { AtlasGlobeState } from '../../../../pages/atlas/useAtlasGlobe';
|
||||
import MProgress from '../../../components/MProgress';
|
||||
import { M_CARD, MHubDawarichEntry, MHubHero, MHubSection, MHubTiles } from './mHubKit';
|
||||
|
||||
/** The numbers on the phone: countries large, continents as rows of bars, the rest as tiles, the next trip at the foot. */
|
||||
export default function MHubOverview({ s }: { s: AtlasGlobeState }): React.ReactElement {
|
||||
const navigate = useNavigate();
|
||||
const d = s.data;
|
||||
const st = d?.stats;
|
||||
const countries = s.totals.countries;
|
||||
const share = Math.min(1, countries / WORLD_COUNTRIES);
|
||||
const planned = (st?.totalCountriesPlanned ?? 0) + (st?.totalCountriesIdea ?? 0);
|
||||
const continents = continentCounts(d);
|
||||
const maxC = Math.max(1, ...continents.map((c) => c.n));
|
||||
const next = d?.nextTrip as { id: number; title: string; daysUntil?: number } | null | undefined;
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
<MHubHero value={countries} unit={s.t('atlas.countries', { count: countries })}>
|
||||
<MProgress value={share * 100} height={6} />
|
||||
<div className="mt-2 flex items-center justify-between text-caption text-m-muted">
|
||||
<span>{s.t('atlas.globe.worldShare', { share: Math.round(share * 100) })}</span>
|
||||
{planned > 0 && (
|
||||
<span>
|
||||
+{planned} {s.t('atlas.planned')}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</MHubHero>
|
||||
|
||||
{next && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => navigate(`/trips/${next.id}`)}
|
||||
className={`${M_CARD} flex items-center gap-3.5 px-4 py-3.5 text-start active:opacity-80`}
|
||||
>
|
||||
{typeof next.daysUntil === 'number' && (
|
||||
<span className="flex flex-none flex-col items-center rounded-[14px] bg-m-act px-3 py-1.5 text-m-actfg">
|
||||
<span className="text-subtitle font-bold tabular-nums leading-none">{next.daysUntil}</span>
|
||||
<span className="text-[0.625rem] font-semibold">{s.t('atlas.daysLeft')}</span>
|
||||
</span>
|
||||
)}
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="block text-caption text-m-muted">{s.t('atlas.nextTrip')}</span>
|
||||
<span className="block truncate text-body font-bold text-m-ink">{next.title}</span>
|
||||
</span>
|
||||
<ChevronRight size={18} className="text-m-faint" />
|
||||
</button>
|
||||
)}
|
||||
|
||||
<MHubSection title={s.t('atlas.globe.continents')} meta={`${s.totals.continents} / ${continents.length}`}>
|
||||
<div className={`${M_CARD} flex flex-col gap-3 px-4 py-4`}>
|
||||
{continents.map((c) => (
|
||||
<div key={c.name} className="flex items-center gap-3">
|
||||
<span className="w-[38%] truncate text-caption font-semibold text-m-ink">{s.t(c.key)}</span>
|
||||
<div className="h-2 min-w-0 flex-1 overflow-hidden rounded-full bg-[color:var(--m-ic)]">
|
||||
<div
|
||||
className="h-full rounded-full bg-m-act transition-[width] duration-700"
|
||||
style={{ width: `${c.n ? Math.max(6, (c.n / maxC) * 100) : 0}%` }}
|
||||
/>
|
||||
</div>
|
||||
<span className="w-6 text-end text-caption font-bold tabular-nums text-m-ink">{c.n}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</MHubSection>
|
||||
|
||||
{s.dawarichEnabled && (
|
||||
<MHubDawarichEntry
|
||||
title={s.t('atlas.globe.dawarichCountries')}
|
||||
hint={s.t('atlas.globe.dawarichCountriesHint')}
|
||||
onClick={() => s.openDawarich('countries')}
|
||||
/>
|
||||
)}
|
||||
|
||||
<MHubTiles
|
||||
tiles={[
|
||||
{ Icon: MapIcon, value: s.totals.regions, label: s.t('atlas.regions', { count: s.totals.regions }) },
|
||||
{ Icon: Briefcase, value: st?.totalTrips ?? 0, label: s.t('atlas.trips', { count: st?.totalTrips ?? 0 }) },
|
||||
{ Icon: MapPin, value: st?.totalPlaces ?? 0, label: s.t('atlas.places', { count: st?.totalPlaces ?? 0 }) },
|
||||
{ Icon: Building2, value: st?.totalCities ?? 0, label: s.t('atlas.cities', { count: st?.totalCities ?? 0 }) },
|
||||
{ Icon: CalendarDays, value: st?.totalDays ?? 0, label: s.t('atlas.days', { count: st?.totalDays ?? 0 }) },
|
||||
{ Icon: Flame, value: d?.streak ?? 0, label: s.t('atlas.yearsInRow', { count: d?.streak ?? 0 }) },
|
||||
{
|
||||
Icon: Plane,
|
||||
value: d?.tripsThisYear ?? 0,
|
||||
label: `${s.t('atlas.tripsIn', { count: d?.tripsThisYear ?? 0 })} ${new Date().getFullYear()}`,
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
import { ArrowDownRight, ArrowUpRight, Footprints, ListOrdered, Mountain } from 'lucide-react';
|
||||
import React from 'react';
|
||||
import {
|
||||
ActivityStatusLine,
|
||||
BasisBadges,
|
||||
periodLabel,
|
||||
UncountedBadges,
|
||||
} 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 { useTourActivityStats } from '../../../../components/Atlas/tourActivity/useTourActivityStats';
|
||||
import type { AtlasGlobeState } from '../../../../pages/atlas/useAtlasGlobe';
|
||||
import MChip from '../../../components/MChip';
|
||||
import MChipStrip from '../../../components/MChipStrip';
|
||||
import { M_CARD, M_INNER, MHubAction, MHubEmpty, MHubHero, MHubSection, MHubTiles } from './mHubKit';
|
||||
|
||||
/** Tours on the phone: the distance large, tours, climb and descent as three tiles, every type as a row with its bar. */
|
||||
export default function MHubTours({ s }: { s: AtlasGlobeState }): React.ReactElement {
|
||||
const stats = useTourActivityStats(true);
|
||||
const unit = useDistanceUnit();
|
||||
const [open, setOpen] = React.useState(false);
|
||||
const summary = stats.summary;
|
||||
const t = s.t;
|
||||
// The period and the kind of tour as two rows of small chips: the desktop's
|
||||
// pickers would open a list over a phone sheet for a choice of a few words.
|
||||
const filters = (
|
||||
<div className="-mx-4 flex flex-col gap-2">
|
||||
<MChipStrip label={t('tours.stats.period')} className="gap-1.5 px-4">
|
||||
{stats.periods.map((p) => (
|
||||
<MChip key={p} pressable active={stats.period === p} onClick={() => stats.setPeriod(p)}>
|
||||
{periodLabel(p, t)}
|
||||
</MChip>
|
||||
))}
|
||||
</MChipStrip>
|
||||
{stats.types.length > 1 && (
|
||||
<MChipStrip label={t('tours.filter.type')} className="gap-1.5 px-4">
|
||||
{stats.types.map((type) => {
|
||||
const Icon = typeIcon(type);
|
||||
return (
|
||||
<MChip key={type} pressable active={stats.type === type} onClick={() => stats.setType(type)}>
|
||||
<Icon size={12} strokeWidth={2.2} /> {typeLabel(type, t)}
|
||||
</MChip>
|
||||
);
|
||||
})}
|
||||
</MChipStrip>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
if (!summary) {
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
{filters}
|
||||
<div className={`${M_CARD} px-4 py-5`}>
|
||||
<ActivityStatusLine stats={stats} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
const totals = summary.totals;
|
||||
if (totals.count === 0) {
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
{filters}
|
||||
<MHubEmpty Icon={Mountain} title={t(stats.data?.entries.length ? 'tours.stats.none' : 'tours.stats.empty')} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
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 };
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
{filters}
|
||||
<MHubHero value={hero.value} unit={hero.unit || undefined}>
|
||||
<div className="flex flex-wrap items-center gap-1.5">
|
||||
<BasisBadges byBasis={totals.byBasis} />
|
||||
</div>
|
||||
</MHubHero>
|
||||
<MHubTiles
|
||||
cols={3}
|
||||
tiles={[
|
||||
{ Icon: Footprints, value: totals.count, label: t('tours.mode.tours') },
|
||||
{ Icon: ArrowUpRight, value: ascent?.text ?? '0', label: t('tours.detail.ascent') },
|
||||
{ Icon: ArrowDownRight, value: descent?.text ?? '0', label: t('tours.detail.descent') },
|
||||
]}
|
||||
/>
|
||||
{stats.type === 'all' && types.length > 0 && (
|
||||
<MHubSection title={t('atlas.globe.byType')} meta={types.length}>
|
||||
<div className={`${M_CARD} flex flex-col gap-1 p-1.5`}>
|
||||
{types.map((x) => {
|
||||
const Icon = typeIcon(x.type);
|
||||
const d = distanceReading(x, unit);
|
||||
return (
|
||||
<div key={x.type} className={`${M_INNER} flex flex-col gap-2 px-3 py-3`}>
|
||||
<div className="flex items-center gap-3">
|
||||
<span className="grid size-9 flex-none place-items-center rounded-full bg-[color:var(--m-ic)] text-m-muted">
|
||||
<Icon size={16} strokeWidth={1.9} />
|
||||
</span>
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="block truncate text-body font-semibold text-m-ink">{typeLabel(x.type, t)}</span>
|
||||
<span className="block text-caption tabular-nums text-m-muted">
|
||||
{t('atlas.globe.tourCount', { count: x.count })}
|
||||
</span>
|
||||
</span>
|
||||
<span className="text-body font-bold tabular-nums text-m-ink">{d?.text ?? ''}</span>
|
||||
</div>
|
||||
<div className="h-1.5 overflow-hidden rounded-full bg-[color:var(--m-ic)]">
|
||||
<div
|
||||
className="h-full rounded-full bg-m-act"
|
||||
style={{ width: `${Math.max(4, ((x.distanceKm.value ?? 0) / maxKm) * 100)}%` }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</MHubSection>
|
||||
)}
|
||||
<div className="flex flex-wrap items-center gap-1.5">
|
||||
<UncountedBadges upcoming={summary.upcoming} {...uncounted} />
|
||||
</div>
|
||||
{summary.done.length > 0 && (
|
||||
<MHubAction Icon={ListOrdered} onClick={() => setOpen(true)}>
|
||||
{t('tours.stats.showTours')}
|
||||
</MHubAction>
|
||||
)}
|
||||
<TourActivityStatsDialog stats={stats} open={open} onClose={() => setOpen(false)} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
import { ChevronRight, Flag, Globe2, Layers, Map as MapIcon, Plane, Users, X } from 'lucide-react';
|
||||
import React from 'react';
|
||||
import BadgeMedal from '../../../../components/AtlasGlobe/BadgeMedal';
|
||||
import { medalLabel } from '../../../../pages/atlas/AtlasGlobeBadges';
|
||||
import type { AtlasGlobeState } from '../../../../pages/atlas/useAtlasGlobe';
|
||||
import MIconBtn from '../../../components/MIconBtn';
|
||||
import MSheet from '../../../components/MSheet';
|
||||
import MToggle from '../../../components/MToggle';
|
||||
import { M_CARD, M_INNER, MHubAction, MHubEmpty, MHubSection, MHubTiles } from './mHubKit';
|
||||
|
||||
/** Gold, silver and bronze for the first three places. */
|
||||
const PODIUM = ['#f5c542', '#c9d1db', '#d08a4f']; // theme-lint-disable: podium medal colours
|
||||
|
||||
function Avatar({
|
||||
name,
|
||||
url,
|
||||
size,
|
||||
}: {
|
||||
name: string;
|
||||
url: string | null | undefined;
|
||||
size: number;
|
||||
}): React.ReactElement {
|
||||
return url ? (
|
||||
<img src={url} alt="" className="flex-none rounded-full object-cover" style={{ width: size, height: size }} />
|
||||
) : (
|
||||
<span
|
||||
className="grid flex-none place-items-center rounded-full bg-m-act font-bold text-m-actfg"
|
||||
style={{ width: size, height: size }}
|
||||
>
|
||||
{name.slice(0, 1).toUpperCase()}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
/** The travellers on the phone: being visible as a switch, the ranking as rows, a profile as its own sheet. */
|
||||
export default function MHubTravellers({ s }: { s: AtlasGlobeState }): React.ReactElement {
|
||||
const { loadPeople } = s;
|
||||
React.useEffect(() => {
|
||||
loadPeople();
|
||||
}, [loadPeople]);
|
||||
const rows = s.ranking;
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
<div className={`${M_CARD} flex items-center gap-3 px-4 py-3.5`}>
|
||||
<span className="min-w-0 flex-1 text-body font-semibold text-m-ink">{s.t('atlas.globe.visibleToOthers')}</span>
|
||||
<MToggle
|
||||
checked={!s.hidden}
|
||||
onChange={() => s.setHidden(!s.hidden)}
|
||||
ariaLabel={s.t('atlas.globe.visibleToOthers')}
|
||||
/>
|
||||
</div>
|
||||
{!rows ? null : rows.length <= 1 ? (
|
||||
<MHubEmpty Icon={Users} title={s.t('atlas.globe.noTravellers')} />
|
||||
) : (
|
||||
<MHubSection title={s.t('atlas.globe.ranking')} meta={rows.length}>
|
||||
<ol className={`${M_CARD} m-0 flex list-none flex-col gap-1 p-1.5`}>
|
||||
{rows.map((p, i) => {
|
||||
const isMe = p.id === s.me?.id;
|
||||
return (
|
||||
<li key={p.id}>
|
||||
<button
|
||||
type="button"
|
||||
disabled={isMe}
|
||||
onClick={() => s.setProfileId(p.id)}
|
||||
className={`${M_INNER} flex w-full items-center gap-3 px-3 py-2.5 text-start ${isMe ? 'bg-[color:var(--m-ic)]' : 'active:opacity-80'}`}
|
||||
>
|
||||
<span
|
||||
className={`grid size-7 flex-none place-items-center rounded-full text-caption font-bold tabular-nums ${i < 3 ? 'text-m-ink' : 'text-m-faint'}`}
|
||||
style={
|
||||
i < 3
|
||||
? {
|
||||
background: `color-mix(in srgb, ${PODIUM[i]} 30%, transparent)`,
|
||||
boxShadow: `inset 0 0 0 1.5px ${PODIUM[i]}`,
|
||||
}
|
||||
: undefined
|
||||
}
|
||||
>
|
||||
{i + 1}
|
||||
</span>
|
||||
<Avatar name={p.username} url={p.avatar_url} size={36} />
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="flex min-w-0 items-center gap-1.5">
|
||||
<span className="truncate text-body font-semibold text-m-ink">{p.username}</span>
|
||||
{isMe && (
|
||||
<span className="flex-none rounded-full bg-m-act px-1.5 py-px text-[0.625rem] font-bold text-m-actfg">
|
||||
{s.t('atlas.globe.you')}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
<span className="flex items-center gap-2.5 text-caption tabular-nums text-m-muted">
|
||||
<span className="inline-flex items-center gap-1">
|
||||
<Globe2 size={11} /> {p.continents}
|
||||
</span>
|
||||
<span className="inline-flex items-center gap-1">
|
||||
<MapIcon size={11} /> {p.regions}
|
||||
</span>
|
||||
</span>
|
||||
</span>
|
||||
<span className="flex w-12 flex-none flex-col items-end">
|
||||
<span className="text-subtitle font-bold tabular-nums leading-none text-m-ink">
|
||||
{p.countries}
|
||||
</span>
|
||||
<span className="mt-0.5 text-[0.625rem] text-m-muted">{s.t('atlas.countries')}</span>
|
||||
</span>
|
||||
<ChevronRight
|
||||
size={16}
|
||||
className={`flex-none text-m-faint ${isMe ? 'invisible' : ''}`}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</button>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ol>
|
||||
</MHubSection>
|
||||
)}
|
||||
<MSheet
|
||||
open={!!s.profile}
|
||||
onClose={() => s.setProfileId(null)}
|
||||
variant="bottom"
|
||||
ariaLabel={s.profile?.username ?? ''}
|
||||
>
|
||||
{s.profile && <ProfileSheet s={s} />}
|
||||
</MSheet>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ProfileSheet({ s }: { s: AtlasGlobeState }): React.ReactElement | null {
|
||||
const p = s.profile;
|
||||
if (!p) return null;
|
||||
return (
|
||||
<div className="flex min-h-0 flex-col overflow-y-auto px-5 pb-6 pt-5">
|
||||
<div className="flex items-center gap-3">
|
||||
<Avatar name={p.username} url={p.avatar_url} size={52} />
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="truncate text-title font-bold text-m-ink">{p.username}</div>
|
||||
<div className="text-caption text-m-muted">
|
||||
{s.t('atlas.globe.collected', { earned: p.badges.length, total: s.badges.length })}
|
||||
</div>
|
||||
</div>
|
||||
<MIconBtn variant="neutral" size={34} ariaLabel={s.t('common.close')} onClick={() => s.setProfileId(null)}>
|
||||
<X size={17} />
|
||||
</MIconBtn>
|
||||
</div>
|
||||
<div className="mt-4">
|
||||
<MHubTiles
|
||||
tiles={[
|
||||
{ Icon: Flag, value: p.countries, label: s.t('atlas.countries') },
|
||||
{ Icon: Globe2, value: p.continents, label: s.t('atlas.globe.continents') },
|
||||
{ Icon: MapIcon, value: p.regions, label: s.t('atlas.regions') },
|
||||
{ Icon: Plane, value: `${Math.round(p.flightKm / 1000)}k`, label: s.t('atlas.globe.flightKm') },
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
<div className="mt-4">
|
||||
{p.badges.length ? (
|
||||
<MHubSection title={s.t('atlas.globe.badges')} meta={p.badges.length}>
|
||||
<div className={`${M_CARD} grid grid-cols-3 gap-1 p-2`}>
|
||||
{p.badges.map((b) => {
|
||||
const params: Record<string, string | number> = { ...(b.params ?? {}) };
|
||||
if (typeof params.country === 'string')
|
||||
params.country = s.resolveName(params.country) || params.country;
|
||||
return (
|
||||
<div key={b.id} className="flex flex-col items-center gap-1 px-1 py-2 text-center">
|
||||
<BadgeMedal
|
||||
id={`mp${p.id}-${b.id}`}
|
||||
motif={b.motif}
|
||||
tier={b.tier}
|
||||
earned
|
||||
size={68}
|
||||
label={medalLabel({ motif: b.motif, target: b.target, current: b.target })}
|
||||
/>
|
||||
<span className="line-clamp-2 text-caption font-semibold leading-tight text-m-ink">
|
||||
{s.t(b.titleKey, params)}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</MHubSection>
|
||||
) : (
|
||||
<MHubEmpty Icon={Users} title={s.t('atlas.globe.noBadgesYet')} />
|
||||
)}
|
||||
</div>
|
||||
<div className="mt-5">
|
||||
<MHubAction
|
||||
Icon={Layers}
|
||||
onClick={() => {
|
||||
s.setProfileId(null);
|
||||
s.startCompare(p);
|
||||
}}
|
||||
>
|
||||
{s.t('atlas.globe.compareOnGlobe')}
|
||||
</MHubAction>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,383 @@
|
||||
import { getIntlLanguage } from '@trek/shared';
|
||||
import {
|
||||
CalendarCheck,
|
||||
CalendarClock,
|
||||
ChevronLeft,
|
||||
ChevronRight,
|
||||
Flag,
|
||||
Loader2,
|
||||
MapPin,
|
||||
Navigation,
|
||||
PenLine,
|
||||
Plus,
|
||||
Radar,
|
||||
Search,
|
||||
Star,
|
||||
Trash2,
|
||||
Undo2,
|
||||
X,
|
||||
} from 'lucide-react';
|
||||
import React from 'react';
|
||||
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 MIconBtn from '../../../components/MIconBtn';
|
||||
import MProgress from '../../../components/MProgress';
|
||||
import MSheet from '../../../components/MSheet';
|
||||
import MSwipeRow from '../../../components/MSwipeRow';
|
||||
import { M_CARD, M_FIELD, M_INNER, MHubAction, MHubDawarichEntry, MHubEmpty, MHubHero, MHubSection } from './mHubKit';
|
||||
|
||||
/** The wishlist on the phone: the headline, one button to add, then open and reached wishes as rows that swipe. */
|
||||
export default function MHubWishlist({ s }: { s: AtlasGlobeState }): React.ReactElement {
|
||||
const b = s.bucketState;
|
||||
const when = whenLabeller(s.language);
|
||||
const items = b.bucketList;
|
||||
const { open, reached, countries, nextDated } = splitWishes(items);
|
||||
const add = () => b.setShowBucketAdd(true);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
{items.length === 0 ? (
|
||||
<MHubEmpty
|
||||
Icon={Star}
|
||||
title={s.t('atlas.bucketEmpty')}
|
||||
hint={s.t('atlas.bucketEmptyHint')}
|
||||
action={
|
||||
<MHubAction Icon={Plus} onClick={add}>
|
||||
{s.t('atlas.globe.newWish')}
|
||||
</MHubAction>
|
||||
}
|
||||
/>
|
||||
) : (
|
||||
<>
|
||||
<MHubHero value={items.length} unit={s.t('atlas.globe.wishes', { count: items.length })}>
|
||||
<MProgress value={(reached.length / items.length) * 100} height={6} />
|
||||
<div className="mt-2 flex items-center justify-between gap-3 text-caption text-m-muted">
|
||||
<span>{s.t('atlas.globe.wishesReached', { done: reached.length, count: items.length })}</span>
|
||||
<span className="inline-flex items-center gap-1">
|
||||
<Flag size={12} /> {countries}
|
||||
</span>
|
||||
</div>
|
||||
{nextDated && (
|
||||
<div className={`${M_INNER} mt-3 flex items-center gap-2.5 px-3 py-2.5`}>
|
||||
<CalendarClock size={15} className="text-m-muted" />
|
||||
<span className="min-w-0 flex-1 truncate text-caption font-semibold text-m-ink">{nextDated.name}</span>
|
||||
<span className="text-caption tabular-nums text-m-muted">{when(nextDated.target_date)}</span>
|
||||
</div>
|
||||
)}
|
||||
</MHubHero>
|
||||
<MHubAction Icon={Plus} onClick={add}>
|
||||
{s.t('atlas.globe.newWish')}
|
||||
</MHubAction>
|
||||
{s.dawarichEnabled && (
|
||||
<MHubDawarichEntry
|
||||
title={s.t('atlas.globe.dawarichWishes')}
|
||||
hint={s.t('atlas.globe.dawarichWishesHint')}
|
||||
onClick={() => s.openDawarich('wishes')}
|
||||
/>
|
||||
)}
|
||||
{open.length > 0 && (
|
||||
<MHubSection title={s.t('atlas.globe.wishesOpen')} meta={open.length}>
|
||||
<div className={`${M_CARD} flex flex-col gap-1 p-1.5`}>
|
||||
{open.map((item) => (
|
||||
<WishRow key={item.id} s={s} item={item} when={when(item.target_date)} />
|
||||
))}
|
||||
</div>
|
||||
</MHubSection>
|
||||
)}
|
||||
{reached.length > 0 && (
|
||||
<MHubSection title={s.t('atlas.globe.wishesDone')} meta={reached.length}>
|
||||
<div className={`${M_CARD} flex flex-col gap-1 p-1.5`}>
|
||||
{reached.map((item) => (
|
||||
<WishRow key={item.id} s={s} item={item} when={when(item.target_date)} />
|
||||
))}
|
||||
</div>
|
||||
</MHubSection>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
<MSheet
|
||||
open={b.showBucketAdd}
|
||||
onClose={b.resetBucketAdd}
|
||||
variant="bottom"
|
||||
ariaLabel={s.t('atlas.globe.newWish')}
|
||||
discardGuard={b.bucketForm}
|
||||
>
|
||||
{b.showBucketAdd && <AddWishSheet s={s} />}
|
||||
</MSheet>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function WishRow({ s, item, when }: { s: AtlasGlobeState; item: BucketItem; when: string | null }): React.ReactElement {
|
||||
const b = s.bucketState;
|
||||
const done = !!item.visited_at;
|
||||
const a2 = wishCountry(item.country_code);
|
||||
const country = a2 ? s.resolveName(a2) : null;
|
||||
const byRecording = item.visited_source === 'dawarich';
|
||||
const hasPlace = !!(item.lat && item.lng);
|
||||
const sub = [country && country !== item.name ? country : null, item.notes].filter(Boolean).join(', ');
|
||||
return (
|
||||
<MSwipeRow
|
||||
surface="var(--m-inner)"
|
||||
inset={4}
|
||||
leading={
|
||||
hasPlace
|
||||
? {
|
||||
label: s.t('atlas.globe.showOnGlobe'),
|
||||
icon: Navigation,
|
||||
tone: 'accent',
|
||||
onAction: () => s.flyToPoint(Number(item.lng), Number(item.lat)),
|
||||
}
|
||||
: undefined
|
||||
}
|
||||
trailing={[
|
||||
{
|
||||
label: s.t('atlas.removeFromBucket'),
|
||||
icon: Trash2,
|
||||
tone: 'danger',
|
||||
onAction: () => void b.handleDeleteBucketItem(item.id),
|
||||
},
|
||||
...(done && byRecording
|
||||
? [
|
||||
{
|
||||
label: s.t('dawarich.bucket.clearVisit'),
|
||||
icon: Undo2,
|
||||
tone: 'neutral' as const,
|
||||
onAction: () => void b.handleClearBucketVisit(item.id),
|
||||
},
|
||||
]
|
||||
: []),
|
||||
]}
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => hasPlace && s.flyToPoint(Number(item.lng), Number(item.lat))}
|
||||
className={`${M_INNER} flex w-full items-center gap-3 px-3 py-3 text-start`}
|
||||
>
|
||||
<span className="grid size-10 flex-none place-items-center rounded-full bg-[color:var(--m-ic)]">
|
||||
{a2 ? <CountryFlag code={a2} size={20} /> : <Star size={16} style={{ color: 'var(--m-st-pending)' }} />}
|
||||
</span>
|
||||
<span className="min-w-0 flex-1">
|
||||
<span
|
||||
className={`block truncate text-body font-semibold ${done ? 'text-m-muted line-through' : 'text-m-ink'}`}
|
||||
>
|
||||
{item.name}
|
||||
</span>
|
||||
{sub && <span className="block truncate text-caption text-m-muted">{sub}</span>}
|
||||
</span>
|
||||
{done ? (
|
||||
<span
|
||||
className="inline-flex flex-none items-center gap-1 rounded-full bg-[color:var(--m-ic)] px-2 py-1 text-caption font-semibold tabular-nums"
|
||||
style={{ color: 'var(--m-st-confirmed)' }}
|
||||
>
|
||||
{byRecording ? <Radar size={11} /> : <CalendarCheck size={11} />} {visitedOn(item, s.language)}
|
||||
</span>
|
||||
) : (
|
||||
when && (
|
||||
<span className="inline-flex flex-none items-center gap-1 rounded-full bg-[color:var(--m-ic)] px-2 py-1 text-caption font-semibold tabular-nums text-m-muted">
|
||||
<CalendarClock size={11} /> {when}
|
||||
</span>
|
||||
)
|
||||
)}
|
||||
</button>
|
||||
</MSwipeRow>
|
||||
);
|
||||
}
|
||||
|
||||
/** 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 label = (text: string) => (
|
||||
<div className="px-1 text-caption font-bold uppercase tracking-wide text-m-muted">{text}</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="flex min-h-0 flex-col">
|
||||
<div className="flex items-center gap-3 px-5 pb-2 pt-5">
|
||||
<div className="min-w-0 flex-1 text-title font-bold text-m-ink">{s.t('atlas.globe.newWish')}</div>
|
||||
<MIconBtn variant="neutral" size={34} ariaLabel={s.t('common.cancel')} onClick={b.resetBucketAdd}>
|
||||
<X size={17} />
|
||||
</MIconBtn>
|
||||
</div>
|
||||
<div className="flex min-h-0 flex-1 flex-col gap-5 overflow-y-auto px-5 pb-4 pt-2">
|
||||
<div className="flex flex-col gap-2">
|
||||
{label(s.t('atlas.globe.wishWhere'))}
|
||||
{picked ? (
|
||||
<div className={`${M_INNER} flex items-center gap-3 px-3 py-3`}>
|
||||
<span
|
||||
className="grid size-10 flex-none place-items-center rounded-full bg-[color:var(--m-ic)]"
|
||||
style={{ color: 'var(--m-st-pending)' }}
|
||||
>
|
||||
{b.bucketForm.lat ? <MapPin size={17} /> : <Star size={16} />}
|
||||
</span>
|
||||
<span className="min-w-0 flex-1">
|
||||
<input
|
||||
value={b.bucketForm.name}
|
||||
onChange={(e) => b.setBucketForm({ ...b.bucketForm, name: e.target.value })}
|
||||
aria-label={s.t('atlas.bucketNamePlaceholder')}
|
||||
className="w-full bg-transparent text-body font-bold text-m-ink outline-none"
|
||||
/>
|
||||
<span className="block truncate text-caption text-m-muted">
|
||||
{b.bucketForm.address ||
|
||||
s.t(b.bucketForm.lat ? 'atlas.globe.showOnGlobe' : 'atlas.globe.wishNoPlace')}
|
||||
</span>
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => b.setBucketForm({ ...b.bucketForm, name: '', lat: '', lng: '', address: undefined })}
|
||||
className="rounded-full bg-[color:var(--m-ic)] px-3 py-1.5 text-caption font-semibold text-m-ink"
|
||||
>
|
||||
{s.t('atlas.globe.change')}
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div className="relative">
|
||||
<Search
|
||||
size={16}
|
||||
className="pointer-events-none absolute start-3.5 top-1/2 -translate-y-1/2 text-m-muted"
|
||||
/>
|
||||
<input
|
||||
value={query}
|
||||
onChange={(e) => setQuery(e.target.value)}
|
||||
placeholder={s.t('atlas.globe.wishSearch')}
|
||||
enterKeyHint="search"
|
||||
className={`${M_FIELD} ps-10`}
|
||||
/>
|
||||
{placesLoading && (
|
||||
<Loader2 size={16} className="absolute end-3.5 top-1/2 -translate-y-1/2 animate-spin text-m-muted" />
|
||||
)}
|
||||
</div>
|
||||
{(placeHits.length > 0 || query.trim()) && (
|
||||
<div className={`${M_CARD} flex flex-col p-1`}>
|
||||
{placeHits.map((p) => (
|
||||
<button
|
||||
key={`${p.lat},${p.lng}`}
|
||||
type="button"
|
||||
onClick={() => b.handleSelectBucketPoi(p)}
|
||||
className="flex items-center gap-3 rounded-[14px] px-3 py-3 text-start active:bg-[color:var(--m-ic)]"
|
||||
>
|
||||
<MapPin size={16} className="flex-none text-m-muted" />
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="block truncate text-body font-semibold text-m-ink">{p.name}</span>
|
||||
{p.address && <span className="block truncate text-caption text-m-muted">{p.address}</span>}
|
||||
</span>
|
||||
</button>
|
||||
))}
|
||||
{query.trim() && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={takeName}
|
||||
className="flex items-center gap-3 rounded-[14px] px-3 py-3 text-start text-m-muted active:bg-[color:var(--m-ic)]"
|
||||
>
|
||||
<PenLine size={16} className="flex-none" />
|
||||
<span className="truncate text-body">
|
||||
{s.t('atlas.globe.wishJustName', { name: query.trim() })}
|
||||
</span>
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-2">
|
||||
{label(s.t('atlas.globe.wishWhen'))}
|
||||
<div className="flex items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
b.setBucketPoiYear(0);
|
||||
b.setBucketPoiMonth(0);
|
||||
}}
|
||||
aria-pressed={year === 0}
|
||||
className={`rounded-full px-4 py-2.5 text-body font-semibold ${year === 0 ? 'bg-m-act text-m-actfg' : 'bg-[color:var(--m-ic)] text-m-ink'}`}
|
||||
>
|
||||
{s.t('atlas.globe.someday')}
|
||||
</button>
|
||||
<div
|
||||
className={`flex flex-1 items-center justify-between rounded-full p-1 ${year ? 'bg-m-act text-m-actfg' : 'bg-[color:var(--m-ic)] text-m-ink'}`}
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
aria-label={s.t('atlas.globe.yearEarlier')}
|
||||
onClick={() => b.setBucketPoiYear((year || thisYear) - 1)}
|
||||
className="grid size-9 place-items-center rounded-full"
|
||||
>
|
||||
<ChevronLeft size={17} />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => b.setBucketPoiYear(year || thisYear)}
|
||||
className="text-body font-bold tabular-nums"
|
||||
>
|
||||
{year || thisYear}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
aria-label={s.t('atlas.globe.yearLater')}
|
||||
onClick={() => b.setBucketPoiYear((year || thisYear) + 1)}
|
||||
className="grid size-9 place-items-center rounded-full"
|
||||
>
|
||||
<ChevronRight size={17} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
className={`grid grid-cols-4 gap-1.5 ${year ? '' : 'pointer-events-none opacity-40'}`}
|
||||
aria-disabled={!year}
|
||||
>
|
||||
{months.map((m, i) => {
|
||||
const on = month === i + 1;
|
||||
return (
|
||||
<button
|
||||
key={m}
|
||||
type="button"
|
||||
aria-pressed={on}
|
||||
onClick={() => b.setBucketPoiMonth(on ? 0 : i + 1)}
|
||||
className={`rounded-[12px] py-2.5 text-caption font-semibold ${on ? 'bg-m-act text-m-actfg' : 'bg-[color:var(--m-ic)] text-m-ink'}`}
|
||||
>
|
||||
{m}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-2">
|
||||
{label(s.t('atlas.globe.wishNote'))}
|
||||
<textarea
|
||||
rows={3}
|
||||
value={b.bucketForm.notes}
|
||||
onChange={(e) => b.setBucketForm({ ...b.bucketForm, notes: e.target.value })}
|
||||
placeholder={s.t('atlas.bucketNotesPlaceholder')}
|
||||
className={`${M_FIELD} resize-none`}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="border-t border-[color:var(--m-rowbr)] px-5 pb-5 pt-3">
|
||||
<MHubAction Icon={Star} disabled={!b.bucketForm.name.trim()} onClick={() => void b.handleAddBucketItem()}>
|
||||
{s.t('atlas.globe.wishSave')}
|
||||
</MHubAction>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
import { ChevronRight, type LucideIcon } from 'lucide-react';
|
||||
import React from 'react';
|
||||
import DawarichIcon from '../../../../components/shared/DawarichIcon';
|
||||
|
||||
/**
|
||||
* The phone's own pieces for the Atlas hub, on the mobile tokens (--m-*): a
|
||||
* glass card, a large figure, tiles set into a card, a section head and an
|
||||
* empty state. Sized for a thumb and a narrow column, not shrunk desktop parts.
|
||||
*/
|
||||
|
||||
export const M_CARD = 'rounded-[22px] border border-[color:var(--m-cbr)] bg-[color:var(--m-card)]';
|
||||
export const M_INNER = 'rounded-[16px] border border-[color:var(--m-inbr)] bg-[color:var(--m-inner)]';
|
||||
export const M_FIELD =
|
||||
'w-full rounded-[14px] border border-[color:var(--m-rowbr)] bg-[color:var(--m-inner)] px-3.5 py-3 text-body text-m-ink outline-none placeholder:text-m-faint';
|
||||
|
||||
export function MHubHero({
|
||||
value,
|
||||
unit,
|
||||
children,
|
||||
}: {
|
||||
value: React.ReactNode;
|
||||
unit?: React.ReactNode;
|
||||
children?: React.ReactNode;
|
||||
}): React.ReactElement {
|
||||
return (
|
||||
<div className={`${M_CARD} relative overflow-hidden px-5 pb-5 pt-4`}>
|
||||
<div
|
||||
aria-hidden="true"
|
||||
className="pointer-events-none absolute -end-12 -top-12 size-40 rounded-full opacity-70"
|
||||
style={{
|
||||
background: 'radial-gradient(circle, color-mix(in srgb, var(--m-act) 14%, transparent), transparent 70%)',
|
||||
}}
|
||||
/>
|
||||
<div className="relative flex items-end gap-2">
|
||||
<span className="text-[3.25rem] font-bold tabular-nums leading-none tracking-tight text-m-ink">{value}</span>
|
||||
{unit && <span className="mb-1 text-subtitle font-semibold text-m-muted">{unit}</span>}
|
||||
</div>
|
||||
{children && <div className="relative mt-3.5">{children}</div>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export interface MHubTileData {
|
||||
Icon: LucideIcon;
|
||||
value: React.ReactNode;
|
||||
label: string;
|
||||
}
|
||||
|
||||
export function MHubTiles({ tiles, cols = 2 }: { tiles: MHubTileData[]; cols?: 2 | 3 }): React.ReactElement {
|
||||
return (
|
||||
<div className={`${M_CARD} grid gap-1.5 p-1.5 ${cols === 3 ? 'grid-cols-3' : 'grid-cols-2'}`}>
|
||||
{tiles.map(({ Icon, value, label }, i) => {
|
||||
// An odd tile out takes the whole row instead of leaving a hole beside it.
|
||||
const wide = cols === 2 && tiles.length % 2 === 1 && i === tiles.length - 1;
|
||||
if (cols === 3) {
|
||||
// Three across leaves a third of a phone: no symbol, the value on one
|
||||
// line, the label allowed two lines instead of an ellipsis.
|
||||
return (
|
||||
<div key={label} className={`${M_INNER} flex min-w-0 flex-col gap-1 px-2.5 py-2.5`}>
|
||||
<span className="whitespace-nowrap text-body font-bold tabular-nums leading-tight text-m-ink">
|
||||
{value}
|
||||
</span>
|
||||
<span className="line-clamp-2 text-[0.6875rem] leading-tight text-m-muted">{label}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<div
|
||||
key={label}
|
||||
className={`${M_INNER} relative flex min-h-[78px] items-center gap-2 overflow-hidden px-3.5 py-3 ${wide ? 'col-span-2' : ''}`}
|
||||
>
|
||||
<span className="relative min-w-0 flex-1">
|
||||
<span className="block text-title font-bold tabular-nums leading-tight text-m-ink">{value}</span>
|
||||
<span className="block truncate text-caption text-m-muted">{label}</span>
|
||||
</span>
|
||||
<Icon
|
||||
size={cols === 3 ? 22 : 30}
|
||||
strokeWidth={1.6}
|
||||
className="flex-none text-m-faint opacity-70"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function MHubSection({
|
||||
title,
|
||||
meta,
|
||||
action,
|
||||
children,
|
||||
}: {
|
||||
title: string;
|
||||
meta?: React.ReactNode;
|
||||
action?: React.ReactNode;
|
||||
children: React.ReactNode;
|
||||
}): React.ReactElement {
|
||||
return (
|
||||
<section className="flex flex-col gap-2.5">
|
||||
<div className="flex items-center justify-between gap-3 px-1">
|
||||
<h3 className="m-0 text-body font-bold text-m-ink">{title}</h3>
|
||||
<div className="flex items-center gap-2">
|
||||
{meta != null && <span className="text-caption font-semibold tabular-nums text-m-muted">{meta}</span>}
|
||||
{action}
|
||||
</div>
|
||||
</div>
|
||||
{children}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
export function MHubEmpty({
|
||||
Icon,
|
||||
title,
|
||||
hint,
|
||||
action,
|
||||
}: {
|
||||
Icon: LucideIcon;
|
||||
title: string;
|
||||
hint?: string;
|
||||
action?: React.ReactNode;
|
||||
}): React.ReactElement {
|
||||
return (
|
||||
<div className={`${M_CARD} flex flex-col items-center gap-2 px-6 py-9 text-center`}>
|
||||
<span className="grid size-12 place-items-center rounded-full bg-[color:var(--m-ic)] text-m-muted">
|
||||
<Icon size={21} strokeWidth={1.8} />
|
||||
</span>
|
||||
<div className="text-body font-bold text-m-ink">{title}</div>
|
||||
{hint && <div className="text-caption text-m-muted">{hint}</div>}
|
||||
{action && <div className="mt-2">{action}</div>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** The way to Dawarich (addon) on the phone: logo, what it does here, chevron. */
|
||||
export function MHubDawarichEntry({
|
||||
title,
|
||||
hint,
|
||||
onClick,
|
||||
}: {
|
||||
title: string;
|
||||
hint: string;
|
||||
onClick: () => void;
|
||||
}): React.ReactElement {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClick}
|
||||
className={`${M_CARD} flex items-center gap-3 px-4 py-3.5 text-start active:opacity-80`}
|
||||
>
|
||||
<span className="flex size-10 flex-none overflow-hidden rounded-full">
|
||||
<DawarichIcon size={40} />
|
||||
</span>
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="line-clamp-2 block text-body font-semibold leading-tight text-m-ink">{title}</span>
|
||||
<span className="mt-0.5 line-clamp-2 block text-caption leading-snug text-m-muted">{hint}</span>
|
||||
</span>
|
||||
<ChevronRight size={17} className="flex-none text-m-faint" />
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
/** The one strong action of a tab, full width, in the phone's action colour. */
|
||||
export function MHubAction({
|
||||
onClick,
|
||||
Icon,
|
||||
children,
|
||||
disabled,
|
||||
}: {
|
||||
onClick: () => void;
|
||||
Icon?: LucideIcon;
|
||||
children: React.ReactNode;
|
||||
disabled?: boolean;
|
||||
}): React.ReactElement {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClick}
|
||||
disabled={disabled}
|
||||
className="flex w-full items-center justify-center gap-2 rounded-[16px] bg-m-act px-4 py-3.5 text-body font-semibold text-m-actfg disabled:opacity-40"
|
||||
>
|
||||
{Icon && <Icon size={16} strokeWidth={2.2} />}
|
||||
{children}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user