import React from 'react' import Markdown from 'react-markdown' import remarkGfm from 'remark-gfm' import { Plus, Check, Star } from 'lucide-react' import PlaceAvatar from '../shared/PlaceAvatar' import { getCategoryIcon } from '../shared/categoryIcons' import { resolveTrackColor } from '../Map/trackColors' import type { Place, Category } from '../../types' interface MemoPlaceRowProps { place: Place category: Category | undefined isSelected: boolean isPlanned: boolean inDay: boolean isChecked: boolean selectMode: boolean selectedDayId: number | null canEditPlaces: boolean isMobile: boolean t: (key: string, params?: Record) => string onPlaceClick: (id: number | null) => void onContextMenu: (e: React.MouseEvent, place: Place) => void onAssignToDay: (placeId: number, dayId?: number) => void toggleSelected: (id: number) => void setDayPickerPlace: (place: any) => void registerPlaceRow: (placeId: number, element: HTMLDivElement | null) => void } export const MemoPlaceRow = React.memo(function MemoPlaceRow({ place, category: cat, isSelected, isPlanned, inDay, isChecked, selectMode, selectedDayId, canEditPlaces, isMobile, t, onPlaceClick, onContextMenu, onAssignToDay, toggleSelected, setDayPickerPlace, registerPlaceRow, }: MemoPlaceRowProps) { const hasGeometry = Boolean(place.route_geometry) // Touch is reached through a long press instead of being locked out (#1616). const dragDisabled = isMobile // One place for what a row does, so the keyboard path below cannot drift from the click. const activate = () => { if (selectMode) { toggleSelected(place.id) } else if (isMobile) { setDayPickerPlace(place) } else { onPlaceClick(isSelected ? null : place.id) } } return (
registerPlaceRow(place.id, element)} role="option" tabIndex={0} aria-selected={isSelected} data-place-id={place.id} draggable={!selectMode && !dragDisabled} onDragStart={e => { if (dragDisabled) { e.preventDefault(); return } e.dataTransfer.setData('placeId', String(place.id)) e.dataTransfer.effectAllowed = 'copy' window.__dragData = { placeId: String(place.id) } }} onClick={activate} onKeyDown={e => { // Only when the row itself has focus — the "+" button inside it keeps its own key handling. if (e.target !== e.currentTarget) return if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); activate() } }} onContextMenu={selectMode ? undefined : e => onContextMenu(e, place)} style={{ display: 'flex', alignItems: 'center', gap: 10, padding: '9px 14px 9px 16px', cursor: selectMode || dragDisabled ? 'pointer' : 'grab', background: isChecked ? 'color-mix(in srgb, var(--accent) 8%, transparent)' : isSelected ? 'var(--border-faint)' : 'transparent', borderBottom: '1px solid var(--border-faint)', transition: 'background 0.1s', contentVisibility: 'auto', containIntrinsicSize: '0 52px', }} onMouseEnter={e => { if (!isSelected && !isChecked) e.currentTarget.style.background = 'var(--bg-hover)' }} onMouseLeave={e => { if (!isSelected && !isChecked) e.currentTarget.style.background = 'transparent' }} > {selectMode && (
{isChecked && }
)}
{/* A stroke of the colour the track is drawn in — the map has no legend of its own, so this is what tells you which line is this row (#776). A line rather than another 11px icon, so it doesn't read as a second category glyph next to the one below. */} {hasGeometry && ( )} {cat && (() => { const CatIcon = getCategoryIcon(cat.icon) return })()} {place.name} {/* Average member rating (#1435). */} {(place.rating_count ?? 0) > 0 && place.rating_avg != null && ( {(Math.round(place.rating_avg * 10) / 10).toLocaleString()} )}
{(place.description || place.address || cat?.name) && (
{/* Rendered, like the same line in the day plan: the description is Markdown everywhere else, and printing it raw here was the one place a formatted place read as `_underscores_`. Still clamped to one line — the row is a list entry, not the inspector. */}
{place.description || place.address || cat?.name || ''}
)}
{!selectMode && !inDay && selectedDayId !== null && ( )}
) })