mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-28 15:40:06 +00:00
feat(collections): list details, place detail sheet, add-place, fusion kick (#1081)
Dashboard widget (B): the collections tool now shows the user's LISTS as compact colour-washed badges (cover image tinted with the list colour, or a gradient) that jump to the list — one list() call, no N+1. List details (C): lists gain a description, a custom cover image (uploaded to /uploads/covers, tinted with the list colour in the hero) and links. A shared ListEditorModal handles both create and edit; the hero shows the description + link chips. New `links` JSON column on collections + collection_places (migration 151) with parse/serialize in the service; a POST :id/cover upload endpoint mirroring trips; cover-file cleanup path-confined locally. Place detail (D): clicking a place opens a bottom sheet (no backdrop, so the map stays visible) — status cycle, copy-to-trip, remove, and an edit mode with a markdown description + links editor (collectionsApi.updatePlace, now wired via a store action). A "+" next to the search adds a place to the list via the maps search. Fusion + fixes (E): the owner can now remove an accepted member (kick) — new removeMember service/route/store + a button in ShareCollectionModal, with a collections:removed WS bounce. findMembership no longer matches on name alone (coordinate proximity required, killing "Starbucks everywhere" false positives). loadCollection swallows a 403/404 after a leave/remove so the URL sync can't throw uncaught. Grid remnants gone; the map select toggle moved onto the map. New strings across all 22 locales; i18n parity strict passes.
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import { Search, MapPin, Plus, Loader2 } from 'lucide-react'
|
||||
import Modal from '../shared/Modal'
|
||||
import { mapsApi } from '../../api/client'
|
||||
import { collectionsApi } from '../../api/collections'
|
||||
import { useTranslation } from '../../i18n'
|
||||
import { useToast } from '../shared/Toast'
|
||||
import { getApiErrorMessage } from '../../types'
|
||||
import type { TranslationFn } from '../../types'
|
||||
|
||||
type MapsPlace = Record<string, unknown>
|
||||
const str = (v: unknown): string | undefined => (typeof v === 'string' && v ? v : undefined)
|
||||
const num = (v: unknown): number | undefined => (typeof v === 'number' ? v : typeof v === 'string' && v !== '' ? Number(v) : undefined)
|
||||
|
||||
interface AddPlaceToCollectionModalProps {
|
||||
isOpen: boolean
|
||||
collectionId: number
|
||||
collectionName: string
|
||||
onClose: () => void
|
||||
onAdded: () => void
|
||||
t: TranslationFn
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for a place (OSM / Google via the maps service) and save it straight
|
||||
* into the current list. Stays open after each add so several places can be
|
||||
* added in one go.
|
||||
*/
|
||||
export default function AddPlaceToCollectionModal({ isOpen, collectionId, collectionName, onClose, onAdded, t }: AddPlaceToCollectionModalProps): React.ReactElement {
|
||||
const { language } = useTranslation()
|
||||
const toast = useToast()
|
||||
const [query, setQuery] = useState('')
|
||||
const [results, setResults] = useState<MapsPlace[]>([])
|
||||
const [searching, setSearching] = useState(false)
|
||||
const [addingIdx, setAddingIdx] = useState<number | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
if (!isOpen) { setQuery(''); setResults([]); setAddingIdx(null) }
|
||||
}, [isOpen])
|
||||
|
||||
const search = async () => {
|
||||
if (!query.trim()) return
|
||||
setSearching(true)
|
||||
try {
|
||||
const res = await mapsApi.search(query, language)
|
||||
setResults((res.places as MapsPlace[]) || [])
|
||||
} catch (err) {
|
||||
toast.error(getApiErrorMessage(err, t('places.mapsSearchError')))
|
||||
} finally {
|
||||
setSearching(false)
|
||||
}
|
||||
}
|
||||
|
||||
const add = async (r: MapsPlace, idx: number) => {
|
||||
const name = str(r.name)
|
||||
if (!name) return
|
||||
setAddingIdx(idx)
|
||||
try {
|
||||
const res = await collectionsApi.savePlace({
|
||||
collection_id: collectionId,
|
||||
name,
|
||||
address: str(r.address) ?? null,
|
||||
lat: num(r.lat) ?? null,
|
||||
lng: num(r.lng) ?? null,
|
||||
google_place_id: str(r.google_place_id) ?? null,
|
||||
google_ftid: str(r.google_ftid) ?? null,
|
||||
osm_id: str(r.osm_id) ?? null,
|
||||
website: str(r.website) ?? null,
|
||||
phone: str(r.phone) ?? null,
|
||||
})
|
||||
if (res.duplicate) toast.info(t('collections.duplicateWarning'))
|
||||
else { toast.success(t('collections.addedToList', { name: collectionName })); onAdded() }
|
||||
} catch (err) {
|
||||
toast.error(getApiErrorMessage(err, t('common.error')))
|
||||
} finally {
|
||||
setAddingIdx(null)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal isOpen={isOpen} onClose={onClose} title={t('collections.addPlace')} size="md">
|
||||
<div className="flex flex-col gap-3">
|
||||
<div className="flex gap-2">
|
||||
<div className="relative flex-1">
|
||||
<Search size={15} className="absolute left-3 top-1/2 -translate-y-1/2 text-content-faint" />
|
||||
<input
|
||||
autoFocus
|
||||
value={query}
|
||||
onChange={e => setQuery(e.target.value)}
|
||||
onKeyDown={e => { if (e.key === 'Enter') search() }}
|
||||
placeholder={t('collections.addPlaceSearch')}
|
||||
className="w-full pl-9 pr-3 py-2 rounded-lg border border-edge bg-surface-input text-content text-[14px] outline-none focus:border-accent"
|
||||
/>
|
||||
</div>
|
||||
<button type="button" onClick={search} disabled={!query.trim() || searching} className="px-4 py-2 rounded-lg bg-accent text-accent-text text-[13px] font-semibold disabled:opacity-50 inline-flex items-center gap-2">
|
||||
{searching ? <Loader2 size={15} className="animate-spin" /> : <Search size={15} />}
|
||||
{t('common.search')}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-1.5 max-h-[380px] overflow-y-auto">
|
||||
{results.length === 0 && !searching && (
|
||||
<p className="text-[13px] text-content-faint py-6 text-center">{t('collections.addPlaceHint')}</p>
|
||||
)}
|
||||
{results.map((r, i) => (
|
||||
<div key={i} className="flex items-center gap-3 px-3 py-2.5 rounded-lg border border-edge bg-surface-card">
|
||||
<div className="w-9 h-9 rounded-lg bg-surface-secondary flex items-center justify-center text-content-faint shrink-0"><MapPin size={16} /></div>
|
||||
<div className="flex flex-col min-w-0 flex-1">
|
||||
<span className="text-[13.5px] font-semibold text-content truncate">{str(r.name)}</span>
|
||||
{str(r.address) && <span className="text-[12px] text-content-faint truncate">{str(r.address)}</span>}
|
||||
</div>
|
||||
<button type="button" onClick={() => add(r, i)} disabled={addingIdx === i} className="px-2.5 py-1.5 rounded-lg bg-inverse text-inverse-text text-[12px] font-semibold inline-flex items-center gap-1.5 disabled:opacity-50 shrink-0">
|
||||
{addingIdx === i ? <Loader2 size={13} className="animate-spin" /> : <Plus size={13} />} {t('common.add')}
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import React from 'react'
|
||||
import { Share2, Users, Plus } from 'lucide-react'
|
||||
import type { CollectionMember } from '@trek/shared'
|
||||
import { Share2, Users, Plus, Link2 } from 'lucide-react'
|
||||
import type { CollectionMember, CollectionLink } from '@trek/shared'
|
||||
import type { TranslationFn } from '../../types'
|
||||
import type { StatusFilter } from '../../store/collectionStore'
|
||||
import { STATUS_META, STATUS_ORDER } from '../../pages/collections/collectionsModel'
|
||||
@@ -14,9 +14,11 @@ function initials(name: string): string {
|
||||
interface CollectionHeroProps {
|
||||
eyebrow: string
|
||||
title: string
|
||||
/** List colour — drives the gradient wash when there is no cover image. */
|
||||
/** List colour — drives the gradient wash (or tints the cover image). */
|
||||
color: string
|
||||
coverImage?: string | null
|
||||
description?: string | null
|
||||
links?: CollectionLink[]
|
||||
counts: Record<StatusFilter, number>
|
||||
statusFilter: StatusFilter
|
||||
onStatusFilter: (f: StatusFilter) => void
|
||||
@@ -37,8 +39,12 @@ interface CollectionHeroProps {
|
||||
* (All / Idea / Want / Visited with live counts). Share + New-list actions sit
|
||||
* top-right. Modelled on the dashboard hero-trip.
|
||||
*/
|
||||
function linkHost(url: string): string {
|
||||
try { return new URL(url).hostname.replace(/^www\./, '') } catch { return url }
|
||||
}
|
||||
|
||||
export default function CollectionHero({
|
||||
eyebrow, title, color, coverImage, counts, statusFilter, onStatusFilter,
|
||||
eyebrow, title, color, coverImage, description, links, counts, statusFilter, onStatusFilter,
|
||||
members, canShare, isOwner, shareMemberCount, onShare, onNewList, t,
|
||||
}: CollectionHeroProps): React.ReactElement {
|
||||
const accepted = members.filter(m => m.status === 'accepted' || m.is_owner)
|
||||
@@ -53,9 +59,14 @@ export default function CollectionHero({
|
||||
|
||||
return (
|
||||
<header className="col-hero" style={{ ['--hero-color' as string]: color }}>
|
||||
{coverImage
|
||||
? <img className="col-hero-img" src={coverImage} alt="" />
|
||||
: <div className="col-hero-bg" />}
|
||||
{coverImage ? (
|
||||
<>
|
||||
<img className="col-hero-img" src={coverImage} alt="" />
|
||||
<div className="col-hero-tint" />
|
||||
</>
|
||||
) : (
|
||||
<div className="col-hero-bg" />
|
||||
)}
|
||||
<div className="col-hero-scrim" />
|
||||
|
||||
<div className="col-hero-actions">
|
||||
@@ -94,6 +105,8 @@ export default function CollectionHero({
|
||||
|
||||
<h1 className="col-hero-title">{title}</h1>
|
||||
|
||||
{description && <p className="col-hero-desc">{description}</p>}
|
||||
|
||||
<div className="col-hero-stats">
|
||||
{chips.map(chip => (
|
||||
<button
|
||||
@@ -108,6 +121,16 @@ export default function CollectionHero({
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{links && links.length > 0 && (
|
||||
<div className="col-hero-links">
|
||||
{links.map((l, i) => (
|
||||
<a key={i} href={l.url} target="_blank" rel="noopener noreferrer" className="col-hero-link" onClick={e => e.stopPropagation()}>
|
||||
<Link2 size={12} /> {l.label || linkHost(l.url)}
|
||||
</a>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</header>
|
||||
)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React from 'react'
|
||||
import { PanelLeftClose, PanelLeftOpen, Search } from 'lucide-react'
|
||||
import { PanelLeftClose, PanelLeftOpen, Search, CheckSquare, Plus } from 'lucide-react'
|
||||
import type { CollectionPlace } from '@trek/shared'
|
||||
import type { TranslationFn } from '../../types'
|
||||
import CollectionMap from './CollectionMap'
|
||||
@@ -15,6 +15,13 @@ interface CollectionMapPanelProps {
|
||||
/** 'list' = split (map can be expanded); 'map' = full (list collapsed). */
|
||||
view: 'list' | 'map'
|
||||
onToggleView: () => void
|
||||
/** Bulk-select toggle — hidden for the "All saved" view. */
|
||||
showSelect: boolean
|
||||
selectMode: boolean
|
||||
onToggleSelect: () => void
|
||||
/** Show a "+" to add a place to the current list (real lists only). */
|
||||
canAddPlace: boolean
|
||||
onAddPlace: () => void
|
||||
search: string
|
||||
onSearch: (v: string) => void
|
||||
t: TranslationFn
|
||||
@@ -22,11 +29,12 @@ interface CollectionMapPanelProps {
|
||||
|
||||
/**
|
||||
* The map surface for the collections page — the map plus its floating controls:
|
||||
* a top-left toggle that collapses/expands the list (animating the split) and a
|
||||
* top-right search box. Used both in the desktop split and full-map view.
|
||||
* a top-left cluster (collapse/expand the list, toggle bulk-select) and a
|
||||
* top-right search box. Used both in the desktop split and the full-map view.
|
||||
*/
|
||||
export default function CollectionMapPanel({
|
||||
places, selectedPlaceId, onSelect, onDeselect, dark, overlay, view, onToggleView, search, onSearch, t,
|
||||
places, selectedPlaceId, onSelect, onDeselect, dark, overlay, view, onToggleView,
|
||||
showSelect, selectMode, onToggleSelect, canAddPlace, onAddPlace, search, onSearch, t,
|
||||
}: CollectionMapPanelProps): React.ReactElement {
|
||||
return (
|
||||
<div className="col-map-shell">
|
||||
@@ -39,18 +47,38 @@ export default function CollectionMapPanel({
|
||||
/>
|
||||
{overlay && (
|
||||
<>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onToggleView}
|
||||
className="col-map-toggle"
|
||||
aria-label={view === 'map' ? t('collections.showList') : t('collections.expandMap')}
|
||||
title={view === 'map' ? t('collections.showList') : t('collections.expandMap')}
|
||||
>
|
||||
{view === 'map' ? <PanelLeftOpen size={17} /> : <PanelLeftClose size={17} />}
|
||||
</button>
|
||||
<div className="col-map-search">
|
||||
<Search size={15} />
|
||||
<input value={search} onChange={e => onSearch(e.target.value)} placeholder={t('collections.search')} />
|
||||
<div className="col-map-controls">
|
||||
<button
|
||||
type="button"
|
||||
onClick={onToggleView}
|
||||
className="col-map-btn"
|
||||
aria-label={view === 'map' ? t('collections.showList') : t('collections.expandMap')}
|
||||
title={view === 'map' ? t('collections.showList') : t('collections.expandMap')}
|
||||
>
|
||||
{view === 'map' ? <PanelLeftOpen size={17} /> : <PanelLeftClose size={17} />}
|
||||
</button>
|
||||
{showSelect && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={onToggleSelect}
|
||||
className={`col-map-btn${selectMode ? ' on' : ''}`}
|
||||
aria-label={t('collections.selectMode')}
|
||||
title={t('collections.selectMode')}
|
||||
>
|
||||
<CheckSquare size={16} />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
<div className="col-map-topright">
|
||||
{canAddPlace && (
|
||||
<button type="button" onClick={onAddPlace} className="col-map-btn" aria-label={t('collections.addPlace')} title={t('collections.addPlace')}>
|
||||
<Plus size={17} />
|
||||
</button>
|
||||
)}
|
||||
<div className="col-map-search">
|
||||
<Search size={15} />
|
||||
<input value={search} onChange={e => onSearch(e.target.value)} placeholder={t('collections.search')} />
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
import React, { useEffect, useRef, useState } from 'react'
|
||||
import Markdown from 'react-markdown'
|
||||
import remarkGfm from 'remark-gfm'
|
||||
import remarkBreaks from 'remark-breaks'
|
||||
import { X, Pencil, Copy, Trash2, MapPin, Link2, Plus, ExternalLink, Check } from 'lucide-react'
|
||||
import type { CollectionPlace, CollectionStatus, CollectionLink } from '@trek/shared'
|
||||
import type { TranslationFn } from '../../types'
|
||||
import MarkdownToolbar from '../Journey/MarkdownToolbar'
|
||||
import StatusBadge from './StatusBadge'
|
||||
import { entityGradient } from '../../utils/gradients'
|
||||
|
||||
function linkHost(url: string): string {
|
||||
try { return new URL(url).hostname.replace(/^www\./, '') } catch { return url }
|
||||
}
|
||||
|
||||
interface CollectionPlaceDetailProps {
|
||||
place: CollectionPlace
|
||||
canEdit: boolean
|
||||
onClose: () => void
|
||||
onSetStatus: (status: CollectionStatus) => void
|
||||
onSave: (patch: { name?: string; description?: string | null; links?: CollectionLink[] }) => Promise<void>
|
||||
onCopyToTrip: () => void
|
||||
onRemove: () => void
|
||||
t: TranslationFn
|
||||
}
|
||||
|
||||
/**
|
||||
* Bottom detail sheet for a saved place — a glassy card docked to the bottom
|
||||
* (full-width on mobile). Read mode renders the description as markdown + link
|
||||
* chips; edit mode swaps in a name field, a markdown editor (toolbar + textarea)
|
||||
* and a links editor, saving via collectionsApi.updatePlace. Also cycles the
|
||||
* status, copies the place to a trip and removes it from the list.
|
||||
*/
|
||||
export default function CollectionPlaceDetail({
|
||||
place, canEdit, onClose, onSetStatus, onSave, onCopyToTrip, onRemove, t,
|
||||
}: CollectionPlaceDetailProps): React.ReactElement {
|
||||
const [editing, setEditing] = useState(false)
|
||||
const [name, setName] = useState(place.name)
|
||||
const [description, setDescription] = useState(place.description ?? '')
|
||||
const [links, setLinks] = useState<CollectionLink[]>(place.links ?? [])
|
||||
const [saving, setSaving] = useState(false)
|
||||
const descRef = useRef<HTMLTextAreaElement>(null)
|
||||
|
||||
// Reset the form only when a DIFFERENT place is opened (keyed on id, not on
|
||||
// every field change — otherwise a save would clobber in-flight edits).
|
||||
useEffect(() => {
|
||||
setEditing(false)
|
||||
setName(place.name)
|
||||
setDescription(place.description ?? '')
|
||||
setLinks(place.links ?? [])
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [place.id])
|
||||
|
||||
const sub = place.category?.name || place.address
|
||||
const banner = place.image_url
|
||||
|
||||
const setLink = (i: number, patch: Partial<CollectionLink>) =>
|
||||
setLinks(links.map((l, idx) => (idx === i ? { ...l, ...patch } : l)))
|
||||
|
||||
const save = async () => {
|
||||
const cleanLinks = links.map(l => ({ label: l.label?.trim() || undefined, url: l.url.trim() })).filter(l => l.url)
|
||||
setSaving(true)
|
||||
try {
|
||||
await onSave({ name: name.trim() || place.name, description: description.trim() || null, links: cleanLinks })
|
||||
setEditing(false)
|
||||
} finally {
|
||||
setSaving(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="col-detail" onClick={e => e.stopPropagation()}>
|
||||
<div className="col-detail-cover" style={banner ? undefined : { backgroundImage: entityGradient(place.id) }}>
|
||||
{banner && <img src={banner} alt="" />}
|
||||
<div className="col-detail-cover-scrim" />
|
||||
<button type="button" className="col-detail-close" onClick={onClose} aria-label={t('common.close')}><X size={16} /></button>
|
||||
<div className="col-detail-head">
|
||||
{editing ? (
|
||||
<input value={name} onChange={e => setName(e.target.value)} className="col-detail-name-input" autoFocus />
|
||||
) : (
|
||||
<h2 className="col-detail-name">{place.name}</h2>
|
||||
)}
|
||||
{sub && <div className="col-detail-sub">{!place.category?.name && <MapPin size={12} />}{sub}</div>}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="col-detail-body">
|
||||
<div className="col-detail-actions">
|
||||
<StatusBadge status={place.status} onChange={onSetStatus} t={t} />
|
||||
<div className="col-detail-actions-spacer" />
|
||||
{canEdit && !editing && (
|
||||
<button type="button" className="col-detail-btn" onClick={() => setEditing(true)}><Pencil size={14} /> {t('common.edit')}</button>
|
||||
)}
|
||||
<button type="button" className="col-detail-btn" onClick={onCopyToTrip}><Copy size={14} /> {t('collections.copyToTrip')}</button>
|
||||
{canEdit && (
|
||||
<button type="button" className="col-detail-btn danger" onClick={onRemove}><Trash2 size={14} /> {t('collections.removeFromList')}</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{editing ? (
|
||||
<div className="col-detail-edit">
|
||||
<label className="col-detail-label">{t('collections.description')}</label>
|
||||
<MarkdownToolbar textareaRef={descRef} onUpdate={setDescription} />
|
||||
<textarea
|
||||
ref={descRef}
|
||||
value={description}
|
||||
onChange={e => setDescription(e.target.value)}
|
||||
rows={5}
|
||||
placeholder={t('collections.descriptionPlaceholder')}
|
||||
className="col-detail-textarea"
|
||||
/>
|
||||
|
||||
<label className="col-detail-label">{t('collections.links')}</label>
|
||||
<div className="col-detail-links-edit">
|
||||
{links.map((l, i) => (
|
||||
<div key={i} className="col-detail-link-row">
|
||||
<input value={l.label ?? ''} onChange={e => setLink(i, { label: e.target.value })} placeholder={t('collections.linkLabel')} className="col-detail-input w-28" />
|
||||
<input value={l.url} onChange={e => setLink(i, { url: e.target.value })} placeholder="https://…" className="col-detail-input flex-1" />
|
||||
<button type="button" onClick={() => setLinks(links.filter((_, idx) => idx !== i))} className="col-detail-icon-btn" aria-label={t('common.delete')}><Trash2 size={14} /></button>
|
||||
</div>
|
||||
))}
|
||||
<button type="button" onClick={() => setLinks([...links, { url: '' }])} className="col-detail-add-link"><Plus size={13} /> <Link2 size={12} /> {t('collections.addLink')}</button>
|
||||
</div>
|
||||
|
||||
<div className="col-detail-edit-actions">
|
||||
<button type="button" onClick={() => { setEditing(false); setName(place.name); setDescription(place.description ?? ''); setLinks(place.links ?? []) }} className="col-detail-btn">{t('common.cancel')}</button>
|
||||
<button type="button" onClick={save} disabled={saving} className="col-detail-btn primary"><Check size={14} /> {t('common.save')}</button>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
{place.description && (
|
||||
<div className="col-detail-md collab-note-md">
|
||||
<Markdown remarkPlugins={[remarkGfm, remarkBreaks]}>{place.description}</Markdown>
|
||||
</div>
|
||||
)}
|
||||
{place.links && place.links.length > 0 && (
|
||||
<div className="col-detail-links">
|
||||
{place.links.map((l, i) => (
|
||||
<a key={i} href={l.url} target="_blank" rel="noopener noreferrer" className="col-detail-link">
|
||||
<ExternalLink size={13} /> {l.label || linkHost(l.url)}
|
||||
</a>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{!place.description && (!place.links || place.links.length === 0) && canEdit && (
|
||||
<button type="button" className="col-detail-empty" onClick={() => setEditing(true)}>
|
||||
<Plus size={14} /> {t('collections.addDetails')}
|
||||
</button>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
import React, { useEffect, useRef, useState } from 'react'
|
||||
import { ImagePlus, Link2, Plus, Trash2 } from 'lucide-react'
|
||||
import Modal from '../shared/Modal'
|
||||
import { useCollectionStore } from '../../store/collectionStore'
|
||||
import { useToast } from '../shared/Toast'
|
||||
import { getApiErrorMessage } from '../../types'
|
||||
import type { TranslationFn } from '../../types'
|
||||
import type { Collection, CollectionLink } from '@trek/shared'
|
||||
|
||||
const SWATCHES = ['#6366f1', '#ec4899', '#14b8a6', '#f97316', '#8b5cf6', '#ef4444', '#3b82f6', '#22c55e']
|
||||
|
||||
interface ListEditorModalProps {
|
||||
/** null = closed, 'new' = create, a Collection = edit that list. */
|
||||
target: Collection | 'new' | null
|
||||
onClose: () => void
|
||||
onCreated: (id: number) => void
|
||||
t: TranslationFn
|
||||
}
|
||||
|
||||
/**
|
||||
* Create / edit a list — name, colour, an optional cover image (tinted with the
|
||||
* list colour in the hero), a description and a set of links. On create it makes
|
||||
* the list then uploads the cover to the new id; on edit it patches + re-uploads.
|
||||
*/
|
||||
export default function ListEditorModal({ target, onClose, onCreated, t }: ListEditorModalProps): React.ReactElement | null {
|
||||
const createCollection = useCollectionStore(s => s.createCollection)
|
||||
const updateCollection = useCollectionStore(s => s.updateCollection)
|
||||
const uploadCover = useCollectionStore(s => s.uploadCover)
|
||||
const toast = useToast()
|
||||
const fileRef = useRef<HTMLInputElement>(null)
|
||||
|
||||
const editing = target && target !== 'new' ? target : null
|
||||
const [name, setName] = useState('')
|
||||
const [color, setColor] = useState('#6366f1')
|
||||
const [description, setDescription] = useState('')
|
||||
const [links, setLinks] = useState<CollectionLink[]>([])
|
||||
const [coverFile, setCoverFile] = useState<File | null>(null)
|
||||
const [coverPreview, setCoverPreview] = useState<string | null>(null)
|
||||
const [saving, setSaving] = useState(false)
|
||||
|
||||
// (Re)seed the form whenever the target changes.
|
||||
useEffect(() => {
|
||||
if (!target) return
|
||||
setName(editing?.name ?? '')
|
||||
setColor(editing?.color ?? '#6366f1')
|
||||
setDescription(editing?.description ?? '')
|
||||
setLinks(editing?.links ?? [])
|
||||
setCoverFile(null)
|
||||
setCoverPreview(editing?.cover_image ?? null)
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [target])
|
||||
|
||||
if (!target) return null
|
||||
|
||||
const pickCover = (file: File | undefined) => {
|
||||
if (!file) return
|
||||
setCoverFile(file)
|
||||
setCoverPreview(URL.createObjectURL(file))
|
||||
}
|
||||
|
||||
const setLink = (i: number, patch: Partial<CollectionLink>) =>
|
||||
setLinks(links.map((l, idx) => (idx === i ? { ...l, ...patch } : l)))
|
||||
|
||||
const save = async () => {
|
||||
const trimmed = name.trim()
|
||||
if (!trimmed) return
|
||||
// Keep only links with a url; drop blank rows.
|
||||
const cleanLinks = links
|
||||
.map(l => ({ label: l.label?.trim() || undefined, url: l.url.trim() }))
|
||||
.filter(l => l.url)
|
||||
setSaving(true)
|
||||
try {
|
||||
let id = editing?.id
|
||||
if (editing) {
|
||||
await updateCollection(editing.id, { name: trimmed, color, description: description.trim() || null, links: cleanLinks })
|
||||
} else {
|
||||
const created = await createCollection({ name: trimmed, color, description: description.trim() || null, links: cleanLinks })
|
||||
id = created?.id
|
||||
}
|
||||
if (id != null && coverFile) await uploadCover(id, coverFile)
|
||||
if (!editing && id != null) onCreated(id)
|
||||
onClose()
|
||||
} catch (err) {
|
||||
toast.error(getApiErrorMessage(err, t('common.error')))
|
||||
} finally {
|
||||
setSaving(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal
|
||||
isOpen
|
||||
onClose={onClose}
|
||||
title={editing ? t('collections.editListTitle') : t('collections.newList')}
|
||||
size="md"
|
||||
footer={
|
||||
<div className="flex justify-end gap-2">
|
||||
<button type="button" onClick={onClose} className="px-3 py-1.5 rounded-lg border border-edge text-content-secondary text-[13px] hover:bg-surface-hover">
|
||||
{t('common.cancel')}
|
||||
</button>
|
||||
<button type="button" onClick={save} disabled={!name.trim() || saving} className="px-3 py-1.5 rounded-lg bg-accent text-accent-text text-[13px] font-semibold disabled:opacity-50">
|
||||
{editing ? t('common.save') : t('collections.create')}
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<div className="flex flex-col gap-4">
|
||||
{/* Cover */}
|
||||
<div>
|
||||
<label className="block text-[12px] font-medium text-content-secondary mb-1.5">{t('collections.coverImage')}</label>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => fileRef.current?.click()}
|
||||
className="relative w-full h-32 rounded-xl overflow-hidden border border-edge bg-surface-secondary flex items-center justify-center text-content-faint hover:border-accent transition-colors"
|
||||
>
|
||||
{coverPreview && <img src={coverPreview} alt="" className="absolute inset-0 w-full h-full object-cover" />}
|
||||
<div className="absolute inset-0" style={{ background: `linear-gradient(135deg, ${color}55, transparent 70%)` }} />
|
||||
<span className="relative flex items-center gap-2 text-[13px] font-medium" style={{ color: coverPreview ? '#fff' : undefined, textShadow: coverPreview ? '0 1px 4px rgba(0,0,0,.5)' : undefined }}>
|
||||
<ImagePlus size={16} /> {coverPreview ? t('collections.changeCover') : t('collections.addCover')}
|
||||
</span>
|
||||
</button>
|
||||
<input ref={fileRef} type="file" accept="image/jpeg,image/png,image/gif,image/webp" className="hidden" onChange={e => pickCover(e.target.files?.[0])} />
|
||||
</div>
|
||||
|
||||
{/* Name */}
|
||||
<div>
|
||||
<label className="block text-[12px] font-medium text-content-secondary mb-1.5">{t('collections.listName')}</label>
|
||||
<input
|
||||
autoFocus
|
||||
value={name}
|
||||
onChange={e => setName(e.target.value)}
|
||||
onKeyDown={e => { if (e.key === 'Enter' && name.trim()) save() }}
|
||||
placeholder={t('collections.listNamePlaceholder')}
|
||||
className="w-full px-3 py-2 rounded-lg border border-edge bg-surface-input text-content text-[14px] outline-none focus:border-accent"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Colour */}
|
||||
<div>
|
||||
<label className="block text-[12px] font-medium text-content-secondary mb-2">{t('collections.listColor')}</label>
|
||||
<div className="flex gap-2 flex-wrap">
|
||||
{SWATCHES.map(col => (
|
||||
<button
|
||||
key={col}
|
||||
type="button"
|
||||
onClick={() => setColor(col)}
|
||||
className="w-7 h-7 rounded-full transition-transform hover:scale-110"
|
||||
style={{ background: col, outline: color === col ? '2px solid var(--accent)' : 'none', outlineOffset: 2 }}
|
||||
aria-label={col}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Description */}
|
||||
<div>
|
||||
<label className="block text-[12px] font-medium text-content-secondary mb-1.5">{t('collections.description')}</label>
|
||||
<textarea
|
||||
value={description}
|
||||
onChange={e => setDescription(e.target.value)}
|
||||
rows={3}
|
||||
placeholder={t('collections.descriptionPlaceholder')}
|
||||
className="w-full px-3 py-2 rounded-lg border border-edge bg-surface-input text-content text-[13px] outline-none focus:border-accent resize-y"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Links */}
|
||||
<div>
|
||||
<label className="block text-[12px] font-medium text-content-secondary mb-1.5">{t('collections.links')}</label>
|
||||
<div className="flex flex-col gap-2">
|
||||
{links.map((l, i) => (
|
||||
<div key={i} className="flex items-center gap-2">
|
||||
<input
|
||||
value={l.label ?? ''}
|
||||
onChange={e => setLink(i, { label: e.target.value })}
|
||||
placeholder={t('collections.linkLabel')}
|
||||
className="w-32 shrink-0 px-2.5 py-1.5 rounded-lg border border-edge bg-surface-input text-content text-[12.5px] outline-none focus:border-accent"
|
||||
/>
|
||||
<input
|
||||
value={l.url}
|
||||
onChange={e => setLink(i, { url: e.target.value })}
|
||||
placeholder="https://…"
|
||||
className="flex-1 min-w-0 px-2.5 py-1.5 rounded-lg border border-edge bg-surface-input text-content text-[12.5px] outline-none focus:border-accent"
|
||||
/>
|
||||
<button type="button" onClick={() => setLinks(links.filter((_, idx) => idx !== i))} className="p-1.5 rounded-md text-content-faint hover:text-danger hover:bg-danger-soft" aria-label={t('common.delete')}>
|
||||
<Trash2 size={14} />
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
<button type="button" onClick={() => setLinks([...links, { url: '' }])} className="inline-flex items-center gap-1.5 self-start px-2.5 py-1.5 rounded-lg border border-dashed border-edge text-content-secondary text-[12.5px] font-medium hover:bg-surface-hover">
|
||||
<Plus size={14} /> <Link2 size={13} /> {t('collections.addLink')}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
@@ -13,13 +13,9 @@ interface ListsRailProps {
|
||||
sharedLists: Collection[]
|
||||
activeId: ActiveCollectionId
|
||||
incomingInvites: IncomingCollectionInvite[]
|
||||
editingListId: number | null
|
||||
editingName: string
|
||||
setEditingName: (v: string) => void
|
||||
onSelect: (id: ActiveCollectionId) => void
|
||||
onNewList: () => void
|
||||
onStartRename: (id: number, name: string) => void
|
||||
onCommitRename: () => void
|
||||
onEdit: (list: Collection) => void
|
||||
onSetColor: (id: number, color: string) => void
|
||||
onRequestDelete: (id: number) => void
|
||||
onAcceptInvite: (id: number) => void
|
||||
@@ -30,26 +26,16 @@ interface ListsRailProps {
|
||||
interface ListRowProps {
|
||||
list: Collection
|
||||
active: boolean
|
||||
editing: boolean
|
||||
editingName: string
|
||||
setEditingName: (v: string) => void
|
||||
onSelect: (id: number) => void
|
||||
onStartRename: (id: number, name: string) => void
|
||||
onCommitRename: () => void
|
||||
onEdit: (list: Collection) => void
|
||||
onSetColor: (id: number, color: string) => void
|
||||
onRequestDelete: (id: number) => void
|
||||
t: TranslationFn
|
||||
}
|
||||
|
||||
function ListRow({
|
||||
list, active, editing, editingName, setEditingName,
|
||||
onSelect, onStartRename, onCommitRename, onSetColor, onRequestDelete, t,
|
||||
}: ListRowProps): React.ReactElement {
|
||||
function ListRow({ list, active, onSelect, onEdit, onSetColor, onRequestDelete, t }: ListRowProps): React.ReactElement {
|
||||
const [menuOpen, setMenuOpen] = useState(false)
|
||||
const [colorOpen, setColorOpen] = useState(false)
|
||||
// Anchor rect for the portalled popover (fixed to the viewport). The popover
|
||||
// is portalled to document.body so the rail's `overflow-y:auto` +
|
||||
// `backdrop-filter` can't clip it.
|
||||
const [anchor, setAnchor] = useState<{ top: number; right: number } | null>(null)
|
||||
const rowRef = useRef<HTMLDivElement>(null)
|
||||
const btnRef = useRef<HTMLButtonElement>(null)
|
||||
@@ -79,7 +65,6 @@ function ListRow({
|
||||
document.addEventListener('mousedown', onDown, true)
|
||||
document.addEventListener('keydown', onKey)
|
||||
window.addEventListener('resize', close)
|
||||
// Any scroll (page or rail) invalidates the anchor rect → just close.
|
||||
window.addEventListener('scroll', close, true)
|
||||
return () => {
|
||||
document.removeEventListener('mousedown', onDown, true)
|
||||
@@ -89,21 +74,6 @@ function ListRow({
|
||||
}
|
||||
}, [open])
|
||||
|
||||
if (editing) {
|
||||
return (
|
||||
<div className="col-row">
|
||||
<input
|
||||
autoFocus
|
||||
value={editingName}
|
||||
onChange={e => setEditingName(e.target.value)}
|
||||
onKeyDown={e => { if (e.key === 'Enter' || e.key === 'Escape') onCommitRename() }}
|
||||
onBlur={onCommitRename}
|
||||
className="col-row-edit"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const popover = open && anchor && ReactDOM.createPortal(
|
||||
<div
|
||||
data-list-pop
|
||||
@@ -112,7 +82,7 @@ function ListRow({
|
||||
>
|
||||
{menuOpen && !colorOpen && (
|
||||
<>
|
||||
<button type="button" onClick={() => { setMenuOpen(false); onStartRename(list.id, list.name) }} className="w-full flex items-center gap-2.5 px-2.5 py-2 rounded-lg text-[13px] text-content-secondary hover:bg-surface-hover">
|
||||
<button type="button" onClick={() => { setMenuOpen(false); onEdit(list) }} className="w-full flex items-center gap-2.5 px-2.5 py-2 rounded-lg text-[13px] text-content-secondary hover:bg-surface-hover">
|
||||
<Pencil size={14} /> {t('collections.editList')}
|
||||
</button>
|
||||
<button type="button" onClick={() => setColorOpen(true)} className="w-full flex items-center gap-2.5 px-2.5 py-2 rounded-lg text-[13px] text-content-secondary hover:bg-surface-hover">
|
||||
@@ -170,16 +140,15 @@ function ListRow({
|
||||
|
||||
/**
|
||||
* Left rail of the user's lists: a "New list" action, the "All saved" union
|
||||
* pseudo-list, owned lists (colour dot + count + rename/colour/delete menu), a
|
||||
* pseudo-list, owned lists (colour dot + count + edit/colour/delete menu), a
|
||||
* shared section, and an incoming-invites block. Styled with the collections
|
||||
* glass tokens (`.col-*`); rendered both in the desktop rail and the mobile
|
||||
* drawer.
|
||||
* drawer. Editing a list opens the shared ListEditorModal via onEdit.
|
||||
*/
|
||||
export default function ListsRail(props: ListsRailProps): React.ReactElement {
|
||||
const {
|
||||
ownedLists, sharedLists, activeId, incomingInvites,
|
||||
editingListId, editingName, setEditingName,
|
||||
onSelect, onNewList, onStartRename, onCommitRename, onSetColor, onRequestDelete,
|
||||
onSelect, onNewList, onEdit, onSetColor, onRequestDelete,
|
||||
onAcceptInvite, onDeclineInvite, t,
|
||||
} = props
|
||||
|
||||
@@ -198,40 +167,14 @@ export default function ListsRail(props: ListsRailProps): React.ReactElement {
|
||||
|
||||
{ownedLists.length > 0 && <div className="col-rail-sep" />}
|
||||
{ownedLists.map(list => (
|
||||
<ListRow
|
||||
key={list.id}
|
||||
list={list}
|
||||
active={activeId === list.id}
|
||||
editing={editingListId === list.id}
|
||||
editingName={editingName}
|
||||
setEditingName={setEditingName}
|
||||
onSelect={onSelect}
|
||||
onStartRename={onStartRename}
|
||||
onCommitRename={onCommitRename}
|
||||
onSetColor={onSetColor}
|
||||
onRequestDelete={onRequestDelete}
|
||||
t={t}
|
||||
/>
|
||||
<ListRow key={list.id} list={list} active={activeId === list.id} onSelect={onSelect} onEdit={onEdit} onSetColor={onSetColor} onRequestDelete={onRequestDelete} t={t} />
|
||||
))}
|
||||
|
||||
{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}
|
||||
editing={editingListId === list.id}
|
||||
editingName={editingName}
|
||||
setEditingName={setEditingName}
|
||||
onSelect={onSelect}
|
||||
onStartRename={onStartRename}
|
||||
onCommitRename={onCommitRename}
|
||||
onSetColor={onSetColor}
|
||||
onRequestDelete={onRequestDelete}
|
||||
t={t}
|
||||
/>
|
||||
<ListRow key={list.id} list={list} active={activeId === list.id} onSelect={onSelect} onEdit={onEdit} onSetColor={onSetColor} onRequestDelete={onRequestDelete} t={t} />
|
||||
))}
|
||||
</>
|
||||
)}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React, { useEffect, useMemo, useState } from 'react'
|
||||
import { UserPlus, Loader2, Clock, Check, Crown, LogOut } from 'lucide-react'
|
||||
import { UserPlus, UserMinus, Loader2, Clock, Check, Crown, LogOut } from 'lucide-react'
|
||||
import type { CollectionMember } from '@trek/shared'
|
||||
import Modal from '../shared/Modal'
|
||||
import CustomSelect from '../shared/CustomSelect'
|
||||
@@ -56,12 +56,14 @@ export default function ShareCollectionModal({
|
||||
const currentUserId = useAuthStore(s => s.user?.id)
|
||||
const invite = useCollectionStore(s => s.invite)
|
||||
const cancelInvite = useCollectionStore(s => s.cancelInvite)
|
||||
const removeMember = useCollectionStore(s => s.removeMember)
|
||||
const leave = useCollectionStore(s => s.leave)
|
||||
|
||||
const [availableUsers, setAvailableUsers] = useState<{ id: number; username: string }[]>([])
|
||||
const [selectedUserId, setSelectedUserId] = useState<number | ''>('')
|
||||
const [inviting, setInviting] = useState(false)
|
||||
const [cancellingId, setCancellingId] = useState<number | null>(null)
|
||||
const [removingId, setRemovingId] = useState<number | null>(null)
|
||||
const [confirmLeave, setConfirmLeave] = useState(false)
|
||||
const [leaving, setLeaving] = useState(false)
|
||||
|
||||
@@ -117,6 +119,18 @@ export default function ShareCollectionModal({
|
||||
}
|
||||
}
|
||||
|
||||
const handleRemove = async (userId: number) => {
|
||||
if (removingId != null) return
|
||||
setRemovingId(userId)
|
||||
try {
|
||||
await removeMember(collectionId, userId)
|
||||
} catch (err) {
|
||||
toast.error(getApiErrorMessage(err, t('common.error')))
|
||||
} finally {
|
||||
setRemovingId(null)
|
||||
}
|
||||
}
|
||||
|
||||
const handleLeave = async () => {
|
||||
setLeaving(true)
|
||||
try {
|
||||
@@ -185,6 +199,18 @@ export default function ShareCollectionModal({
|
||||
{cancellingId === member.user_id ? <Loader2 size={12} className="animate-spin" /> : t('collections.share.cancel')}
|
||||
</button>
|
||||
)}
|
||||
{isOwner && !member.is_owner && member.status === 'accepted' && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => handleRemove(member.user_id)}
|
||||
disabled={removingId === member.user_id}
|
||||
title={t('collections.share.remove')}
|
||||
aria-label={t('collections.share.remove')}
|
||||
className="shrink-0 p-1 rounded-md text-content-faint hover:text-danger hover:bg-danger-soft transition-colors disabled:opacity-50"
|
||||
>
|
||||
{removingId === member.user_id ? <Loader2 size={12} className="animate-spin" /> : <UserMinus size={13} />}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
|
||||
@@ -1,26 +1,22 @@
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import { Bookmark, ArrowRight } from 'lucide-react'
|
||||
import { Bookmark, ArrowRight, MapPin } from 'lucide-react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from '../../i18n'
|
||||
import PlaceAvatar from '../shared/PlaceAvatar'
|
||||
import { collectionsApi } from '../../api/collections'
|
||||
import type { CollectionPlace } from '@trek/shared'
|
||||
import { entityGradient } from '../../utils/gradients'
|
||||
import type { Collection } from '@trek/shared'
|
||||
|
||||
/**
|
||||
* Dashboard sidebar widget — a glassy `.tool` card (cloned from the dashboard's
|
||||
* UpcomingTool) that surfaces the user's saved-places library: a total count
|
||||
* plus the most recently saved places. Every row and the header "→" jump to
|
||||
* /collections.
|
||||
*
|
||||
* Self-contained on purpose: it fetches its own data on mount, and it is only
|
||||
* ever mounted when BOTH gates are satisfied (admin addon enabled AND the
|
||||
* per-user widget flag on — see DashboardPage `showCollections`). That keeps the
|
||||
* data fetch strictly "only when shown" and means the dashboard never hits
|
||||
* /api/addons/collections while the addon is disabled.
|
||||
* Dashboard sidebar widget — a glassy `.tool` card that surfaces the user's
|
||||
* saved-place LISTS as compact colour-washed badges (a mini version of the
|
||||
* collections hero): each badge shows the list's cover image (tinted with its
|
||||
* colour) or a colour gradient, its name and place count, and jumps to that
|
||||
* list. Fetches only list() (per-list place_count), so no N+1.
|
||||
*/
|
||||
export default function CollectionsWidget({ onOpen }: { onOpen: () => void }): React.ReactElement {
|
||||
const { t } = useTranslation()
|
||||
const [places, setPlaces] = useState<CollectionPlace[]>([])
|
||||
const [count, setCount] = useState(0)
|
||||
const navigate = useNavigate()
|
||||
const [lists, setLists] = useState<Collection[]>([])
|
||||
const [loading, setLoading] = useState(true)
|
||||
|
||||
useEffect(() => {
|
||||
@@ -28,27 +24,9 @@ export default function CollectionsWidget({ onOpen }: { onOpen: () => void }): R
|
||||
;(async () => {
|
||||
try {
|
||||
const data = await collectionsApi.list()
|
||||
if (cancelled) return
|
||||
// Union every list the user owns or co-owns, deduped, newest first —
|
||||
// mirrors the store's "All saved" pseudo-list so the widget shows the
|
||||
// same recent saves the page does.
|
||||
const results = await Promise.all(data.collections.map(c => collectionsApi.get(c.id).catch(() => null)))
|
||||
if (cancelled) return
|
||||
const seen = new Set<number>()
|
||||
const merged: CollectionPlace[] = []
|
||||
for (const res of results) {
|
||||
if (!res) continue
|
||||
for (const p of res.places) {
|
||||
if (seen.has(p.id)) continue
|
||||
seen.add(p.id)
|
||||
merged.push(p)
|
||||
}
|
||||
}
|
||||
merged.sort((a, b) => (b.created_at ?? '').localeCompare(a.created_at ?? ''))
|
||||
setCount(merged.length)
|
||||
setPlaces(merged.slice(0, 4))
|
||||
if (!cancelled) setLists(data.collections)
|
||||
} catch {
|
||||
if (!cancelled) { setPlaces([]); setCount(0) }
|
||||
if (!cancelled) setLists([])
|
||||
} finally {
|
||||
if (!cancelled) setLoading(false)
|
||||
}
|
||||
@@ -64,27 +42,28 @@ export default function CollectionsWidget({ onOpen }: { onOpen: () => void }): R
|
||||
<ArrowRight size={14} />
|
||||
</button>
|
||||
</div>
|
||||
{loading ? null : places.length === 0 ? (
|
||||
{loading ? null : lists.length === 0 ? (
|
||||
<div className="col-empty">{t('collections.widget.empty')}</div>
|
||||
) : (
|
||||
<>
|
||||
<div className="col-count">{t('collections.widget.savedCount', { count })}</div>
|
||||
<div className="col-list">
|
||||
{places.map(p => (
|
||||
<button key={p.id} className="col-item" onClick={onOpen}>
|
||||
<PlaceAvatar
|
||||
place={p}
|
||||
size={36}
|
||||
category={p.category ? { color: p.category.color ?? undefined, icon: p.category.icon ?? undefined } : null}
|
||||
/>
|
||||
<div className="col-info">
|
||||
<div className="t">{p.name}</div>
|
||||
<div className="s">{p.category?.name || p.address || ''}</div>
|
||||
</div>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
<div className="col-badges">
|
||||
{lists.slice(0, 6).map(list => (
|
||||
<button
|
||||
key={list.id}
|
||||
className="col-badge"
|
||||
style={{ ['--badge-color' as string]: list.color || '#6366f1' }}
|
||||
onClick={() => navigate(`/collections/${list.id}`)}
|
||||
>
|
||||
{list.cover_image
|
||||
? <img className="col-badge-media" src={list.cover_image} alt="" />
|
||||
: <div className="col-badge-media" style={{ backgroundImage: entityGradient(list.id) }} />}
|
||||
<div className="col-badge-tint" />
|
||||
<div className="col-badge-body">
|
||||
<span className="col-badge-name">{list.name}</span>
|
||||
<span className="col-badge-count"><MapPin size={11} /> {list.place_count ?? 0}</span>
|
||||
</div>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user