mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 08:30:05 +00:00
refactor(weather): share the day weather anchor and icon map between desktop and phone
The day plan, the day panel, the phone timeline and the phone day sheet read the day local weather anchor from dayWeatherAnchor, and every weather icon comes from one map in weatherIcons.
This commit is contained in:
@@ -7,7 +7,8 @@ import { fmtTransitDuration } from '../../../../components/Planner/transitDispla
|
||||
import { routeModeIcon } from '../../../../components/Planner/routeModes'
|
||||
import { formatTime } from '../../../../utils/formatters'
|
||||
import { useMPlanTimeline, type MPlanTimelineController } from './useMPlanTimeline'
|
||||
import { cityPillsForDay, weatherIconFor } from './planTimelineModel'
|
||||
import { cityPillsForDay } from './planTimelineModel'
|
||||
import { weatherIconFor } from '../../../../components/Weather/weatherIcons'
|
||||
import type { HotelChip, PlanRow } from './planTimelineModel'
|
||||
import { useMPlanDragReorder } from './useMPlanDragReorder'
|
||||
import { useTouchDragBridge } from '../../../../hooks/useTouchDragBridge'
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import { Cloud, CloudDrizzle, CloudLightning, CloudRain, CloudSnow, Sun, Wind } from 'lucide-react'
|
||||
import type { LucideIcon } from 'lucide-react'
|
||||
import {
|
||||
TRANSPORT_TYPES, getAssignmentReservations, getDisplayTimeForDay, getSpanPhase, getTransportRouteEndpoints, hidesOnMiddleDay,
|
||||
parseTimeToMinutes,
|
||||
@@ -338,12 +336,3 @@ export function breaksChronology(
|
||||
.filter((m): m is number => m != null)
|
||||
return times.some((m, i) => i > 0 && m < times[i - 1])
|
||||
}
|
||||
|
||||
const WEATHER_ICON_MAP: Record<string, LucideIcon> = {
|
||||
Clear: Sun, Clouds: Cloud, Rain: CloudRain, Drizzle: CloudDrizzle,
|
||||
Thunderstorm: CloudLightning, Snow: CloudSnow, Mist: Wind, Fog: Wind, Haze: Wind,
|
||||
}
|
||||
|
||||
export function weatherIconFor(main: string | undefined): LucideIcon {
|
||||
return (main && WEATHER_ICON_MAP[main]) || Cloud
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import { useRouteCalculation } from '../../../../hooks/useRouteCalculation'
|
||||
import { assignmentsApi, reservationsApi, weatherApi } from '../../../../api/client'
|
||||
import { useRouteModeOptions } from '../../../../components/Planner/routeModes'
|
||||
import { getDayBookendHotels } from '../../../../utils/dayOrder'
|
||||
import { dayWeatherAnchor } from '../../../../utils/dayWeather'
|
||||
import { getDisplayTimeForDay, getMergedItems, getTransportForDay, hasCarrierEndpointOnDay, isCarrierTransport } from '../../../../utils/dayMerge'
|
||||
import { dayCoMapsUrl, dayExportStops, dayGoogleMapsUrl, optimizeDayOrder, type DayCarrier } from '../lib/dayRoute'
|
||||
import { buildTransitLeg, buildTransitNameIndex, type TransitLeg } from '../../../../components/Planner/transitLeg'
|
||||
@@ -107,13 +108,12 @@ export function useMPlanTimeline(planner: TripPlanner) {
|
||||
|
||||
// ── Weather chip — anchored to the day's first located stop, else its hotel ──
|
||||
const weatherAnchor = useMemo<{ lat: number; lng: number; name: string | null } | null>(() => {
|
||||
const located = dayAssignments.find(a => a.place?.lat != null && a.place?.lng != null)
|
||||
if (located) return { lat: located.place!.lat!, lng: located.place!.lng!, name: located.place!.name ?? null }
|
||||
const hotel = day ? getDayBookendHotels(day, days, tripAccommodations).morning : undefined
|
||||
if (hotel && hotel.place_lat != null && hotel.place_lng != null) {
|
||||
return { lat: hotel.place_lat, lng: hotel.place_lng, name: hotel.place_name ?? null }
|
||||
}
|
||||
return null
|
||||
const { lat, lng, name } = dayWeatherAnchor(
|
||||
dayAssignments,
|
||||
() => (day ? getDayBookendHotels(day, days, tripAccommodations).morning : undefined),
|
||||
a => a.place?.lat != null && a.place?.lng != null,
|
||||
)
|
||||
return lat != null && lng != null ? { lat, lng, name } : null
|
||||
}, [day, dayAssignments, days, tripAccommodations])
|
||||
|
||||
const [weather, setWeather] = useState<WeatherResult | null>(null)
|
||||
|
||||
@@ -18,7 +18,8 @@ import { dayCoMapsUrl, dayGoogleMapsUrl, optimizeDayOrder } from '../lib/dayRout
|
||||
import GoogleMapsIcon from '../../../../components/shared/GoogleMapsIcon'
|
||||
import { BlurredCode } from '../../../../components/shared/BookingCode'
|
||||
import { splitNoteTime } from '../lib/dayNotes'
|
||||
import { weatherIconFor } from '../plan/planTimelineModel'
|
||||
import { weatherIconFor } from '../../../../components/Weather/weatherIcons'
|
||||
import { dayWeatherAnchor } from '../../../../utils/dayWeather'
|
||||
import type { Assignment, DayNote, Reservation } from '../../../../types'
|
||||
import { Eyebrow, INNER_CLS, StatBox, TileHeader, displayTime } from './MTripSheetUi'
|
||||
|
||||
@@ -61,13 +62,10 @@ export default function MDaySheet({ planner, shell }: MTripSheetsProps) {
|
||||
// hotel you wake up in (unconditional bookend lookup, mirroring useMPlanTimeline).
|
||||
// Never a place from another day — on a roadtrip that silently showed another
|
||||
// city's weather with nothing naming the place.
|
||||
const locatedPlace = dayAssignments.find(a => a.place?.lat && a.place?.lng)?.place
|
||||
const weatherHotel = day && !locatedPlace
|
||||
? getDayBookendHotels(day, planner.days, planner.tripAccommodations).morning
|
||||
: undefined
|
||||
const lat = locatedPlace?.lat ?? weatherHotel?.place_lat ?? null
|
||||
const lng = locatedPlace?.lng ?? weatherHotel?.place_lng ?? null
|
||||
const weatherPlaceName = locatedPlace?.name ?? weatherHotel?.place_name ?? null
|
||||
const { lat, lng, name: weatherPlaceName } = dayWeatherAnchor(
|
||||
dayAssignments,
|
||||
() => (day ? getDayBookendHotels(day, planner.days, planner.tripAccommodations).morning : undefined),
|
||||
)
|
||||
|
||||
const [weather, setWeather] = useState<WeatherResult | null>(null)
|
||||
const [weatherLoading, setWeatherLoading] = useState(false)
|
||||
|
||||
Reference in New Issue
Block a user