mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 16:33:16 +00:00
bacc6a29a7
All places offers the pairs that look like one place: both sides side by side with what differs marked, "keep this one" to group them as one place of the user's own (undo right after), and "not the same place" to set a pair aside for good. Desktop dialog and phone sheet share usePlaceDuplicates; every locale has the new strings. What the last dev run flagged on the client: - Tailwind's Prettier plugin had trimmed the leading space of conditional class names (col-filter-btn, col-lrow sel, col-split map-full, col-detail docked), so the filter row and the open row lost their styling; those classes are now joined so the formatter cannot glue them. - The dock position lives in one helper for the lists and All places, which moves the measured-position markers there instead of adding new ones. - usePlacesLibrary is split into filters, pages, detail and cover hooks that derive their loading state instead of setting it inside effects; the big sheets and views are cut into parts under the complexity limit, dynamic icons go through createElement, originName moves out of a component file. - formatRange is guarded like in the packing export, the cover lookup skips places without a position. - Tests follow the rename to Places, the category icon, the default list icon and the new trip collections store; react-hooks/refs is lowered to the count the run measured. - The rating on a place is a round badge again, in the list and on the map.
120 lines
5.0 KiB
TypeScript
120 lines
5.0 KiB
TypeScript
import React, { createElement } from 'react'
|
|
import { Plus, Layers, Users, Upload, Globe2 } from 'lucide-react'
|
|
import type { Collection } from '@trek/shared'
|
|
import type { TranslationFn } from '../../types'
|
|
import { ALL_SAVED } from '../../store/collectionStore'
|
|
import type { ActiveCollectionId, IncomingCollectionInvite } from '../../store/collectionStore'
|
|
import CollectionInviteCard from './CollectionInviteCard'
|
|
import { Tooltip } from '../shared/Tooltip'
|
|
import { listIcon } from './listIcons'
|
|
|
|
interface ListsRailProps {
|
|
ownedLists: Collection[]
|
|
sharedLists: Collection[]
|
|
activeId: ActiveCollectionId
|
|
/** How many places the lists hold together, beside "All saved". */
|
|
savedCount?: number
|
|
/** The overview of every place is open (PLC-07); it sits above the lists. */
|
|
libraryActive?: boolean
|
|
onSelectLibrary?: () => void
|
|
incomingInvites: IncomingCollectionInvite[]
|
|
onSelect: (id: ActiveCollectionId) => void
|
|
onNewList: () => void
|
|
/** Read a list file as a new list (#2198). */
|
|
onImportList: () => void
|
|
onAcceptInvite: (id: number) => void
|
|
onDeclineInvite: (id: number) => void
|
|
t: TranslationFn
|
|
}
|
|
|
|
function ListRow({ list, active, onSelect }: { list: Collection; active: boolean; onSelect: (id: number) => void }): React.ReactElement {
|
|
const ListIcon = listIcon(list.icon)
|
|
return (
|
|
<div className="col-row">
|
|
<button type="button" onClick={() => onSelect(list.id)} className={`col-row-btn${active ? ' on' : ''}`}>
|
|
{/* The list's own symbol in its own colour (the default one without a colour). */}
|
|
<span className="ico tile list" style={{ ['--list' as string]: list.color || '#6366f1' }}>{createElement(ListIcon, { size: 15 })}</span>
|
|
<span className="nm">{list.name}</span>
|
|
<span className="ct">{list.place_count ?? 0}</span>
|
|
</button>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
/**
|
|
* Left rail of the user's lists: "New list" and "Import list" actions, the "All saved" union
|
|
* pseudo-list, owned lists (colour dot + count), a shared section, and an
|
|
* incoming-invites block. Selecting a list makes it active; editing / deleting
|
|
* happens from the Edit button in the hero of the active list.
|
|
*/
|
|
export default function ListsRail(props: ListsRailProps): React.ReactElement {
|
|
const {
|
|
ownedLists, sharedLists, activeId, incomingInvites, libraryActive = false, onSelectLibrary, savedCount = 0,
|
|
onSelect, onNewList, onImportList, onAcceptInvite, onDeclineInvite, t,
|
|
} = props
|
|
|
|
return (
|
|
<>
|
|
<div className="col-rail-newrow">
|
|
<button type="button" onClick={onNewList} className="col-rail-new">
|
|
<span className="col-rail-plus"><Plus size={15} strokeWidth={2.4} /></span> {t('collections.newList')}
|
|
</button>
|
|
{/* Import sits beside New rather than in the hero: a file becomes a NEW
|
|
list, so it belongs where lists are made, not on the one open. */}
|
|
<Tooltip label={t('collections.file.importTitle')} placement="bottom">
|
|
<button
|
|
type="button"
|
|
onClick={onImportList}
|
|
className="col-rail-new col-rail-import"
|
|
aria-label={t('collections.file.importButton')}
|
|
>
|
|
<Upload size={16} />
|
|
</button>
|
|
</Tooltip>
|
|
</div>
|
|
|
|
{onSelectLibrary && (
|
|
<div className="col-row">
|
|
<button type="button" onClick={onSelectLibrary} className={`col-row-btn${libraryActive ? ' on' : ''}`} aria-current={libraryActive ? 'page' : undefined}>
|
|
<span className="ico tile"><Globe2 size={15} /></span>
|
|
<span className="nm">{t('collections.library.title')}</span>
|
|
</button>
|
|
</div>
|
|
)}
|
|
<div className="col-row">
|
|
<button type="button" onClick={() => onSelect(ALL_SAVED)} className={`col-row-btn${!libraryActive && activeId === ALL_SAVED ? ' on' : ''}`}>
|
|
<span className="ico tile"><Layers size={15} /></span>
|
|
<span className="nm">{t('collections.allSaved')}</span>
|
|
{savedCount > 0 && <span className="ct">{savedCount}</span>}
|
|
</button>
|
|
</div>
|
|
|
|
{ownedLists.length > 0 && <div className="col-rail-label">{t('collections.myLists')}</div>}
|
|
{ownedLists.map(list => (
|
|
<ListRow key={list.id} list={list} active={activeId === list.id} onSelect={onSelect} />
|
|
))}
|
|
|
|
{sharedLists.length > 0 && (
|
|
<>
|
|
<div className="col-rail-label"><Users size={12} /> {t('collections.shared')}</div>
|
|
{sharedLists.map(list => (
|
|
<ListRow key={list.id} list={list} active={activeId === list.id} onSelect={onSelect} />
|
|
))}
|
|
</>
|
|
)}
|
|
|
|
{incomingInvites.length > 0 && (
|
|
<>
|
|
<div className="col-rail-label">
|
|
{t('collections.invites.title')}
|
|
<span className="badge">{incomingInvites.length}</span>
|
|
</div>
|
|
{incomingInvites.map(inv => (
|
|
<CollectionInviteCard key={inv.collection_id} invite={inv} onAccept={onAcceptInvite} onDecline={onDeclineInvite} t={t} />
|
|
))}
|
|
</>
|
|
)}
|
|
</>
|
|
)
|
|
}
|