feat(dialogs): Vacay, Collections, Atlas and Journey in the new dialog look

Every popup of the four pages moves to the shared dialog frame the trip
uses: head band with its icon, the scrolling body, the footer with its
actions, and ConfirmDialog for the questions.

- Vacay: settings, removing a year (now says so when it fails), the
  fusion request, inviting a person, a person's colour and sharing the
  calendar.
- Collections: new and edited lists, adding a place, importing a file and
  a trip's places, sharing, labels and assigning them, copying to a trip,
  moving or duplicating, saving a trip's places and deleting a list. The
  stylesheet of the old import view goes.
- Atlas: the country popup with the flag in its head, its choices as rows
  and the wishlist step; Dawarich's Atlas dialog and its accept dialog on
  the desktop.
- Journey: creating a journey, its settings, linking a trip, inviting a
  contributor, the entry editor (discarding asks in a dialog) and the
  photo provider picker; the entry card's menu is the shared one.

The phone keeps its own sheets: where a dialog is shared with it
(Dawarich, the contributor invite, the provider picker) only the desktop
frame changes.
This commit is contained in:
Maurice
2026-09-28 16:52:32 +02:00
parent 9064ee57b7
commit acd003ea67
46 changed files with 3338 additions and 2803 deletions
@@ -2,7 +2,7 @@
import React from 'react'
import type { Mock } from 'vitest'
import { http, HttpResponse } from 'msw'
import { render, screen, fireEvent, waitFor } from '../../../tests/helpers/render'
import { render, screen, fireEvent, waitFor, within } from '../../../tests/helpers/render'
import { server } from '../../../tests/helpers/msw/server'
import type { Category } from '@trek/shared'
import { useTranslation } from '../../i18n/TranslationContext'
@@ -68,6 +68,11 @@ function typeName(value: string): void {
fireEvent.change(screen.getByPlaceholderText('Name'), { target: { value } })
}
/** The results panel's own close button; the dialog's head band has one of the same name. */
function dismissResultsButton(): HTMLElement {
return within(screen.getByRole('group', { name: 'Search' })).getByRole('button', { name: 'Close' })
}
describe('AddPlaceToCollectionModal', () => {
beforeEach(() => {
addToast = vi.fn<AddToast>(() => 0)
@@ -151,7 +156,7 @@ describe('AddPlaceToCollectionModal', () => {
fireEvent.click(screen.getByRole('button', { name: /Search/ }))
await screen.findByText('Kissa Sakaiki')
fireEvent.click(screen.getByRole('button', { name: 'Close' }))
fireEvent.click(dismissResultsButton())
expect(screen.queryByText('Kissa Sakaiki')).not.toBeInTheDocument()
})
@@ -182,7 +187,7 @@ describe('AddPlaceToCollectionModal', () => {
fireEvent.click(screen.getByRole('button', { name: /Search/ }))
await screen.findByText('No places found')
fireEvent.click(screen.getByRole('button', { name: 'Close' }))
fireEvent.click(dismissResultsButton())
expect(screen.queryByText('No places found')).not.toBeInTheDocument()
})
@@ -1,11 +1,13 @@
import React, { useEffect, useRef, useState } from 'react'
import React, { useEffect, useId, useRef, useState } from 'react'
import Markdown from 'react-markdown'
import remarkGfm from 'remark-gfm'
import remarkBreaks from 'remark-breaks'
import { Search, MapPin, Plus, Loader2, Link2, Trash2, Check, X } from 'lucide-react'
import Modal from '../shared/Modal'
import { Bookmark, Search, MapPin, MapPinned, Loader2, Trash2, Check, X } from 'lucide-react'
import { DialogButton, DialogFooter, DialogHeader, DialogSection, DialogShell, DialogTile, FooterSpacer, NEUTRAL_TINT, fs } from '../shared/DialogShell'
import { AddRowButton, EditorField, GRID_2, INPUT, PANEL, Segmented, TEXTAREA } from '../shared/dialogParts'
import { NumericInput } from '../shared/NumericInput'
import MarkdownToolbar from '../Journey/MarkdownToolbar'
import NoteFormatToolbar from '../shared/NoteFormatToolbar'
import { Tooltip } from '../shared/Tooltip'
import { mapsApi } from '../../api/client'
import { collectionsApi } from '../../api/collections'
import { getCategoryIcon } from '../shared/categoryIcons'
@@ -20,6 +22,19 @@ 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)
/**
* The search row, pinned to the top of the scrolling body. The dialog stays open
* after an add, and the row used to sit above the viewport once the form was
* scrolled, so it looked like the button had vanished (#1921). The negative
* margins let its background cover the body's padding while it is stuck.
*/
const STICKY_SEARCH = 'sticky top-0 z-20 -mx-6 -mt-5 bg-surface-card px-6 pb-1 pt-5'
/** A chip of the category row; the picked one wears the category's own colour. */
const CHIP = 'inline-flex items-center gap-1.5 rounded-full border px-3 py-1 font-semibold'
const CHIP_OFF = 'border-edge-faint bg-surface-card text-content-muted hover:text-content'
const CHIP_NONE_ON = 'border-content bg-surface-card text-content'
const ROW_ACTION = 'grid h-8 w-8 flex-none place-items-center rounded-[9px] text-content-faint hover:bg-surface-secondary'
interface AddPlaceToCollectionModalProps {
isOpen: boolean
collectionId: number
@@ -31,10 +46,11 @@ interface AddPlaceToCollectionModalProps {
}
/**
* Add a place to the current list — everything in one view: a search field that
* fills in the location when a result is picked, plus name / category / status /
* markdown description / links, all editable together before saving. Stays open
* after each add so several places can be added in a row.
* Add a place to the current list, everything in one view: the name typed into
* the head band, a search that fills it and the location in when a result is
* picked, plus status, category, a markdown description and links, all editable
* together before saving. Stays open after each add so several places can be
* added in a row.
*/
export default function AddPlaceToCollectionModal({ isOpen, collectionId, collectionName, categories, onClose, onAdded, t }: AddPlaceToCollectionModalProps): React.ReactElement {
const { language } = useTranslation()
@@ -60,6 +76,8 @@ export default function AddPlaceToCollectionModal({ isOpen, collectionId, collec
const [saving, setSaving] = useState(false)
const descRef = useRef<HTMLTextAreaElement>(null)
const searchRef = useRef<HTMLInputElement>(null)
const labelId = useId()
const fieldId = useId()
const reset = () => { setQuery(''); setResults([]); setNoResults(false); setPicked(null); setName(''); setAddress(''); setLat(''); setLng(''); setCategoryId(null); setDescription(''); setLinks([]); setStatus('idea') }
useEffect(() => { if (!isOpen) reset() }, [isOpen])
@@ -141,157 +159,202 @@ export default function AddPlaceToCollectionModal({ isOpen, collectionId, collec
const match = text.match(/^(-?\d+(?:\.\d*)?)(?:\s*[,;]\s*|\s+)(-?\d+(?:\.\d*)?)$/)
if (match) { e.preventDefault(); setLat(match[1]); setLng(match[2]) }
}
const coordInputClass = 'w-full px-3 py-2 rounded-lg border border-edge bg-surface-input text-content text-[14px] outline-none focus:border-accent'
const header = (
<DialogHeader
tile={<DialogTile><MapPinned size={20} strokeWidth={1.9} className="text-content-muted" /></DialogTile>}
tint={NEUTRAL_TINT}
labelId={labelId}
onClose={onClose}
eyebrow={t('collections.addPlace')}
// Typed into the band, as in the planner's place dialog. It takes no focus
// on opening: the dialog starts at the search, which fills the name in.
titleInput={{ value: name, onChange: setName, label: t('common.name'), placeholder: t('common.name') }}
sub={<><Bookmark size={11} strokeWidth={2.2} className="mr-1 inline-block align-[-1px]" />{collectionName}</>}
/>
)
const footer = (
<DialogFooter>
<FooterSpacer />
<DialogButton onClick={onClose}>{t('common.cancel')}</DialogButton>
<DialogButton
variant="primary"
onClick={() => void save()}
disabled={saving || !name.trim()}
icon={saving ? <Loader2 size={14} className="animate-spin" /> : <Check size={14} strokeWidth={2.2} />}
>
{t('common.add')}
</DialogButton>
</DialogFooter>
)
return (
<Modal
isOpen={isOpen}
onClose={onClose}
title={t('collections.addPlace')}
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={saving || !name.trim()} className="px-3 py-1.5 rounded-lg bg-accent text-accent-text text-[13px] font-semibold disabled:opacity-50 inline-flex items-center gap-1.5">
{saving ? <Loader2 size={14} className="animate-spin" /> : <Check size={14} />} {t('common.add')}
</button>
</div>
}
>
<div className="flex flex-col gap-4">
{/* Search — picking a result fills the location below. Pinned to the top of
the scrolling dialog body: the dialog stays open after an add, and the
search row used to sit above the viewport once the form was scrolled,
so it looked like the button had vanished (#1921). The negative margins
let its background cover the body padding while it is stuck. */}
<div className="sticky top-0 z-20 -mx-6 -mt-6 -mb-4 px-6 pt-6 pb-4 bg-surface-card">
<div className="relative">
<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
ref={searchRef}
value={query}
onChange={e => { setQuery(e.target.value); setNoResults(false) }}
onKeyDown={e => { if (e.key === 'Enter') { e.preventDefault(); 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>
<DialogShell open={isOpen} onClose={onClose} labelledBy={labelId} width="detail" align="top" header={header} footer={footer}>
{/* Search: picking a result fills the name and the location below. */}
<div className={STICKY_SEARCH}>
<div className="relative">
<div className="flex items-stretch gap-2">
<div className="relative min-w-0 flex-1">
<Search size={14} className="pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-content-faint" aria-hidden="true" />
<input
autoFocus
ref={searchRef}
type="text"
value={query}
onChange={e => { setQuery(e.target.value); setNoResults(false) }}
onKeyDown={e => { if (e.key === 'Enter') { e.preventDefault(); search() } }}
aria-label={t('collections.addPlaceSearch')}
placeholder={t('collections.addPlaceSearch')}
className={`${INPUT} pl-8`}
/>
</div>
{(results.length > 0 || noResults) && (
<div className="absolute z-20 left-0 right-0 mt-1.5 max-h-[280px] overflow-y-auto rounded-xl border border-edge bg-surface-card shadow-lg p-1.5 flex flex-col gap-1">
<div className="flex items-center justify-between px-2 py-1">
<span className="text-[11px] font-semibold uppercase tracking-wide text-content-faint">{t('common.search')}</span>
<button type="button" onClick={dismissResults} className="p-1 rounded-md text-content-faint hover:text-content hover:bg-surface-hover" aria-label={t('common.close')}><X size={13} /></button>
</div>
{noResults ? (
<div className="px-2.5 py-3 text-center text-[12.5px] text-content-faint">{t('planner.noPlacesFound')}</div>
) : results.map((r, i) => (
<button key={i} type="button" onClick={() => pick(r)} className="flex items-center gap-3 px-2.5 py-2 rounded-lg text-left hover:bg-surface-hover transition-colors">
<div className="w-8 h-8 min-w-[32px] rounded-lg bg-surface-secondary flex items-center justify-center text-content-faint shrink-0"><MapPin size={15} /></div>
<div className="flex flex-col min-w-0 flex-1">
<span className="text-[13px] font-semibold text-content truncate">{str(r.name)}</span>
{str(r.address) && <span className="text-[11.5px] text-content-faint truncate">{str(r.address)}</span>}
</div>
<DialogButton
variant="primary"
onClick={() => void search()}
disabled={!query.trim() || searching}
icon={searching ? <Loader2 size={14} className="animate-spin" /> : <Search size={14} strokeWidth={2.2} />}
>
{t('common.search')}
</DialogButton>
</div>
{(results.length > 0 || noResults) && (
<div
role="group"
aria-label={t('common.search')}
className="absolute left-0 right-0 z-20 mt-1.5 flex max-h-[280px] flex-col gap-0.5 overflow-y-auto rounded-[12px] border border-edge-faint bg-surface-card p-1 shadow-dropdown"
>
<div className="flex items-center justify-between py-0.5 pl-2.5 pr-0.5">
<span className="font-geist font-bold uppercase tracking-[.08em] text-content-faint" style={fs(9.5)}>{t('common.search')}</span>
<Tooltip label={t('common.close')}>
<button type="button" onClick={dismissResults} aria-label={t('common.close')}
className="grid h-7 w-7 place-items-center rounded-[8px] text-content-faint hover:bg-surface-hover hover:text-content">
<X size={13} />
</button>
))}
</Tooltip>
</div>
)}
</div>
{noResults ? (
<div className="px-2.5 py-3 text-center text-content-faint" style={fs(12.5, 'body')}>{t('planner.noPlacesFound')}</div>
) : results.map((r, i) => (
<button key={i} type="button" onClick={() => pick(r)} className="flex w-full items-center gap-2.5 rounded-[8px] px-2.5 py-2 text-left hover:bg-surface-hover">
<span className="grid h-8 w-8 flex-none place-items-center rounded-[9px] bg-surface-secondary text-content-faint"><MapPin size={15} /></span>
<span className="min-w-0 flex-1">
<span className="block truncate font-semibold text-content" style={fs(13, 'body')}>{str(r.name)}</span>
{str(r.address) && <span className="block truncate text-content-faint" style={fs(11.5)}>{str(r.address)}</span>}
</span>
</button>
))}
</div>
)}
</div>
</div>
{/* Name */}
<div>
<label className="block text-[12px] font-medium text-content-secondary mb-1.5">{t('common.name')}</label>
<input value={name} onChange={e => setName(e.target.value)} placeholder={t('common.name')} className="w-full px-3 py-2 rounded-lg border border-edge bg-surface-input text-content text-[14px] outline-none focus:border-accent" />
{/* Where it is: filled in by a picked result, but also typeable, so a place
can be added by GPS alone (#1435). */}
<div className={PANEL}>
<EditorField label={t('places.formAddress')} htmlFor={`${fieldId}-address`}>
<input
id={`${fieldId}-address`}
type="text"
value={address}
onChange={e => setAddress(e.target.value)}
placeholder={t('places.formAddressPlaceholder')}
className={INPUT}
/>
</EditorField>
<div role="group" aria-label={t('collections.coordinates')} className={GRID_2}>
<EditorField label={t('places.formLatLabel')} htmlFor={`${fieldId}-lat`}>
<NumericInput id={`${fieldId}-lat`} mode="signed" value={lat} onValueChange={setLat} onPaste={coordPaste} placeholder={t('places.formLat')} className={INPUT} />
</EditorField>
<EditorField label={t('places.formLngLabel')} htmlFor={`${fieldId}-lng`}>
<NumericInput id={`${fieldId}-lng`} mode="signed" value={lng} onValueChange={setLng} onPaste={coordPaste} placeholder={t('places.formLng')} className={INPUT} />
</EditorField>
</div>
</div>
{/* Address + coordinates — editable so a place can be added by GPS alone */}
<div>
<label className="block text-[12px] font-medium text-content-secondary mb-1.5">{t('places.formAddress')}</label>
<input value={address} onChange={e => setAddress(e.target.value)} placeholder={t('places.formAddressPlaceholder')} className={coordInputClass} />
<div className="grid grid-cols-2 gap-2 mt-2">
<NumericInput mode="signed" value={lat} onValueChange={setLat} onPaste={coordPaste} placeholder={t('places.formLat')} className={coordInputClass} />
<NumericInput mode="signed" value={lng} onValueChange={setLng} onPaste={coordPaste} placeholder={t('places.formLng')} className={coordInputClass} />
</div>
</div>
<EditorField label={t('mobileCollections.status')}>
<Segmented<CollectionStatus>
label={t('mobileCollections.status')}
value={status}
onChange={setStatus}
options={STATUS_ORDER.map(s => {
const Icon = STATUS_META[s].icon
return { value: s, label: t(STATUS_META[s].labelKey), icon: <Icon size={13} style={{ color: STATUS_META[s].color }} /> }
})}
/>
</EditorField>
{/* Status */}
<div>
<div className="flex flex-wrap gap-1.5">
{STATUS_ORDER.map(s => {
const Icon = STATUS_META[s].icon
const on = status === s
{categories.length > 0 && (
<EditorField label={t('collections.category')}>
<div role="group" aria-label={t('collections.category')} className="flex flex-wrap gap-1.5">
<button
type="button"
onClick={() => setCategoryId(null)}
aria-pressed={categoryId == null}
className={`${CHIP} ${categoryId == null ? CHIP_NONE_ON : CHIP_OFF}`}
style={fs(12, 'body')}
>
{t('collections.noCategory')}
</button>
{categories.map(cat => {
const Icon = getCategoryIcon(cat.icon ?? undefined)
const on = categoryId === cat.id
const col = cat.color || '#6366f1' // theme-lint-disable: the category's own colour, and the default one without a colour is drawn in
return (
<button key={s} type="button" onClick={() => setStatus(s)} className={`inline-flex items-center gap-1.5 px-3 py-1.5 rounded-full text-[12px] font-semibold border transition-colors ${on ? 'bg-inverse text-inverse-text border-transparent' : 'bg-surface-card text-content-secondary border-edge hover:bg-surface-hover'}`}>
<Icon size={13} style={{ color: on ? undefined : STATUS_META[s].color }} /> {t(STATUS_META[s].labelKey)}
<button
key={cat.id}
type="button"
onClick={() => setCategoryId(cat.id)}
aria-pressed={on}
className={`${CHIP} ${CHIP_OFF}`}
style={{ ...fs(12, 'body'), ...(on ? { color: col, background: `color-mix(in oklch, ${col} 15%, transparent)`, borderColor: `color-mix(in oklch, ${col} 40%, transparent)` } : {}) }}
>
<Icon size={13} /> {cat.name}
</button>
)
})}
</div>
</div>
</EditorField>
)}
{/* Category */}
{categories.length > 0 && (
<div>
<label className="block text-[12px] font-medium text-content-secondary mb-1.5">{t('collections.category')}</label>
<div className="flex flex-wrap gap-1.5">
<button type="button" onClick={() => setCategoryId(null)} className={`px-3 py-1.5 rounded-full text-[12px] font-medium border transition-colors ${categoryId == null ? 'bg-inverse text-inverse-text border-transparent' : 'bg-surface-card text-content-secondary border-edge hover:bg-surface-hover'}`}>
{t('collections.noCategory')}
</button>
{categories.map(cat => {
const Icon = getCategoryIcon(cat.icon ?? undefined)
const on = categoryId === cat.id
const col = cat.color || '#6366f1'
return (
<button
key={cat.id}
type="button"
onClick={() => setCategoryId(cat.id)}
className="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-full text-[12px] font-medium border transition-colors bg-surface-card border-edge hover:bg-surface-hover"
style={on ? { color: col, background: `color-mix(in oklch, ${col} 15%, transparent)`, borderColor: `color-mix(in oklch, ${col} 40%, transparent)` } : undefined}
>
<Icon size={13} /> {cat.name}
</button>
)
})}
</div>
<DialogSection
label={<label htmlFor={`${fieldId}-description`}>{t('collections.description')}</label>}
action={<NoteFormatToolbar textareaRef={descRef} onChange={setDescription} compact customTooltips />}
>
<textarea
id={`${fieldId}-description`}
ref={descRef}
value={description}
onChange={e => setDescription(e.target.value)}
rows={3}
placeholder={t('collections.descriptionPlaceholder')}
className={`${TEXTAREA} resize-y`}
/>
{description.trim() && (
<div className="collab-note-md mt-2 text-content-secondary" style={fs(13, 'body')}>
<Markdown remarkPlugins={[remarkGfm, remarkBreaks]}>{description}</Markdown>
</div>
)}
</DialogSection>
{/* Description */}
<div>
<label className="block text-[12px] font-medium text-content-secondary mb-1.5">{t('collections.description')}</label>
<MarkdownToolbar textareaRef={descRef} onUpdate={setDescription} />
<textarea ref={descRef} 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" />
{description.trim() && (
<div className="collab-note-md mt-2 text-[13px] text-content-secondary"><Markdown remarkPlugins={[remarkGfm, remarkBreaks]}>{description}</Markdown></div>
)}
</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-28 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>
<DialogSection label={t('collections.links')}>
<div className="flex flex-col gap-2">
{links.map((l, i) => (
<div key={i} className="flex items-center gap-2">
<div className="w-28 flex-none">
<input value={l.label ?? ''} onChange={e => setLink(i, { label: e.target.value })} placeholder={t('collections.linkLabel')} className={INPUT} />
</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>
<input value={l.url} onChange={e => setLink(i, { url: e.target.value })} placeholder="https://…" className={`${INPUT} flex-1`} />
<Tooltip label={t('common.delete')}>
<button type="button" onClick={() => setLinks(links.filter((_, idx) => idx !== i))} aria-label={t('common.delete')} className={`${ROW_ACTION} hover:text-danger`}>
<Trash2 size={14} />
</button>
</Tooltip>
</div>
))}
<AddRowButton onClick={() => setLinks([...links, { url: '' }])}>{t('collections.addLink')}</AddRowButton>
</div>
</div>
</Modal>
</DialogSection>
</DialogShell>
)
}
@@ -65,10 +65,10 @@ describe('BulkAssignLabelModal', () => {
const berlinRow = screen.getByRole('button', { name: 'Berlin' });
await user.click(berlinRow);
expect(berlinRow).toHaveClass('border-accent');
expect(berlinRow).toHaveAttribute('aria-pressed', 'true');
await user.click(berlinRow);
expect(berlinRow).not.toHaveClass('border-accent');
expect(berlinRow).toHaveAttribute('aria-pressed', 'false');
expect(screen.getByRole('button', { name: /^Assign label$/ })).toBeDisabled();
});
@@ -83,7 +83,7 @@ describe('BulkAssignLabelModal', () => {
await waitFor(() => expect(props.onAssign).toHaveBeenCalledWith([2, 1]));
// Selection resets so the modal is ready for the next batch.
await waitFor(() => expect(screen.getByRole('button', { name: /^Assign label$/ })).toBeDisabled());
expect(screen.getByRole('button', { name: 'Berlin' })).not.toHaveClass('border-accent');
expect(screen.getByRole('button', { name: 'Berlin' })).toHaveAttribute('aria-pressed', 'false');
});
it('FE-COMP-BULKLABEL-006: a second click while the assign is pending is ignored', async () => {
@@ -1,6 +1,6 @@
import React, { useState } from 'react'
import React, { useId, useState } from 'react'
import { Check, Loader2, Settings2, Tags } from 'lucide-react'
import Modal from '../shared/Modal'
import { DialogButton, DialogFooter, DialogHeader, DialogShell, DialogTile, FooterSpacer, NEUTRAL_TINT, fs } from '../shared/DialogShell'
import type { CollectionLabel } from '@trek/shared'
import type { TranslationFn } from '../../types'
@@ -24,6 +24,7 @@ interface BulkAssignLabelModalProps {
export default function BulkAssignLabelModal({ isOpen, labels, count, onAssign, onManage, onClose, t }: BulkAssignLabelModalProps): React.ReactElement {
const [picked, setPicked] = useState<number[]>([])
const [busy, setBusy] = useState(false)
const labelId = useId()
const toggle = (id: number) => setPicked(picked.includes(id) ? picked.filter(x => x !== id) : [...picked, id])
@@ -39,54 +40,66 @@ export default function BulkAssignLabelModal({ isOpen, labels, count, onAssign,
}
return (
<Modal isOpen={isOpen} onClose={onClose} title={t('collections.labels.assignN', { count })} size="lg">
<DialogShell
open={isOpen}
onClose={onClose}
labelledBy={labelId}
width="narrow"
header={(
<DialogHeader
tile={<DialogTile><Tags size={20} strokeWidth={1.9} className="text-content-muted" /></DialogTile>}
tint={NEUTRAL_TINT}
labelId={labelId}
onClose={onClose}
title={t('collections.labels.assignN', { count })}
/>
)}
footer={labels.length === 0 ? undefined : (
<DialogFooter>
<DialogButton onClick={onManage} icon={<Settings2 size={14} strokeWidth={2.2} />}>{t('collections.labels.manage')}</DialogButton>
<FooterSpacer />
<DialogButton onClick={onClose}>{t('common.cancel')}</DialogButton>
<DialogButton
variant="primary"
onClick={assign}
disabled={picked.length === 0 || busy}
icon={busy ? <Loader2 size={14} className="animate-spin" /> : <Check size={14} strokeWidth={2.2} />}
>
{t('collections.labels.assign')}
</DialogButton>
</DialogFooter>
)}
>
{labels.length === 0 ? (
<div className="flex flex-col items-center gap-3 py-6 text-center">
<Tags size={26} className="text-content-faint" />
<p className="text-[13px] text-content-faint">{t('collections.labels.emptyHint')}</p>
<button type="button" onClick={onManage} className="flex items-center gap-1.5 px-3 py-2 rounded-lg border border-edge text-[13px] text-content hover:bg-surface-hover">
<Settings2 size={14} /> {t('collections.labels.manage')}
</button>
<div className="flex flex-col items-center px-4 py-6 text-center">
<div className="mb-3 grid h-11 w-11 place-items-center rounded-2xl bg-surface-secondary text-content-faint">
<Tags size={20} />
</div>
<p className="m-0 mb-4 text-content-faint" style={fs(13, 'body')}>{t('collections.labels.emptyHint')}</p>
<DialogButton variant="primary" onClick={onManage} icon={<Settings2 size={14} strokeWidth={2.2} />}>{t('collections.labels.manage')}</DialogButton>
</div>
) : (
<div className="flex flex-col gap-3">
<div className="flex flex-col gap-1 max-h-[46vh] overflow-y-auto -mx-1 px-1">
{labels.map(l => {
const on = picked.includes(l.id)
return (
<button
key={l.id}
type="button"
onClick={() => toggle(l.id)}
className={`flex items-center gap-2.5 px-3 py-2.5 rounded-xl border text-left transition-colors ${on ? 'border-accent bg-accent/10' : 'border-edge bg-surface-card hover:bg-surface-hover'}`}
>
<span className="w-3.5 h-3.5 rounded-full shrink-0" style={{ background: l.color || '#6366f1' }} />
<span className="flex-1 min-w-0 text-[13px] font-medium text-content truncate">{l.name}</span>
{on && <Check size={15} className="text-accent shrink-0" />}
</button>
)
})}
</div>
{/* nowrap on all three: the labels are long in several locales and used to
wrap into two lines inside the buttons before the dialog got wider. */}
<div className="flex justify-end gap-2 pt-2 border-t border-edge">
<button type="button" onClick={onManage} className="mr-auto flex items-center gap-1.5 px-3 py-2 rounded-lg text-[13px] text-content-secondary whitespace-nowrap hover:bg-surface-hover">
<Settings2 size={14} /> {t('collections.labels.manage')}
</button>
<button type="button" onClick={onClose} className="px-3 py-2 rounded-lg border border-edge text-content-secondary text-[13px] whitespace-nowrap hover:bg-surface-hover">
{t('common.cancel')}
</button>
<button
type="button"
onClick={assign}
disabled={picked.length === 0 || busy}
className="flex items-center gap-1.5 px-3 py-2 rounded-lg bg-accent text-accent-text text-[13px] font-semibold whitespace-nowrap hover:opacity-90 disabled:opacity-50"
>
{busy ? <Loader2 size={14} className="animate-spin" /> : <Check size={14} />} {t('collections.labels.assign')}
</button>
</div>
<div className="flex flex-col gap-0.5 rounded-[14px] border border-edge-faint bg-surface-secondary p-1.5">
{labels.map(l => {
const on = picked.includes(l.id)
return (
<button
key={l.id}
type="button"
aria-pressed={on}
onClick={() => toggle(l.id)}
className={`flex min-h-[44px] items-center gap-3 rounded-[10px] px-3 py-2 text-left ${on ? 'bg-surface-card shadow-sm' : 'hover:bg-surface-card'}`}
>
<span className="h-2.5 w-2.5 flex-none rounded-full" style={{ background: l.color || '#6366f1' }} /* theme-lint-disable: the label's own colour, and the first swatch of the label manager for one without */ />
<span className="min-w-0 flex-1 truncate font-semibold text-content" style={fs(13, 'body')}>{l.name}</span>
<span className={`grid h-6 w-6 flex-none place-items-center rounded-[8px] ${on ? 'bg-accent text-accent-text' : 'border border-edge bg-surface-card text-transparent'}`}>
<Check size={13} />
</span>
</button>
)
})}
</div>
)}
</Modal>
</DialogShell>
)
}
@@ -1,6 +1,7 @@
import React, { useEffect, useMemo, useState } from 'react'
import React, { useEffect, useId, useMemo, useState } from 'react'
import { Search, MapPin, Loader2, Copy, CalendarDays } from 'lucide-react'
import Modal from '../shared/Modal'
import { DialogButton, DialogFooter, DialogHeader, DialogShell, DialogTile, FooterSpacer, NEUTRAL_TINT, fs } from '../shared/DialogShell'
import { INPUT } from '../shared/dialogParts'
import { useToast } from '../shared/Toast'
import { tripsApi } from '../../api/client'
import { getApiErrorMessage } from '../../utils/apiError'
@@ -35,6 +36,7 @@ interface CopyToTripModalProps {
export default function CopyToTripModal({ isOpen, onClose, placeIds, onCopy, t }: CopyToTripModalProps): React.ReactElement | null {
const toast = useToast()
const { language } = useTranslation()
const labelId = useId()
const [trips, setTrips] = useState<TripOption[]>([])
const [loading, setLoading] = useState(false)
const [search, setSearch] = useState('')
@@ -90,59 +92,75 @@ export default function CopyToTripModal({ isOpen, onClose, placeIds, onCopy, t }
}
return (
<Modal
isOpen
<DialogShell
onClose={onClose}
title={placeIds.length > 1 ? t('collections.copyN', { count: placeIds.length }) : t('collections.copyToTripTitle')}
size="sm"
labelledBy={labelId}
width="narrow"
// The list shrinks while the search narrows it; a pinned top edge keeps the field still.
align="top"
header={(
<DialogHeader
tile={<DialogTile><Copy size={20} strokeWidth={1.9} className="text-content-muted" /></DialogTile>}
tint={NEUTRAL_TINT}
labelId={labelId}
onClose={onClose}
title={placeIds.length > 1 ? t('collections.copyN', { count: placeIds.length }) : t('collections.copyToTripTitle')}
/>
)}
footer={(
<DialogFooter>
<FooterSpacer />
<DialogButton onClick={onClose}>{t('common.cancel')}</DialogButton>
</DialogFooter>
)}
>
<div className="flex flex-col gap-3">
<div className="relative">
<Search size={14} className="absolute left-2.5 top-1/2 -translate-y-1/2 text-content-faint" />
<input
autoFocus
value={search}
onChange={e => setSearch(e.target.value)}
placeholder={t('collections.copyToTripSearch')}
className="w-full pl-8 pr-3 py-2 rounded-lg border border-edge bg-surface-input text-content text-[13px] outline-none focus:border-accent"
/>
</div>
{loading ? (
<div className="flex items-center justify-center py-10 text-content-faint">
<Loader2 size={20} className="animate-spin" />
</div>
) : filtered.length === 0 ? (
<p className="text-center text-[13px] text-content-faint py-10">{t('collections.noTrips')}</p>
) : (
<div className="flex flex-col gap-1 max-h-[50vh] overflow-y-auto -mx-1 px-1">
{filtered.map(trip => {
const busy = busyTripId === trip.id
return (
<button
key={trip.id}
type="button"
onClick={() => handleCopy(trip.id)}
disabled={busy}
className="flex items-center gap-3 px-3 py-2.5 rounded-xl border border-edge bg-surface-card text-left hover:bg-surface-hover transition-colors disabled:opacity-60"
>
<span className="w-9 h-9 rounded-lg bg-surface-secondary flex items-center justify-center shrink-0 overflow-hidden text-content-faint">
{trip.cover_image ? <img src={trip.cover_image} alt="" className="w-full h-full object-cover" /> : <MapPin size={15} />}
</span>
<span className="flex-1 min-w-0">
<span className="block text-[13px] font-medium text-content truncate">{trip.title}</span>
{dateRange(trip) && (
<span className="flex items-center gap-1 text-[11.5px] text-content-faint truncate">
<CalendarDays size={11} className="shrink-0" /> {dateRange(trip)}
</span>
)}
</span>
{busy ? <Loader2 size={15} className="animate-spin text-content-faint shrink-0" /> : <Copy size={15} className="text-content-faint shrink-0" />}
</button>
)
})}
</div>
)}
<div className="relative">
<Search size={14} className="pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-content-faint" aria-hidden="true" />
<input
autoFocus
value={search}
onChange={e => setSearch(e.target.value)}
placeholder={t('collections.copyToTripSearch')}
aria-label={t('collections.copyToTripSearch')}
className={`${INPUT} pl-8`}
/>
</div>
</Modal>
{loading ? (
<div className="flex items-center justify-center py-8 text-content-faint">
<Loader2 size={20} className="animate-spin" />
</div>
) : filtered.length === 0 ? (
<p className="m-0 rounded-[12px] bg-surface-secondary px-4 py-6 text-center text-content-faint" style={fs(12.5, 'body')}>{t('collections.noTrips')}</p>
) : (
<div className="flex flex-col gap-0.5 rounded-[14px] border border-edge-faint bg-surface-secondary p-1.5">
{filtered.map(trip => {
const busy = busyTripId === trip.id
const range = dateRange(trip)
return (
<button
key={trip.id}
type="button"
onClick={() => handleCopy(trip.id)}
disabled={busy}
className="flex min-h-[52px] items-center gap-3 rounded-[10px] px-2.5 py-2 text-left hover:bg-surface-card disabled:opacity-60"
>
<span className="grid h-9 w-9 flex-none place-items-center overflow-hidden rounded-[9px] bg-surface-tertiary text-content-faint">
{trip.cover_image ? <img src={trip.cover_image} alt="" className="h-full w-full object-cover" /> : <MapPin size={15} />}
</span>
<span className="min-w-0 flex-1">
<span className="block truncate font-semibold text-content" style={fs(13, 'body')}>{trip.title}</span>
{range && (
<span className="mt-0.5 flex items-center gap-1 truncate text-content-faint" style={fs(11.5)}>
<CalendarDays size={11} className="flex-none" /> {range}
</span>
)}
</span>
{busy ? <Loader2 size={15} className="flex-none animate-spin text-content-faint" /> : <Copy size={15} className="flex-none text-content-faint" />}
</button>
)
})}
</div>
)}
</DialogShell>
)
}
@@ -154,7 +154,8 @@ describe('ImportCollectionModal with a GPX (#2301)', () => {
it('FE-COMP-COLLIMPORT-011: says which files it takes', () => {
renderModal();
expect(screen.getByText('.trekcollection.json · .gpx')).toBeInTheDocument();
expect(screen.getByText('.trekcollection.json')).toBeInTheDocument();
expect(screen.getByText('.gpx')).toBeInTheDocument();
const input = document.querySelector('input[type="file"]') as HTMLInputElement;
expect(input.accept).toContain('.gpx');
});
@@ -1,6 +1,7 @@
import React, { useMemo, useRef, useState } from 'react'
import { Upload, FileJson, Loader2, MapPin, Tag, AlertCircle, Route, Info, Plus, FolderInput, Check, Search, Bookmark } from 'lucide-react'
import Modal from '../shared/Modal'
import React, { useId, useMemo, useRef, useState } from 'react'
import { Upload, FileDown, FileJson, Loader2, MapPin, Tag, AlertCircle, Route, Info, Plus, FolderInput, Check, Search, Bookmark } from 'lucide-react'
import { DialogButton, DialogFooter, DialogHeader, DialogShell, DialogTile, FooterSpacer, NEUTRAL_TINT, fs } from '../shared/DialogShell'
import { EditorField, INPUT } from '../shared/dialogParts'
import { MAX_COLLECTION_FILE_PLACES, type Collection, type CollectionFile } from '@trek/shared'
import type { TranslationFn } from '../../types'
import { getApiErrorMessage } from '../../types'
@@ -36,6 +37,18 @@ const ERROR_KEYS: Record<CollectionFileError, string> = {
'too-many-places': 'collections.file.errorTooManyPlaces',
}
/**
* The square that stands for a list: its colour as a wash, the icon in the
* colour itself. A list without one is drawn in the default the lists rail uses.
*/
function swatch(color?: string | null): React.CSSProperties {
const tone = color || '#6366f1' // theme-lint-disable: a list's own colour, and the default one without a colour is drawn in
return { background: `color-mix(in srgb, ${tone} 14%, transparent)`, color: tone }
}
const ROWS = 'flex flex-col gap-0.5 rounded-[14px] border border-edge-faint bg-surface-secondary p-1.5'
const HINT = 'm-0 leading-normal text-content-faint'
/** What a GPX held besides its places, said before anything is imported. */
function GpxNotes({ leftovers, placeCount, t }: { leftovers: GpxLeftovers; placeCount: number; t: TranslationFn }) {
const notes = [
@@ -45,10 +58,10 @@ function GpxNotes({ leftovers, placeCount, t }: { leftovers: GpxLeftovers; place
].filter(Boolean)
if (notes.length === 0) return null
return (
<ul className="flex flex-col gap-1">
<ul className="m-0 flex list-none flex-col gap-1 p-0">
{notes.map(note => (
<li key={note as string} className="flex items-start gap-2 text-[12px] text-content-muted">
<Info size={13} className="shrink-0 mt-0.5 text-content-faint" />
<li key={note as string} className="flex items-start gap-2 text-content-muted" style={fs(12, 'body')}>
<Info size={13} className="mt-0.5 flex-none text-content-faint" />
<span>{note}</span>
</li>
))}
@@ -69,17 +82,17 @@ function TargetCard({ active, icon: Icon, title, hint, onClick }: {
type="button"
onClick={onClick}
aria-pressed={active}
className={`relative flex flex-col items-start gap-1.5 px-3 py-3 rounded-xl border text-left transition-colors ${
active ? 'border-accent bg-surface-hover' : 'border-edge hover:bg-surface-hover'
className={`relative flex flex-col items-start gap-1.5 rounded-[14px] border p-3 text-left transition-colors ${
active ? 'border-accent bg-surface-card shadow-sm' : 'border-edge-faint bg-surface-secondary hover:bg-surface-card'
}`}
>
<span className={`w-8 h-8 rounded-lg flex items-center justify-center ${active ? 'bg-accent text-accent-text' : 'bg-surface-input text-content-muted'}`}>
<span className={`grid h-8 w-8 place-items-center rounded-[10px] ${active ? 'bg-accent text-accent-text' : 'bg-surface-card text-content-muted shadow-sm'}`}>
<Icon size={15} />
</span>
<span className="text-[13px] font-semibold text-content">{title}</span>
<span className="text-[11.5px] text-content-faint leading-snug">{hint}</span>
<span className="font-semibold text-content" style={fs(13, 'body')}>{title}</span>
<span className="leading-snug text-content-faint" style={fs(11.5)}>{hint}</span>
{active && (
<span className="absolute top-2 right-2 w-4 h-4 rounded-full bg-accent text-accent-text flex items-center justify-center">
<span className="absolute right-2 top-2 grid h-4 w-4 place-items-center rounded-full bg-accent text-accent-text">
<Check size={11} strokeWidth={3} />
</span>
)}
@@ -104,16 +117,17 @@ function ListChoice({ lists, selectedId, onSelect, t }: {
<div className="flex flex-col gap-2">
{lists.length > 5 && (
<div className="relative">
<Search size={14} className="absolute left-2.5 top-1/2 -translate-y-1/2 text-content-faint" />
<Search size={14} className="pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-content-faint" aria-hidden="true" />
<input
value={search}
onChange={e => setSearch(e.target.value)}
aria-label={t('collections.file.searchLists')}
placeholder={t('collections.file.searchLists')}
className="w-full pl-8 pr-3 py-2 rounded-lg border border-edge bg-surface-input text-content text-[13px] outline-none focus:border-accent"
className={`${INPUT} pl-8`}
/>
</div>
)}
<div className="flex flex-col gap-1 max-h-[34vh] overflow-y-auto -mx-1 px-1">
<div className={`${ROWS} max-h-[34vh] overflow-y-auto`}>
{shown.map(list => {
const active = list.id === selectedId
return (
@@ -122,23 +136,21 @@ function ListChoice({ lists, selectedId, onSelect, t }: {
type="button"
onClick={() => onSelect(list.id)}
aria-pressed={active}
className={`flex items-center gap-3 px-3 py-2.5 rounded-xl border text-left transition-colors ${
active ? 'border-accent bg-surface-hover' : 'border-edge bg-surface-card hover:bg-surface-hover'
}`}
className={`flex min-h-[46px] items-center gap-3 rounded-[10px] px-2.5 py-2 text-left ${active ? 'bg-surface-card shadow-sm' : 'hover:bg-surface-card'}`}
>
<span className="w-9 h-9 min-w-[36px] rounded-lg flex items-center justify-center shrink-0 text-white" style={{ background: list.color || '#6366f1' }}>
<span className="grid h-8 w-8 flex-none place-items-center rounded-[9px]" style={swatch(list.color)}>
<Bookmark size={15} />
</span>
<span className="flex-1 min-w-0">
<span className="block text-[13px] font-semibold text-content truncate">{list.name}</span>
<span className="block text-[11.5px] text-content-faint">{t('collections.placeCount', { count: list.place_count ?? 0 })}</span>
<span className="min-w-0 flex-1">
<span className="block truncate font-semibold text-content" style={fs(13, 'body')}>{list.name}</span>
<span className="block text-content-faint" style={fs(11.5)}>{t('collections.placeCount', { count: list.place_count ?? 0 })}</span>
</span>
{active && <Check size={16} className="shrink-0 text-accent" />}
{active && <Check size={16} className="flex-none text-accent-on" />}
</button>
)
})}
{shown.length === 0 && (
<p className="text-center text-[13px] text-content-faint py-6">{t('collections.noOtherLists')}</p>
<p className="m-0 py-6 text-center text-content-faint" style={fs(13, 'body')}>{t('collections.noOtherLists')}</p>
)}
</div>
</div>
@@ -169,6 +181,8 @@ export default function ImportCollectionModal({
onImport, onImportInto, lists, defaultListId, onReadGpx, onClose, t,
}: ImportCollectionModalProps): React.ReactElement {
const inputRef = useRef<HTMLInputElement>(null)
const titleId = useId()
const nameId = useId()
const [file, setFile] = useState<CollectionFile | null>(null)
const [leftovers, setLeftovers] = useState<GpxLeftovers | null>(null)
const [name, setName] = useState('')
@@ -243,131 +257,148 @@ export default function ImportCollectionModal({
const nothingToImport = !!leftovers && !!file && file.places.length === 0
return (
<Modal
isOpen
<DialogShell
onClose={onClose}
title={t('collections.file.importTitle')}
size="sm"
footer={
<div className="flex justify-end gap-2">
<button type="button" onClick={onClose} className="px-4 py-2 rounded-lg text-[13px] font-medium text-content-muted hover:bg-surface-hover transition-colors">
{t('common.cancel')}
</button>
<button
type="button"
onClick={submit}
disabled={!file || busy || nothingToImport || (intoExisting ? listId == null : !name.trim())}
className="px-4 py-2 rounded-lg text-[13px] font-semibold bg-accent text-accent-text disabled:opacity-50 transition-opacity inline-flex items-center gap-2"
>
{busy && <Loader2 size={14} className="animate-spin" />}
{intoExisting ? t('collections.file.confirmInto') : t('collections.file.confirm')}
</button>
</div>
}
>
<div className="flex flex-col gap-3">
<input
ref={inputRef}
type="file"
accept=".json,application/json,.gpx,application/gpx+xml"
className="hidden"
onChange={e => { void take(e.target.files?.[0]); e.target.value = '' }}
labelledBy={titleId}
width="narrow"
// The body grows once a file is read; the top edge stays where it was.
align="top"
header={(
<DialogHeader
tile={<DialogTile><FileDown size={20} strokeWidth={1.9} className="text-content-muted" /></DialogTile>}
tint={NEUTRAL_TINT}
labelId={titleId}
onClose={onClose}
title={t('collections.file.importTitle')}
/>
{!file ? (
<button
type="button"
onClick={() => inputRef.current?.click()}
onDragOver={e => { e.preventDefault(); setDragging(true) }}
onDragLeave={() => setDragging(false)}
onDrop={onDrop}
disabled={reading}
aria-busy={reading}
className={`flex flex-col items-center justify-center gap-2 px-4 py-10 rounded-xl border border-dashed transition-colors ${
dragging ? 'border-accent bg-surface-hover' : 'border-edge hover:bg-surface-hover'
}`}
)}
footer={(
<DialogFooter>
<FooterSpacer />
<DialogButton onClick={onClose}>{t('common.cancel')}</DialogButton>
<DialogButton
variant="primary"
onClick={() => void submit()}
disabled={!file || busy || nothingToImport || (intoExisting ? listId == null : !name.trim())}
icon={busy ? <Loader2 size={14} className="animate-spin" /> : undefined}
>
{reading ? <Loader2 size={22} className="text-content-faint animate-spin" /> : <Upload size={22} className="text-content-faint" />}
<span className="text-[13px] font-medium text-content">
{reading ? t('collections.file.reading') : t('collections.file.choose')}
</span>
<span className="text-[11.5px] text-content-faint">{COLLECTION_FILE_EXTENSION} · {COLLECTION_GPX_EXTENSION}</span>
</button>
) : (
<>
<div className="flex items-center gap-3 px-3 py-2.5 rounded-xl border border-edge bg-surface-card">
<span className="w-9 h-9 min-w-[36px] rounded-lg flex items-center justify-center shrink-0 text-white" style={{ background: file.color || '#6366f1' }}>
{leftovers ? <Route size={15} /> : <FileJson size={15} />}
{intoExisting ? t('collections.file.confirmInto') : t('collections.file.confirm')}
</DialogButton>
</DialogFooter>
)}
>
<input
ref={inputRef}
type="file"
accept=".json,application/json,.gpx,application/gpx+xml"
className="hidden"
onChange={e => { void take(e.target.files?.[0]); e.target.value = '' }}
/>
{!file ? (
<button
type="button"
onClick={() => inputRef.current?.click()}
onDragOver={e => { e.preventDefault(); setDragging(true) }}
onDragLeave={() => setDragging(false)}
onDrop={onDrop}
disabled={reading}
aria-busy={reading}
className={`flex min-h-[132px] w-full flex-col items-center justify-center gap-1.5 rounded-[14px] border-2 border-dashed p-4 transition-colors ${
dragging ? 'border-accent bg-surface-tertiary' : 'border-edge bg-surface-secondary hover:border-content-faint'
}`}
>
{reading
? <Loader2 size={20} className="animate-spin text-content-faint" />
: <Upload size={20} strokeWidth={1.8} className="text-content-faint" />}
<span className="font-semibold text-content" style={fs(13, 'body')}>
{reading ? t('collections.file.reading') : t('collections.file.choose')}
</span>
<span className="flex items-center gap-1.5 text-content-faint" style={fs(11.5)}><span>{COLLECTION_FILE_EXTENSION}</span><span>{COLLECTION_GPX_EXTENSION}</span></span>
</button>
) : (
<>
{/* What the file holds, read before anything is imported. */}
<div className="flex flex-col gap-2.5">
<div className="flex items-center gap-3 rounded-[14px] border border-edge-faint bg-surface-secondary p-2.5">
<span className="grid h-9 w-9 flex-none place-items-center rounded-[10px]" style={swatch(file.color)}>
{leftovers ? <Route size={16} /> : <FileJson size={16} />}
</span>
<span className="flex-1 min-w-0">
<span className="block text-[13px] font-semibold text-content truncate">{file.name}</span>
<span className="flex items-center gap-3 text-[11.5px] text-content-faint">
<span className="min-w-0 flex-1">
<span className="block truncate font-semibold text-content" style={fs(13, 'body')}>{file.name}</span>
<span className="flex items-center gap-3 text-content-faint" style={fs(11.5)}>
<span className="inline-flex items-center gap-1"><MapPin size={11} />{t('collections.placeCount', { count: file.places.length })}</span>
{file.labels && file.labels.length > 0 && (
<span className="inline-flex items-center gap-1"><Tag size={11} />{t('collections.file.labelCount', { count: file.labels.length })}</span>
)}
</span>
</span>
<button type="button" onClick={() => inputRef.current?.click()} className="text-[12px] font-medium text-accent shrink-0 hover:underline">
<button
type="button"
onClick={() => inputRef.current?.click()}
className="flex-none rounded-[8px] bg-surface-card px-2.5 py-1 font-semibold text-content shadow-sm ring-1 ring-edge-faint hover:bg-surface-secondary"
style={fs(12, 'body')}
>
{t('collections.file.change')}
</button>
</div>
{file.description && (
<p className="text-[12px] text-content-muted whitespace-pre-wrap">{file.description}</p>
<p className="m-0 whitespace-pre-wrap text-content-muted" style={fs(12, 'body')}>{file.description}</p>
)}
{leftovers && <GpxNotes leftovers={leftovers} placeCount={file.places.length} t={t} />}
</div>
{canChoose && (
<div className="grid grid-cols-2 gap-2">
<TargetCard
active={target === 'new'}
icon={Plus}
title={t('collections.file.targetNew')}
hint={t('collections.file.targetNewHint')}
onClick={() => setTarget('new')}
/>
<TargetCard
active={intoExisting}
icon={FolderInput}
title={t('collections.file.targetExisting')}
hint={t('collections.file.targetExistingHint')}
onClick={() => setTarget('existing')}
/>
</div>
)}
{canChoose && (
<div className="grid grid-cols-2 gap-2">
<TargetCard
active={target === 'new'}
icon={Plus}
title={t('collections.file.targetNew')}
hint={t('collections.file.targetNewHint')}
onClick={() => setTarget('new')}
/>
<TargetCard
active={intoExisting}
icon={FolderInput}
title={t('collections.file.targetExisting')}
hint={t('collections.file.targetExistingHint')}
onClick={() => setTarget('existing')}
/>
</div>
)}
{intoExisting ? (
<>
<ListChoice lists={targets} selectedId={listId} onSelect={setListId} t={t} />
<p className="text-[11.5px] text-content-faint">{t('collections.file.intoHint')}</p>
</>
) : (
<>
<label className="flex flex-col gap-1.5">
<span className="text-[12px] font-medium text-content-muted">{t('collections.listName')}</span>
<input
value={name}
onChange={e => setName(e.target.value)}
maxLength={120}
className="w-full px-3 py-2 rounded-lg border border-edge bg-surface-input text-content text-[13px] outline-none focus:border-accent"
/>
</label>
{intoExisting ? (
<div className="flex flex-col gap-2">
<ListChoice lists={targets} selectedId={listId} onSelect={setListId} t={t} />
<p className={HINT} style={fs(11.5)}>{t('collections.file.intoHint')}</p>
</div>
) : (
<EditorField
label={t('collections.listName')}
htmlFor={nameId}
// Ratings and members are a TREK file's business; a GPX never had any.
hint={leftovers ? undefined : t('collections.file.hint')}
>
<input
id={nameId}
value={name}
onChange={e => setName(e.target.value)}
maxLength={120}
className={INPUT}
/>
</EditorField>
)}
</>
)}
{!leftovers && <p className="text-[11.5px] text-content-faint">{t('collections.file.hint')}</p>}
</>
)}
</>
)}
{errorText && (
<p className="flex items-start gap-2 text-[12px] text-danger">
<AlertCircle size={13} className="shrink-0 mt-0.5" />
<span>{errorText}</span>
</p>
)}
</div>
</Modal>
{errorText && (
<div role="alert" className="flex items-start gap-2 rounded-[12px] bg-danger-soft px-3 py-2 text-danger" style={fs(12, 'body')}>
<AlertCircle size={13} className="mt-0.5 flex-none" />
<span>{errorText}</span>
</div>
)}
</DialogShell>
)
}
@@ -1,7 +1,7 @@
// FE-COMP-COLIMPORT-001 to FE-COMP-COLIMPORT-007
import React from 'react';
import { describe, it, expect, beforeEach, vi } from 'vitest';
import { render, screen, waitFor, within } from '../../../tests/helpers/render';
import { render, screen, fireEvent, waitFor, within } from '../../../tests/helpers/render';
import userEvent from '@testing-library/user-event';
import { http, HttpResponse } from 'msw';
import { server } from '../../../tests/helpers/msw/server';
@@ -65,11 +65,12 @@ describe('ImportFromTripModal', () => {
it('FE-COMP-COLIMPORT-001: lists the trips with their place count and a localized date range', async () => {
render(<Harness />);
await waitFor(() => expect(screen.getByText('Rome 2026')).toBeInTheDocument());
// The count is a compact badge; the full wording stays as its title.
expect(screen.getByTitle('3 places')).toHaveTextContent('3');
// The count is a compact badge; the full wording is in its tooltip.
fireEvent.mouseEnter(screen.getByText('3'));
expect(await screen.findByRole('tooltip')).toHaveTextContent('3 places');
// Formatted through the shared formatter, never the raw ISO string.
const dateBadge = screen.getByTitle(/May/);
expect(dateBadge.textContent).toMatch(/May 1.*–.*May 8/);
const dateBadge = screen.getByText(/May/);
expect(dateBadge.textContent).toMatch(/May 1.*→.*May 8/);
expect(dateBadge.textContent).not.toMatch(/2026-05-01/);
expect(screen.getByText('Lisbon')).toBeInTheDocument();
});
@@ -1,6 +1,8 @@
import React, { useEffect, useMemo, useState } from 'react'
import { ArrowLeft, Calendar, Check, ChevronRight, Loader2, MapPin, Map as MapIcon, Search, Sparkles } from 'lucide-react'
import Modal from '../shared/Modal'
import React, { useEffect, useId, useMemo, useState } from 'react'
import { ArrowLeft, Calendar, Check, ChevronRight, ListPlus, Loader2, MapPin, Map as MapIcon, Search, Sparkles } from 'lucide-react'
import { DialogButton, DialogFooter, DialogHeader, DialogShell, DialogTile, FooterSpacer, NEUTRAL_TINT, fs } from '../shared/DialogShell'
import { INPUT } from '../shared/dialogParts'
import { Tooltip } from '../shared/Tooltip'
import { tripsApi } from '../../api/client'
import { collectionsApi } from '../../api/collections'
import { getCategoryIcon } from '../shared/categoryIcons'
@@ -36,10 +38,37 @@ function importOrder(p: CollectionImportablePlace): number {
function tripRange(trip: Trip, locale: string): string | null {
const from = formatDate(trip.start_date, locale)
const to = formatDate(trip.end_date, locale)
if (from && to && to !== from) return `${from} – ${to}`
if (from && to && to !== from) return `${from} → ${to}`
return from || to || null
}
/**
* The toolbar of the places step, pinned to the top of the scrolling body so the
* search and the filters stay in reach down a long trip. The negative margins
* let its background cover the body's padding while it is stuck.
*/
const STICKY_BAR = 'sticky top-0 z-10 -mx-6 -mb-3 -mt-5 flex flex-wrap items-center gap-2 bg-surface-card px-6 pb-3 pt-5'
const ROWS = 'flex flex-col gap-0.5 rounded-[14px] border border-edge-faint bg-surface-secondary p-1.5'
/** A small fact on a trip tile; each is its own pill, so a narrow tile wraps between them instead of clipping a word. */
const META_PILL = 'inline-flex min-w-0 max-w-full items-center gap-1 truncate rounded-full bg-surface-tertiary px-1.5 py-px font-semibold tabular-nums text-content-muted'
const CHIP = 'inline-flex flex-none items-center gap-1 rounded-full px-2.5 py-1 font-semibold disabled:cursor-default disabled:opacity-50'
const CHIP_OFF = 'bg-surface-card text-content-muted ring-1 ring-edge-faint hover:text-content'
const CHIP_ON = 'bg-accent text-accent-text'
const TAG = 'flex-none whitespace-nowrap rounded-full px-2 py-[2px] font-semibold tabular-nums'
/** The dashed box a step shows when there is nothing to pick. */
function EmptyState({ icon, good = false, children }: { icon: React.ReactNode; good?: boolean; children: React.ReactNode }) {
return (
<div
className={`flex flex-col items-center justify-center gap-2 rounded-[14px] border border-dashed px-4 py-8 text-center ${good ? 'border-success bg-success-soft text-success' : 'border-edge text-content-faint'}`}
style={fs(12.5, 'body')}
>
{icon}
<span>{children}</span>
</div>
)
}
/**
* Bulk import of a trip's places into the current list.
*
@@ -51,6 +80,7 @@ function tripRange(trip: Trip, locale: string): string | null {
export default function ImportFromTripModal({ isOpen, collectionId, collectionName, categories, onClose, onImported, t }: ImportFromTripModalProps): React.ReactElement {
const toast = useToast()
const { language } = useTranslation()
const labelId = useId()
const [step, setStep] = useState<Step>('trip')
const [trips, setTrips] = useState<Trip[]>([])
const [tripsLoading, setTripsLoading] = useState(false)
@@ -142,199 +172,218 @@ export default function ImportFromTripModal({ isOpen, collectionId, collectionNa
const categoryById = useMemo(() => new Map(categories.map(c => [c.id, c])), [categories])
const title = step === 'places' && trip
? trip.title
const tripShown = step === 'places' ? trip : null
const title = tripShown
? tripShown.title
: step === 'done'
? t('collections.importDoneTitle')
: t('collections.importTitle')
const footer = step === 'done'
? (
<div className="flex justify-end">
<button type="button" onClick={onClose} className="px-4 py-1.5 rounded-lg bg-accent text-accent-text text-[13px] font-semibold">{t('common.close')}</button>
</div>
// The first step says what it is for under the title; the second names the
// trip, and the dialog's own title moves up to the eyebrow.
let sub: React.ReactNode
if (step === 'trip') sub = t('collections.importPickTripHint', { name: collectionName })
else if (tripShown) sub = tripRange(tripShown, language) ?? undefined
const header = (
<DialogHeader
tile={<DialogTile><ListPlus size={20} strokeWidth={1.9} className="text-content-muted" /></DialogTile>}
tint={NEUTRAL_TINT}
labelId={labelId}
onClose={onClose}
eyebrow={tripShown ? t('collections.importTitle') : undefined}
title={title}
sub={sub}
subWraps={step === 'trip'}
/>
)
let footer: React.ReactNode
if (step === 'done') {
footer = (
<DialogFooter>
<FooterSpacer />
<DialogButton variant="primary" onClick={onClose}>{t('common.close')}</DialogButton>
</DialogFooter>
)
: step === 'places'
? (
<div className="flex items-center justify-between gap-3">
<span className="text-[12.5px] text-content-faint">
{t('collections.importSelectedCount', { count: selected.size })}
</span>
<div className="flex 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={runImport}
disabled={importing || selected.size === 0}
className="px-4 py-1.5 rounded-lg bg-accent text-accent-text text-[13px] font-semibold disabled:opacity-50 inline-flex items-center gap-1.5"
>
{importing ? <Loader2 size={14} className="animate-spin" /> : <Check size={14} />}
{t('collections.importAction', { count: selected.size })}
</button>
</div>
</div>
)
: (
<div className="flex justify-end">
<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>
</div>
)
} else if (step === 'places') {
footer = (
<DialogFooter>
<DialogButton onClick={() => setStep('trip')} icon={<ArrowLeft size={14} strokeWidth={2.2} />}>{t('common.back')}</DialogButton>
<span className="ml-1 text-content-faint" style={fs(12.5, 'body')}>
{t('collections.importSelectedCount', { count: selected.size })}
</span>
<FooterSpacer />
<DialogButton onClick={onClose}>{t('common.cancel')}</DialogButton>
<DialogButton
variant="primary"
onClick={() => void runImport()}
disabled={importing || selected.size === 0}
icon={importing ? <Loader2 size={14} className="animate-spin" /> : <Check size={14} strokeWidth={2.2} />}
>
{t('collections.importAction', { count: selected.size })}
</DialogButton>
</DialogFooter>
)
} else {
footer = (
<DialogFooter>
<FooterSpacer />
<DialogButton onClick={onClose}>{t('common.cancel')}</DialogButton>
</DialogFooter>
)
}
return (
<Modal isOpen={isOpen} onClose={onClose} title={title} size="xl" footer={footer}>
<div className="col-imp">
{/* ── Step 1: which trip ─────────────────────────────────────────── */}
{step === 'trip' && (
<>
<p className="col-imp-lead">{t('collections.importPickTripHint', { name: collectionName })}</p>
{tripsLoading ? (
<div className="col-imp-grid">
{[0, 1, 2, 3].map(i => <div key={i} className="col-imp-trip trek-skeleton" style={{ height: 68 }} />)}
</div>
) : trips.length === 0 ? (
<div className="col-imp-empty">
<MapIcon size={22} />
<span>{t('collections.importNoTrips')}</span>
</div>
) : (
<div className="col-imp-grid trek-stagger">
{trips.map(tr => {
const range = tripRange(tr, language)
const places = tr.place_count ?? 0
return (
<button key={tr.id} type="button" className="col-imp-trip" onClick={() => pickTrip(tr)}>
<span className="col-imp-trip-cover">
{tr.cover_image
? <img src={tr.cover_image} alt="" loading="lazy" />
: <MapIcon size={16} />}
</span>
<span className="col-imp-trip-body">
<span className="col-imp-trip-name">{tr.title}</span>
{/* Badges rather than one run-on line: the tile is half the dialog
wide, and a date range plus a place count ran out of room and
got clipped mid-word. Each pill can now wrap as a unit. */}
<span className="col-imp-trip-meta">
{range && (
<span className="col-imp-pill" title={range}>
<Calendar size={10} />{range}
</span>
)}
<span className="col-imp-pill num" title={t('collections.importPlacesCount', { count: places })}>
<MapPin size={10} />{places}
</span>
</span>
</span>
<ChevronRight size={16} className="col-imp-trip-go" />
</button>
)
})}
</div>
)}
</>
)}
{/* ── Step 2: which places ───────────────────────────────────────── */}
{step === 'places' && (
<>
<div className="col-imp-bar">
<button type="button" className="col-imp-back" onClick={() => setStep('trip')} aria-label={t('common.back')}>
<ArrowLeft size={15} />
</button>
<div className="col-imp-search">
<Search size={14} />
<input
value={query}
onChange={e => setQuery(e.target.value)}
placeholder={t('collections.importSearchPlaces')}
aria-label={t('collections.importSearchPlaces')}
/>
</div>
{savedCount > 0 && (
// Pinned at the top: the three steps are of very different heights.
<DialogShell open={!!isOpen} onClose={onClose} labelledBy={labelId} width="editor" align="top" header={header} footer={footer}>
{/* Step 1: which trip */}
{step === 'trip' && (
tripsLoading ? (
<div className="grid grid-cols-2 gap-2 max-sm:grid-cols-1">
{[0, 1, 2, 3].map(i => <div key={i} className="trek-skeleton h-[64px] rounded-[14px]" />)}
</div>
) : trips.length === 0 ? (
<EmptyState icon={<MapIcon size={22} />}>{t('collections.importNoTrips')}</EmptyState>
) : (
<div className="trek-stagger grid grid-cols-2 gap-2 max-sm:grid-cols-1">
{trips.map(tr => {
const range = tripRange(tr, language)
const places = tr.place_count ?? 0
return (
<button
key={tr.id}
type="button"
className={`col-imp-chip${onlyNew ? ' on' : ''}`}
aria-pressed={onlyNew}
onClick={() => setOnlyNew(v => !v)}
onClick={() => pickTrip(tr)}
className="group flex w-full items-center gap-3 rounded-[14px] border border-edge-faint bg-surface-secondary p-2.5 text-left transition-colors hover:bg-surface-card hover:shadow-sm"
>
<Sparkles size={12} />{t('collections.importOnlyNew')}
<span className="grid h-[42px] w-[42px] flex-none place-items-center overflow-hidden rounded-[11px] bg-surface-tertiary text-content-faint">
{tr.cover_image
? <img src={tr.cover_image} alt="" loading="lazy" className="h-full w-full object-cover" />
: <MapIcon size={16} />}
</span>
<span className="flex min-w-0 flex-1 flex-col gap-1">
<span className="truncate font-semibold text-content" style={fs(13.5, 'body')}>{tr.title}</span>
{/* Badges rather than one run-on line: a date range plus a place
count ran out of room on a half-width tile and got clipped
mid-word. Each pill can now wrap as a unit. */}
<span className="flex min-w-0 flex-wrap items-center gap-1" style={fs(10.5)}>
{range && (
<Tooltip label={range}>
<span className={META_PILL}><Calendar size={10} className="flex-none" />{range}</span>
</Tooltip>
)}
<Tooltip label={t('collections.importPlacesCount', { count: places })}>
<span className={`${META_PILL} flex-none`}><MapPin size={10} className="flex-none" />{places}</span>
</Tooltip>
</span>
</span>
<ChevronRight size={16} className="flex-none text-content-faint transition-transform group-hover:translate-x-0.5 group-hover:text-content-muted" />
</button>
)}
)
})}
</div>
)
)}
{/* Step 2: which places */}
{step === 'places' && (
<>
<div className={STICKY_BAR}>
<div className="relative min-w-[150px] flex-1">
<Search size={14} className="pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-content-faint" aria-hidden="true" />
<input
type="text"
value={query}
onChange={e => setQuery(e.target.value)}
placeholder={t('collections.importSearchPlaces')}
aria-label={t('collections.importSearchPlaces')}
className={`${INPUT} pl-8`}
/>
</div>
{savedCount > 0 && (
<button
type="button"
className="col-imp-chip"
onClick={toggleAllVisible}
disabled={selectableVisible.length === 0}
className={`${CHIP} ${onlyNew ? CHIP_ON : CHIP_OFF}`}
style={fs(11.5, 'body')}
aria-pressed={onlyNew}
onClick={() => setOnlyNew(v => !v)}
>
{allVisibleSelected ? t('collections.importClearSelection') : t('collections.importSelectAll')}
<Sparkles size={12} />{t('collections.importOnlyNew')}
</button>
</div>
{itemsLoading ? (
<div className="col-imp-list">
{[0, 1, 2, 3, 4].map(i => <div key={i} className="col-imp-row trek-skeleton" style={{ height: 56 }} />)}
</div>
) : items.length === 0 ? (
<div className="col-imp-empty">
<MapPin size={22} />
<span>{t('collections.importEmptyTrip')}</span>
</div>
) : newCount === 0 ? (
<div className="col-imp-empty col-imp-empty-good">
<Check size={22} />
<span>{t('collections.importNothingNew')}</span>
</div>
) : (
<div className="col-imp-list trek-stagger">
{visible.map(p => {
const dup = p.already_in_list
const on = selected.has(p.place_id)
const cat = p.category_id != null ? categoryById.get(p.category_id) : undefined
const Icon = getCategoryIcon(cat?.icon ?? undefined)
return (
<button
key={p.place_id}
type="button"
className={`col-imp-row${on ? ' on' : ''}${dup ? ' dup' : ''}`}
onClick={() => !dup && toggle(p.place_id)}
disabled={dup}
aria-pressed={dup ? undefined : on}
>
<span className="col-imp-box">{on && <Check size={12} strokeWidth={3} />}</span>
<span className="col-imp-ico" style={cat?.color ? { color: cat.color } : undefined}>
<Icon size={15} />
</span>
<span className="col-imp-txt">
<span className="nm">{p.name}</span>
{p.address && <span className="ad">{p.address}</span>}
</span>
<span className={`col-imp-tag${dup ? ' saved' : p.scheduled ? '' : ' fresh'}`}>
{dup
? t('collections.importAlreadySaved')
: p.scheduled
? t('collections.importOnDay', { count: p.day_number ?? 0 })
: t('collections.importUnscheduled')}
</span>
</button>
)
})}
</div>
)}
</>
)}
{/* ── Step 3: what happened ──────────────────────────────────────── */}
{step === 'done' && result && (
<div className="col-imp-done">
<span className="col-imp-done-ring"><Check size={26} strokeWidth={2.5} /></span>
<span className="col-imp-done-t">{t('collections.importDone', { count: result.copied })}</span>
<span className="col-imp-done-s">
{result.skipped > 0
? t('collections.importDoneSkipped', { count: result.skipped })
: t('collections.importDoneClean', { name: collectionName })}
</span>
<button
type="button"
className={`${CHIP} ${CHIP_OFF}`}
style={fs(11.5, 'body')}
onClick={toggleAllVisible}
disabled={selectableVisible.length === 0}
>
{allVisibleSelected ? t('collections.importClearSelection') : t('collections.importSelectAll')}
</button>
</div>
)}
</div>
</Modal>
{itemsLoading ? (
<div className={ROWS}>
{[0, 1, 2, 3, 4].map(i => <div key={i} className="trek-skeleton h-12 rounded-[10px]" />)}
</div>
) : items.length === 0 ? (
<EmptyState icon={<MapPin size={22} />}>{t('collections.importEmptyTrip')}</EmptyState>
) : newCount === 0 ? (
<EmptyState icon={<Check size={22} />} good>{t('collections.importNothingNew')}</EmptyState>
) : (
<div className={`${ROWS} trek-stagger`}>
{visible.map(p => {
const dup = p.already_in_list
const on = selected.has(p.place_id)
const cat = p.category_id != null ? categoryById.get(p.category_id) : undefined
const Icon = getCategoryIcon(cat?.icon ?? undefined)
let tag: React.ReactNode
if (dup) tag = <span className={`${TAG} text-content-faint`} style={fs(10.5)}>{t('collections.importAlreadySaved')}</span>
else if (p.scheduled) tag = <span className={`${TAG} bg-surface-tertiary text-content-muted`} style={fs(10.5)}>{t('collections.importOnDay', { count: p.day_number ?? 0 })}</span>
else tag = <span className={`${TAG} bg-accent-subtle text-accent-on`} style={fs(10.5)}>{t('collections.importUnscheduled')}</span>
return (
<button
key={p.place_id}
type="button"
onClick={() => !dup && toggle(p.place_id)}
disabled={dup}
aria-pressed={dup ? undefined : on}
className={`flex min-h-[48px] w-full items-center gap-3 rounded-[10px] px-2.5 py-1.5 text-left disabled:cursor-default disabled:opacity-50 ${on ? 'bg-surface-card shadow-sm' : 'enabled:hover:bg-surface-card'}`}
>
<span className={`grid h-4 w-4 flex-none place-items-center rounded-[5px] ${dup ? 'invisible' : on ? 'bg-accent text-accent-text' : 'border-[1.5px] border-edge'}`}>
{on && <Check size={11} strokeWidth={3} />}
</span>
<span className="grid h-7 w-7 flex-none place-items-center rounded-[9px] bg-surface-tertiary text-content-muted" style={cat?.color ? { color: cat.color } : undefined}>
<Icon size={15} />
</span>
<span className="flex min-w-0 flex-1 flex-col">
<span className="truncate font-semibold text-content" style={fs(13, 'body')}>{p.name}</span>
{p.address && <span className="truncate text-content-faint" style={fs(11)}>{p.address}</span>}
</span>
{tag}
</button>
)
})}
</div>
)}
</>
)}
{/* Step 3: what happened */}
{step === 'done' && result && (
<div className="flex flex-col items-center gap-2.5 px-4 pb-4 pt-6 text-center">
<span className="trek-popover-enter grid h-[60px] w-[60px] place-items-center rounded-full bg-success-soft text-success">
<Check size={26} strokeWidth={2.5} />
</span>
<span className="font-bold text-content" style={fs(15, 'subtitle')}>{t('collections.importDone', { count: result.copied })}</span>
<span className="max-w-[320px] leading-normal text-content-faint" style={fs(12.5, 'body')}>
{result.skipped > 0
? t('collections.importDoneSkipped', { count: result.skipped })
: t('collections.importDoneClean', { name: collectionName })}
</span>
</div>
)}
</DialogShell>
)
}
@@ -1,6 +1,8 @@
import React, { useState } from 'react'
import { Plus, Trash2, Loader2 } from 'lucide-react'
import Modal from '../shared/Modal'
import React, { useId, useState } from 'react'
import { Plus, Settings2, Trash2, Loader2 } from 'lucide-react'
import { DialogButton, DialogHeader, DialogSection, DialogShell, DialogTile, NEUTRAL_TINT, fs } from '../shared/DialogShell'
import { INPUT, PANEL } from '../shared/dialogParts'
import { Tooltip } from '../shared/Tooltip'
import type { CollectionLabel, CollectionLabelUpdateRequest } from '@trek/shared'
import type { TranslationFn } from '../../types'
@@ -19,17 +21,26 @@ interface LabelManagerProps {
/** Swatch row shared by the create form and each row's recolor control. */
function Swatches({ value, onPick }: { value: string; onPick: (c: string) => void }): React.ReactElement {
return (
<div className="flex items-center gap-1.5 flex-wrap">
{SWATCHES.map(c => (
<button
key={c}
type="button"
onClick={() => onPick(c)}
className={`w-5 h-5 rounded-full border transition-transform ${value.toLowerCase() === c ? 'border-content scale-110' : 'border-transparent'}`}
style={{ background: c }}
aria-label={c}
/>
))}
<div className="flex flex-none flex-wrap items-center gap-1.5">
{SWATCHES.map(c => {
const on = value.toLowerCase() === c
return (
<button
key={c}
type="button"
onClick={() => onPick(c)}
aria-label={c}
aria-pressed={on}
className="h-5 w-5 rounded-full p-0 transition-transform"
style={{
background: c,
outline: on ? '2px solid var(--text-primary)' : '2px solid transparent',
outlineOffset: 1.5,
transform: on ? 'scale(1.08)' : 'scale(1)',
}}
/>
)
})}
</div>
)
}
@@ -58,22 +69,28 @@ function LabelRow({ label, onUpdate, onDelete, t }: {
}
return (
<div className="flex items-center gap-2 px-2.5 py-2 rounded-xl border border-edge bg-surface-card">
<span className="w-3.5 h-3.5 rounded-full shrink-0" style={{ background: color }} />
<div className="flex items-center gap-2.5 rounded-[12px] bg-surface-secondary py-1.5 pl-3 pr-1.5">
<span className="h-2.5 w-2.5 flex-none rounded-full" style={{ background: color }} />
{/* Transparent on the row until pointed at or typed in; the dark: variants
outrank the global dark rule that paints every input. */}
<input
value={name}
onChange={e => setName(e.target.value)}
onBlur={commitName}
onKeyDown={e => { if (e.key === 'Enter') (e.target as HTMLInputElement).blur() }}
maxLength={60}
className="flex-1 min-w-0 bg-transparent text-[13px] text-content outline-none"
className="-ml-1.5 min-w-0 flex-1 rounded-[8px] border-0 bg-transparent px-1.5 py-1 font-semibold text-content outline-none hover:bg-surface-card focus:bg-surface-card focus:shadow-sm dark:bg-transparent dark:hover:bg-surface-card dark:focus:bg-surface-card"
style={fs(13, 'body')}
aria-label={t('collections.labels.name')}
/>
<Swatches value={color} onPick={pickColor} />
{busy && <Loader2 size={14} className="animate-spin text-content-faint shrink-0" />}
<button type="button" onClick={() => onDelete(label.id)} className="p-1 text-content-faint hover:text-danger shrink-0" aria-label={t('common.delete')}>
<Trash2 size={14} />
</button>
{busy && <Loader2 size={14} className="flex-none animate-spin text-content-faint" />}
<Tooltip label={t('common.delete')}>
<button type="button" onClick={() => onDelete(label.id)} aria-label={t('common.delete')}
className="grid h-7 w-7 flex-none place-items-center rounded-full text-content-faint hover:bg-surface-card hover:text-danger">
<Trash2 size={13} />
</button>
</Tooltip>
</div>
)
}
@@ -86,6 +103,7 @@ export default function LabelManager({ isOpen, labels, onCreate, onUpdate, onDel
const [newName, setNewName] = useState('')
const [newColor, setNewColor] = useState(SWATCHES[0])
const [adding, setAdding] = useState(false)
const labelId = useId()
const add = async () => {
const trimmed = newName.trim()
@@ -100,40 +118,55 @@ export default function LabelManager({ isOpen, labels, onCreate, onUpdate, onDel
}
}
// Every change is saved as it is made, so there is nothing to confirm in a footer.
return (
<Modal isOpen={isOpen} onClose={onClose} title={t('collections.labels.manage')} size="sm">
<div className="flex flex-col gap-3">
<DialogShell
open={isOpen}
onClose={onClose}
labelledBy={labelId}
width="narrow"
header={(
<DialogHeader
tile={<DialogTile><Settings2 size={20} strokeWidth={1.9} className="text-content-muted" /></DialogTile>}
tint={NEUTRAL_TINT}
labelId={labelId}
onClose={onClose}
title={t('collections.labels.manage')}
/>
)}
>
<DialogSection label={t('collections.labels.title')}>
{labels.length === 0 ? (
<p className="text-center text-[13px] text-content-faint py-4">{t('collections.labels.empty')}</p>
<p className="m-0 rounded-[12px] bg-surface-secondary px-4 py-5 text-center text-content-faint" style={fs(12.5, 'body')}>{t('collections.labels.empty')}</p>
) : (
<div className="flex flex-col gap-1.5 max-h-[46vh] overflow-y-auto -mx-1 px-1">
<div className="flex flex-col gap-1.5">
{labels.map(l => <LabelRow key={l.id} label={l} onUpdate={onUpdate} onDelete={onDelete} t={t} />)}
</div>
)}
<div className="flex flex-col gap-2 pt-3 border-t border-edge">
<div className={`${PANEL} mt-3`}>
<div className="flex items-center gap-2">
<span className="w-3.5 h-3.5 rounded-full shrink-0" style={{ background: newColor }} />
<span className="h-2.5 w-2.5 flex-none rounded-full" style={{ background: newColor }} />
<input
value={newName}
onChange={e => setNewName(e.target.value)}
onKeyDown={e => { if (e.key === 'Enter') add() }}
maxLength={60}
placeholder={t('collections.labels.namePlaceholder')}
className="flex-1 min-w-0 px-3 py-2 rounded-lg border border-edge bg-surface-input text-content text-[13px] outline-none focus:border-accent"
className={`${INPUT} flex-1`}
/>
<button
type="button"
<DialogButton
variant="primary"
onClick={add}
disabled={!newName.trim() || adding}
className="flex items-center gap-1.5 px-3 py-2 rounded-lg bg-accent text-white text-[13px] font-semibold hover:opacity-90 disabled:opacity-50 shrink-0"
icon={adding ? <Loader2 size={14} className="animate-spin" /> : <Plus size={14} strokeWidth={2.2} />}
>
{adding ? <Loader2 size={14} className="animate-spin" /> : <Plus size={14} />} {t('collections.labels.add')}
</button>
{t('collections.labels.add')}
</DialogButton>
</div>
<Swatches value={newColor} onPick={setNewColor} />
</div>
</div>
</Modal>
</DialogSection>
</DialogShell>
)
}
@@ -1,6 +1,8 @@
import React, { useEffect, useRef, useState } from 'react'
import { ImagePlus, Link2, Plus, Trash2, Search, Loader2 } from 'lucide-react'
import Modal from '../shared/Modal'
import React, { useEffect, useId, useRef, useState } from 'react'
import { Bookmark, ImagePlus, Trash2, Search, Loader2 } from 'lucide-react'
import { DeleteButton, DialogButton, DialogFooter, DialogHeader, DialogSection, DialogShell, DialogTile, FooterSpacer, fs } from '../shared/DialogShell'
import { AddRowButton, EditorField, INPUT, TEXTAREA } from '../shared/dialogParts'
import { Tooltip } from '../shared/Tooltip'
import { useCollectionStore } from '../../store/collectionStore'
import { useToast } from '../shared/Toast'
import { tripsApi } from '../../api/client'
@@ -19,6 +21,10 @@ interface CoverSearchPhoto {
const SWATCHES = ['#6366f1', '#ec4899', '#14b8a6', '#f97316', '#8b5cf6', '#ef4444', '#3b82f6', '#22c55e']
/** A photographer's name laid over the bottom of a result, on a wash of the card colour. */
const PHOTO_CREDIT = 'absolute inset-x-0 bottom-0 truncate bg-[color:color-mix(in_srgb,var(--bg-card)_85%,transparent)] px-1.5 py-1 text-content-muted'
const ROW_ACTION = 'grid h-8 w-8 flex-none place-items-center rounded-[9px] text-content-faint hover:bg-surface-secondary hover:text-danger'
interface ListEditorModalProps {
/** null = closed, 'new' = create, a Collection = edit that list. */
target: Collection | 'new' | null
@@ -40,6 +46,7 @@ export default function ListEditorModal({ target, onClose, onCreated, onRequestD
const uploadCover = useCollectionStore(s => s.uploadCover)
const toast = useToast()
const fileRef = useRef<HTMLInputElement>(null)
const labelId = useId()
const editing = target && target !== 'new' ? target : null
const [name, setName] = useState('')
@@ -152,161 +159,146 @@ export default function ListEditorModal({ target, onClose, onCreated, onRequestD
}
}
return (
<Modal
isOpen
// The list's own colour runs through the dialog: the head band, its tile and the cover.
const header = (
<DialogHeader
tile={<DialogTile><Bookmark size={20} strokeWidth={1.9} style={{ color }} /></DialogTile>}
tint={`color-mix(in srgb, ${color} 12%, transparent)`}
labelId={labelId}
onClose={onClose}
title={editing ? t('collections.editListTitle') : t('collections.newList')}
size="md"
footer={
<div className="flex items-center gap-2">
{editing && editing.is_owner !== false && (
<button
type="button"
onClick={() => { onClose(); onRequestDelete(editing.id) }}
className="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-danger text-[13px] font-medium hover:bg-danger-soft"
>
<Trash2 size={14} /> {t('collections.deleteList')}
</button>
)}
<div className="flex justify-end gap-2 ml-auto">
<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>
}
>
<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])} />
eyebrow={editing ? t('collections.editListTitle') : t('collections.newList')}
titleInput={{
value: name,
onChange: setName,
label: t('collections.listName'),
placeholder: t('collections.listNamePlaceholder'),
autoFocus: true,
onKeyDown: e => { if (e.key === 'Enter' && name.trim()) void save() },
}}
/>
)
{/* Unsplash cover search — same source as trip creation */}
<div className="mt-2 flex gap-2">
<input
value={coverQuery}
onChange={e => setCoverQuery(e.target.value)}
onKeyDown={e => { if (e.key === 'Enter') { e.preventDefault(); searchCover() } }}
placeholder={t('dashboard.unsplashSearchPlaceholder')}
className="flex-1 min-w-0 px-3 py-2 rounded-lg border border-edge bg-surface-input text-content text-[13px] outline-none focus:border-accent"
/>
<button
type="button"
onClick={searchCover}
disabled={searchingCover || (!coverQuery.trim() && !name.trim())}
className="px-3 py-2 rounded-lg border border-edge text-content-secondary text-[13px] hover:bg-surface-hover disabled:opacity-40 inline-flex items-center gap-1.5 whitespace-nowrap"
>
{searchingCover ? <Loader2 size={14} className="animate-spin" /> : <Search size={14} />}
{t('dashboard.searchUnsplash')}
</button>
</div>
{coverResults.length > 0 && (
<div className="grid grid-cols-3 gap-2 mt-2">
{coverResults.map(photo => (
const footer = (
<DialogFooter>
{editing && editing.is_owner !== false && (
<DeleteButton label={t('collections.deleteList')} onClick={() => { onClose(); onRequestDelete(editing.id) }} />
)}
<FooterSpacer />
<DialogButton onClick={onClose}>{t('common.cancel')}</DialogButton>
<DialogButton
variant="primary"
onClick={() => void save()}
disabled={!name.trim() || saving}
icon={saving ? <Loader2 size={14} className="animate-spin" /> : undefined}
>
{editing ? t('common.save') : t('collections.create')}
</DialogButton>
</DialogFooter>
)
return (
// Pinned at the top: the photo results grow the body under the search.
<DialogShell onClose={onClose} labelledBy={labelId} width="detail" align="top" header={header} footer={footer}>
<DialogSection label={t('collections.coverImage')}>
<button
type="button"
onClick={() => fileRef.current?.click()}
className="relative flex h-32 w-full items-center justify-center overflow-hidden rounded-[14px] border border-edge-faint bg-surface-secondary transition-colors hover:border-content-faint"
>
{coverPreview && <img src={coverPreview} alt="" className="absolute inset-0 h-full w-full object-cover" />}
<span className="absolute inset-0" style={{ background: `linear-gradient(135deg, color-mix(in srgb, ${color} 33%, transparent), transparent 70%)` }} />
{/* A chip rather than bare text, so it reads the same on any photo. */}
<span className="relative inline-flex items-center gap-1.5 rounded-full bg-surface-card px-3 py-1.5 font-semibold text-content shadow-sm" style={fs(12.5, 'body')}>
<ImagePlus size={15} /> {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])} />
{/* Unsplash cover search, the same source as trip creation */}
<div className="mt-2 flex gap-2">
<input
value={coverQuery}
onChange={e => setCoverQuery(e.target.value)}
onKeyDown={e => { if (e.key === 'Enter') { e.preventDefault(); searchCover() } }}
aria-label={t('dashboard.unsplashSearchPlaceholder')}
placeholder={t('dashboard.unsplashSearchPlaceholder')}
className={`${INPUT} flex-1`}
/>
<DialogButton
onClick={() => void searchCover()}
disabled={searchingCover || (!coverQuery.trim() && !name.trim())}
icon={searchingCover ? <Loader2 size={14} className="animate-spin" /> : <Search size={14} strokeWidth={2.2} />}
>
{t('dashboard.searchUnsplash')}
</DialogButton>
</div>
{coverResults.length > 0 && (
<div className="mt-2 grid grid-cols-3 gap-2">
{coverResults.map(photo => {
const on = coverPreview === photo.url
return (
<button
type="button"
key={photo.id}
onClick={() => pickUnsplash(photo)}
aria-label={photo.photographer || 'Unsplash'}
className={`relative h-20 overflow-hidden rounded-lg border transition-colors ${coverPreview === photo.url ? 'border-accent ring-2 ring-accent/25' : 'border-edge hover:border-accent'}`}
aria-pressed={on}
className={`relative h-20 overflow-hidden rounded-[10px] transition-shadow ${on ? 'ring-2 ring-accent' : 'ring-1 ring-edge-faint hover:ring-content-faint'}`}
>
<img src={photo.thumb} alt={photo.description || ''} loading="lazy" className="w-full h-full object-cover" />
{photo.photographer && (
<span className="absolute inset-x-0 bottom-0 truncate bg-black/55 px-1.5 py-1 text-[10px] text-white">{photo.photographer}</span>
)}
<img src={photo.thumb} alt={photo.description || ''} loading="lazy" className="h-full w-full object-cover" />
{photo.photographer && <span className={PHOTO_CREDIT} style={fs(10)}>{photo.photographer}</span>}
</button>
))}
</div>
)}
</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>
)}
</DialogSection>
{/* 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"
/>
<EditorField label={t('collections.listColor')}>
<div role="group" aria-label={t('collections.listColor')} className="flex flex-wrap gap-2">
{SWATCHES.map(col => (
<button
key={col}
type="button"
onClick={() => setColor(col)}
aria-label={col}
aria-pressed={color === col}
className={`h-7 w-7 rounded-full transition-transform hover:scale-110 ${color === col ? 'ring-2 ring-accent ring-offset-2 ring-offset-surface-card' : ''}`}
style={{ background: col }}
/>
))}
</div>
</EditorField>
{/* 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')}>
<EditorField label={t('collections.description')} htmlFor={`${labelId}-description`}>
<textarea
id={`${labelId}-description`}
value={description}
onChange={e => setDescription(e.target.value)}
rows={3}
placeholder={t('collections.descriptionPlaceholder')}
className={`${TEXTAREA} resize-y`}
/>
</EditorField>
<DialogSection label={t('collections.links')}>
<div className="flex flex-col gap-2">
{links.map((l, i) => (
<div key={i} className="flex items-center gap-2">
<div className="w-32 flex-none">
<input value={l.label ?? ''} onChange={e => setLink(i, { label: e.target.value })} placeholder={t('collections.linkLabel')} className={INPUT} />
</div>
<input value={l.url} onChange={e => setLink(i, { url: e.target.value })} placeholder="https://…" className={`${INPUT} flex-1`} />
<Tooltip label={t('common.delete')}>
<button type="button" onClick={() => setLinks(links.filter((_, idx) => idx !== i))} aria-label={t('common.delete')} className={ROW_ACTION}>
<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>
</Tooltip>
</div>
))}
<AddRowButton onClick={() => setLinks([...links, { url: '' }])}>{t('collections.addLink')}</AddRowButton>
</div>
</div>
</Modal>
</DialogSection>
</DialogShell>
)
}
@@ -1,6 +1,7 @@
import React, { useMemo, useState } from 'react'
import { Search, ArrowRight, Copy, Loader2, Bookmark } from 'lucide-react'
import Modal from '../shared/Modal'
import React, { useId, useMemo, useState } from 'react'
import { Search, ArrowRight, Copy, CopyPlus, FolderInput, Loader2 } from 'lucide-react'
import { DialogButton, DialogFooter, DialogHeader, DialogShell, DialogTile, FooterSpacer, NEUTRAL_TINT, fs } from '../shared/DialogShell'
import { INPUT } from '../shared/dialogParts'
import type { Collection } from '@trek/shared'
import type { TranslationFn } from '../../types'
@@ -17,12 +18,13 @@ interface MoveToListModalProps {
/**
* Target-list picker for moving or duplicating the selected places into another
* of the user's lists. `mode` only changes the wording + the trailing icon; the
* action itself is the parent's onPick.
* of the user's lists. `mode` only changes the wording + the icons; the action
* itself is the parent's onPick.
*/
export default function MoveToListModal({ mode, lists, count, onPick, onClose, t }: MoveToListModalProps): React.ReactElement {
const [search, setSearch] = useState('')
const [busy, setBusy] = useState<number | null>(null)
const labelId = useId()
const filtered = useMemo(() => {
const q = search.trim().toLowerCase()
@@ -35,56 +37,70 @@ export default function MoveToListModal({ mode, lists, count, onPick, onClose, t
try { await onPick(id) } finally { setBusy(null) }
}
// The head tile repeats the icon of the selection bar button that opened the dialog.
const Tile = mode === 'move' ? FolderInput : CopyPlus
const Trailing = mode === 'move' ? ArrowRight : Copy
return (
<Modal
isOpen
<DialogShell
onClose={onClose}
title={mode === 'move' ? t('collections.moveToListTitle', { count }) : t('collections.duplicateToListTitle', { count })}
size="sm"
labelledBy={labelId}
width="narrow"
align="top"
header={(
<DialogHeader
tile={<DialogTile><Tile size={20} strokeWidth={1.9} className="text-content-muted" /></DialogTile>}
tint={NEUTRAL_TINT}
labelId={labelId}
onClose={onClose}
title={mode === 'move' ? t('collections.moveToListTitle', { count }) : t('collections.duplicateToListTitle', { count })}
/>
)}
footer={(
<DialogFooter>
<FooterSpacer />
<DialogButton onClick={onClose}>{t('common.cancel')}</DialogButton>
</DialogFooter>
)}
>
<div className="flex flex-col gap-3">
{lists.length > 3 && (
<div className="relative">
<Search size={14} className="absolute left-2.5 top-1/2 -translate-y-1/2 text-content-faint" />
<input
autoFocus
value={search}
onChange={e => setSearch(e.target.value)}
placeholder={t('collections.copyToTripSearch')}
className="w-full pl-8 pr-3 py-2 rounded-lg border border-edge bg-surface-input text-content text-[13px] outline-none focus:border-accent"
/>
</div>
)}
{filtered.length === 0 ? (
<p className="text-center text-[13px] text-content-faint py-8">{t('collections.noOtherLists')}</p>
) : (
<div className="flex flex-col gap-1 max-h-[50vh] overflow-y-auto -mx-1 px-1">
{filtered.map(list => {
const isBusy = busy === list.id
return (
<button
key={list.id}
type="button"
onClick={() => pick(list.id)}
disabled={busy != null}
className="flex items-center gap-3 px-3 py-2.5 rounded-xl border border-edge bg-surface-card text-left hover:bg-surface-hover transition-colors disabled:opacity-60"
>
<span className="w-9 h-9 min-w-[36px] rounded-lg flex items-center justify-center shrink-0 text-white" style={{ background: list.color || '#6366f1' }}>
<Bookmark size={15} />
</span>
<span className="flex-1 min-w-0">
<span className="block text-[13px] font-semibold text-content truncate">{list.name}</span>
<span className="block text-[11.5px] text-content-faint">{t('collections.placeCount', { count: list.place_count ?? 0 })}</span>
</span>
{isBusy ? <Loader2 size={15} className="animate-spin text-content-faint shrink-0" /> : <Trailing size={15} className="text-content-faint shrink-0" />}
</button>
)
})}
</div>
)}
</div>
</Modal>
{lists.length > 3 && (
<div className="relative">
<Search size={14} className="pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-content-faint" aria-hidden="true" />
<input
autoFocus
value={search}
onChange={e => setSearch(e.target.value)}
placeholder={t('collections.copyToTripSearch')}
aria-label={t('collections.copyToTripSearch')}
className={`${INPUT} pl-8`}
/>
</div>
)}
{filtered.length === 0 ? (
<p className="m-0 rounded-[12px] bg-surface-secondary px-4 py-6 text-center text-content-faint" style={fs(12.5, 'body')}>{t('collections.noOtherLists')}</p>
) : (
<div className="flex flex-col gap-0.5 rounded-[14px] border border-edge-faint bg-surface-secondary p-1.5">
{filtered.map(list => {
const isBusy = busy === list.id
return (
<button
key={list.id}
type="button"
onClick={() => pick(list.id)}
disabled={busy != null}
className="flex min-h-[48px] items-center gap-3 rounded-[10px] px-3 py-2 text-left hover:bg-surface-card disabled:opacity-60"
>
<span className="h-2.5 w-2.5 flex-none rounded-full" style={{ background: list.color || '#6366f1' }} /* theme-lint-disable: the list's own colour, and the default a list without one is drawn in (ListsRail) */ />
<span className="min-w-0 flex-1">
<span className="block truncate font-semibold text-content" style={fs(13, 'body')}>{list.name}</span>
<span className="block text-content-faint" style={fs(11.5)}>{t('collections.placeCount', { count: list.place_count ?? 0 })}</span>
</span>
{isBusy ? <Loader2 size={15} className="flex-none animate-spin text-content-faint" /> : <Trailing size={15} className="flex-none text-content-faint" />}
</button>
)
})}
</div>
)}
</DialogShell>
)
}
@@ -1,6 +1,7 @@
import React, { useEffect, useMemo, useState } from 'react'
import { Search, Bookmark, ArrowRight, Loader2, Plus } from 'lucide-react'
import Modal from '../shared/Modal'
import React, { useEffect, useId, useMemo, useState } from 'react'
import { Search, Bookmark, ArrowRight, Loader2 } from 'lucide-react'
import { DialogButton, DialogFooter, DialogHeader, DialogShell, DialogTile, FooterSpacer, NEUTRAL_TINT, fs } from '../shared/DialogShell'
import { INPUT } from '../shared/dialogParts'
import { useToast } from '../shared/Toast'
import { useTranslation } from '../../i18n'
import { collectionsApi } from '../../api/collections'
@@ -24,6 +25,7 @@ interface SaveTripPlacesToListModalProps {
export default function SaveTripPlacesToListModal({ isOpen, tripId, placeIds, onClose, onDone }: SaveTripPlacesToListModalProps): React.ReactElement | null {
const { t } = useTranslation()
const toast = useToast()
const labelId = useId()
const [lists, setLists] = useState<Collection[]>([])
const [loading, setLoading] = useState(false)
const [search, setSearch] = useState('')
@@ -68,51 +70,68 @@ export default function SaveTripPlacesToListModal({ isOpen, tripId, placeIds, on
}
return (
<Modal isOpen onClose={onClose} title={t('collections.saveNToList', { count: placeIds.length })} size="sm">
<div className="flex flex-col gap-3">
{lists.length > 5 && (
<div className="relative">
<Search size={14} className="absolute left-2.5 top-1/2 -translate-y-1/2 text-content-faint" />
<input
autoFocus
value={search}
onChange={e => setSearch(e.target.value)}
placeholder={t('collections.searchLists')}
className="w-full pl-8 pr-3 py-2 rounded-lg border border-edge bg-surface-input text-content text-[13px] outline-none focus:border-accent"
/>
</div>
)}
{loading ? (
<div className="flex items-center justify-center py-10 text-content-faint"><Loader2 size={20} className="animate-spin" /></div>
) : filtered.length === 0 ? (
<p className="text-center text-[13px] text-content-faint py-8">{t('collections.noOwnLists')}</p>
) : (
<div className="flex flex-col gap-1 max-h-[50vh] overflow-y-auto -mx-1 px-1">
{filtered.map(list => {
const busy = busyId === list.id
return (
<button
key={list.id}
type="button"
onClick={() => pick(list)}
disabled={busyId != null}
className="flex items-center gap-3 px-3 py-2.5 rounded-xl border border-edge bg-surface-card text-left hover:bg-surface-hover transition-colors disabled:opacity-60"
>
<span className="w-9 h-9 min-w-[36px] rounded-lg flex items-center justify-center shrink-0 text-white" style={{ background: list.color || '#6366f1' }}>
<Bookmark size={15} />
</span>
<span className="flex-1 min-w-0">
<span className="block text-[13px] font-semibold text-content truncate">{list.name}</span>
<span className="block text-[11.5px] text-content-faint">{t('collections.placeCount', { count: list.place_count ?? 0 })}</span>
</span>
{busy ? <Loader2 size={15} className="animate-spin text-content-faint shrink-0" /> : <ArrowRight size={15} className="text-content-faint shrink-0" />}
</button>
)
})}
</div>
)}
<p className="text-[11.5px] text-content-faint inline-flex items-center gap-1.5"><Plus size={12} /> {t('collections.saveToListHint')}</p>
</div>
</Modal>
<DialogShell
onClose={onClose}
labelledBy={labelId}
width="narrow"
align="top"
header={(
<DialogHeader
tile={<DialogTile><Bookmark size={20} strokeWidth={1.9} className="text-content-muted" /></DialogTile>}
tint={NEUTRAL_TINT}
labelId={labelId}
onClose={onClose}
title={t('collections.saveNToList', { count: placeIds.length })}
sub={t('collections.saveToListHint')}
/>
)}
footer={(
<DialogFooter>
<FooterSpacer />
<DialogButton onClick={onClose}>{t('common.cancel')}</DialogButton>
</DialogFooter>
)}
>
{lists.length > 5 && (
<div className="relative">
<Search size={14} className="pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-content-faint" aria-hidden="true" />
<input
autoFocus
value={search}
onChange={e => setSearch(e.target.value)}
placeholder={t('collections.searchLists')}
aria-label={t('collections.searchLists')}
className={`${INPUT} pl-8`}
/>
</div>
)}
{loading ? (
<div className="flex items-center justify-center py-8 text-content-faint"><Loader2 size={20} className="animate-spin" /></div>
) : filtered.length === 0 ? (
<p className="m-0 rounded-[12px] bg-surface-secondary px-4 py-6 text-center text-content-faint" style={fs(12.5, 'body')}>{t('collections.noOwnLists')}</p>
) : (
<div className="flex flex-col gap-0.5 rounded-[14px] border border-edge-faint bg-surface-secondary p-1.5">
{filtered.map(list => {
const busy = busyId === list.id
return (
<button
key={list.id}
type="button"
onClick={() => pick(list)}
disabled={busyId != null}
className="flex min-h-[48px] items-center gap-3 rounded-[10px] px-3 py-2 text-left hover:bg-surface-card disabled:opacity-60"
>
<span className="h-2.5 w-2.5 flex-none rounded-full" style={{ background: list.color || '#6366f1' }} /* theme-lint-disable: the list's own colour, and the default a list without one is drawn in (ListsRail) */ />
<span className="min-w-0 flex-1">
<span className="block truncate font-semibold text-content" style={fs(13, 'body')}>{list.name}</span>
<span className="block text-content-faint" style={fs(11.5)}>{t('collections.placeCount', { count: list.place_count ?? 0 })}</span>
</span>
{busy ? <Loader2 size={15} className="flex-none animate-spin text-content-faint" /> : <ArrowRight size={15} className="flex-none text-content-faint" />}
</button>
)
})}
</div>
)}
</DialogShell>
)
}
@@ -57,6 +57,13 @@ function memberRow(username: string): HTMLElement {
return nameCell.parentElement as HTMLElement
}
/** The confirm button of the leave question. The question is drawn over the
* dialog, whose own Leave list button stays in the page, so it is the last one. */
function confirmLeaveButton(): HTMLElement {
const buttons = screen.getAllByRole('button', { name: 'Leave list' })
return buttons[buttons.length - 1]
}
describe('ShareCollectionModal', () => {
beforeEach(() => {
resetAllStores()
@@ -90,7 +97,8 @@ describe('ShareCollectionModal', () => {
it('FE-COMP-COLSHARE-002: the title names the list and the roster is counted', () => {
setup()
expect(screen.getByRole('heading', { name: 'Share “Tokyo 2026”' })).toBeInTheDocument()
expect(screen.getByRole('heading', { name: 'Share list' })).toBeInTheDocument()
expect(screen.getByRole('heading', { name: 'Tokyo 2026' })).toBeInTheDocument()
expect(screen.getByText('Members')).toBeInTheDocument()
expect(screen.getByText('3')).toBeInTheDocument()
})
@@ -257,7 +265,7 @@ describe('ShareCollectionModal', () => {
it('FE-COMP-COLSHARE-022: a confirmed leave calls the store and hands back to the page', async () => {
const { props } = setup({ isOwner: false })
fireEvent.click(screen.getByRole('button', { name: 'Leave list' }))
fireEvent.click(screen.getAllByRole('button', { name: 'Leave list' })[0])
fireEvent.click(confirmLeaveButton())
await waitFor(() => expect(actions.leave).toHaveBeenCalledWith(7))
expect(addToast).toHaveBeenCalledWith('You left the list', 'success', undefined)
expect(props.onAfterLeave).toHaveBeenCalledTimes(1)
@@ -267,7 +275,7 @@ describe('ShareCollectionModal', () => {
actions.leave.mockRejectedValue({ response: { data: { error: 'Owners cannot leave' } } })
const { props } = setup({ isOwner: false })
fireEvent.click(screen.getByRole('button', { name: 'Leave list' }))
fireEvent.click(screen.getAllByRole('button', { name: 'Leave list' })[0])
fireEvent.click(confirmLeaveButton())
await waitFor(() => expect(addToast).toHaveBeenCalledWith('Owners cannot leave', 'error', undefined))
expect(props.onAfterLeave).not.toHaveBeenCalled()
})
@@ -286,9 +294,7 @@ describe('ShareCollectionModal', () => {
it('FE-COMP-COLSHARE-025: the modal close button calls onClose', () => {
const { props } = setup()
// The Modal chrome's only unnamed control is its close button.
const header = screen.getByRole('heading', { name: 'Share “Tokyo 2026”' }).parentElement as HTMLElement
fireEvent.click(header.querySelector('button') as HTMLButtonElement)
fireEvent.click(screen.getByRole('button', { name: 'Close' }))
expect(props.onClose).toHaveBeenCalledTimes(1)
})
})
@@ -1,10 +1,13 @@
import React, { useEffect, useMemo, useState } from 'react'
import React, { useEffect, useId, useMemo, useState, type ReactNode } from 'react'
import { avatarSrc } from '../../utils/avatarSrc'
import { UserPlus, UserMinus, Loader2, Clock, Crown, LogOut } from 'lucide-react'
import { UserPlus, UserMinus, UserX, Loader2, Clock, Crown, LogOut, Share2 } from 'lucide-react'
import type { CollectionMember, CollectionRole } from '@trek/shared'
import Modal from '../shared/Modal'
import { DialogButton, DialogFooter, DialogHeader, DialogSection, DialogShell, DialogTile, FooterSpacer, NEUTRAL_TINT, fs } from '../shared/DialogShell'
import ConfirmDialog from '../shared/ConfirmDialog'
import CustomSelect from '../shared/CustomSelect'
import { Tooltip } from '../shared/Tooltip'
import { useToast } from '../shared/Toast'
import { TripMemberAvatar } from '../Trips/TripMemberAvatar'
import { useCollectionStore } from '../../store/collectionStore'
import { useAuthStore } from '../../store/authStore'
import { collectionsApi } from '../../api/collections'
@@ -25,16 +28,22 @@ interface ShareCollectionModalProps {
const ROLE_ORDER: CollectionRole[] = ['viewer', 'editor', 'admin']
function MemberAvatar({ member }: { member: CollectionMember }): React.ReactElement {
const initial = (member.username || '?').charAt(0).toUpperCase()
// The trip share dialog's roster, so a shared list and a shared trip read alike.
const COUNT = 'rounded-full bg-surface-tertiary px-2 py-[2px] font-geist font-bold text-content-muted'
const ROWS = 'flex flex-col gap-0.5 rounded-[14px] border border-edge-faint bg-surface-secondary p-1.5'
const ROW = 'flex min-h-[48px] items-center gap-3 rounded-[10px] px-2.5 py-1.5 hover:bg-surface-card'
const BADGE = 'inline-flex flex-none items-center gap-1 rounded-full px-2 py-[2px] font-semibold'
const DANGER_BUTTON = 'inline-flex items-center gap-1.5 rounded-[10px] bg-surface-card px-3.5 py-2 font-medium text-danger shadow-sm ring-1 ring-edge-faint hover:bg-danger-soft disabled:cursor-default disabled:opacity-50'
/** A round icon button of a row, named by its tooltip; faint until the pointer is on it. */
function RowAction({ label, onClick, disabled, children }: { label: string; onClick: () => void; disabled?: boolean; children: ReactNode }) {
return (
<span className="w-8 h-8 rounded-full shrink-0 overflow-hidden flex items-center justify-center bg-surface-secondary text-content-secondary text-[12px] font-semibold">
{member.avatar ? (
<img src={avatarSrc(member.avatar)!} alt="" className="w-full h-full object-cover" />
) : (
initial
)}
</span>
<Tooltip label={label}>
<button type="button" onClick={onClick} disabled={disabled} aria-label={label}
className="grid h-8 w-8 flex-none place-items-center rounded-[9px] text-content-faint hover:bg-surface-secondary hover:text-danger disabled:opacity-40">
{children}
</button>
</Tooltip>
)
}
@@ -56,6 +65,7 @@ export default function ShareCollectionModal({
t,
}: ShareCollectionModalProps): React.ReactElement | null {
const toast = useToast()
const labelId = useId()
const currentUserId = useAuthStore(s => s.user?.id)
const invite = useCollectionStore(s => s.invite)
const cancelInvite = useCollectionStore(s => s.cancelInvite)
@@ -162,168 +172,140 @@ export default function ShareCollectionModal({
}
}
return (
<Modal
isOpen
onClose={onClose}
title={t('collections.share.titleNamed', { name: collectionName })}
size="xl"
>
<div className="flex flex-col gap-5">
{/* Member roster */}
<div>
<h3 className="text-[11px] font-semibold uppercase tracking-wider text-content-faint mb-2.5 flex items-center gap-2">
{t('collections.share.members')}
<span className="inline-flex items-center justify-center min-w-[18px] h-[18px] px-1 rounded-full bg-surface-secondary text-content-secondary text-[10px] font-bold tabular-nums">{sortedMembers.length}</span>
</h3>
<div className="flex flex-col gap-1.5">
{sortedMembers.map(member => {
const isSelf = member.user_id === currentUserId
const pending = member.status === 'pending'
return (
<div
key={member.user_id}
className={`flex items-center gap-3 px-3 py-2.5 rounded-xl border border-edge bg-surface-secondary/50 ${pending ? 'opacity-90' : ''}`}
>
<MemberAvatar member={member} />
<div className="flex-1 min-w-0">
<p className="text-[13.5px] font-semibold text-content truncate flex items-center gap-1.5">
{member.username}
{isSelf && <span className="text-content-faint font-normal text-[12px]">({t('collections.share.you')})</span>}
</p>
{member.email && !pending && (
<p className="text-[11.5px] text-content-faint truncate">{member.email}</p>
)}
</div>
{member.is_owner ? (
<span className="inline-flex items-center gap-1 text-[10.5px] font-semibold uppercase tracking-wide px-2 py-1 rounded-full bg-amber-500/12 text-amber-600 dark:text-amber-400 shrink-0">
<Crown size={11} /> {t('collections.share.owner')}
</span>
) : pending ? (
<span className="inline-flex items-center gap-1 text-[10.5px] font-semibold uppercase tracking-wide px-2 py-1 rounded-full bg-amber-500/12 text-amber-600 dark:text-amber-400 shrink-0">
<Clock size={11} /> {t('collections.share.pending')}
</span>
) : isOwner ? (
<div className="w-[118px] shrink-0">
<CustomSelect
size="sm"
value={member.role ?? 'editor'}
onChange={v => handleSetRole(member.user_id, v as CollectionRole)}
options={ROLE_ORDER.map(r => ({ value: r, label: t(`collections.role.${r}`) }))}
disabled={settingRoleId === member.user_id}
/>
</div>
) : (
<span className="inline-flex items-center gap-1 text-[10.5px] font-semibold uppercase tracking-wide px-2 py-1 rounded-full bg-surface-secondary text-content-secondary shrink-0">
{t(`collections.role.${member.role ?? 'editor'}`)}
</span>
)}
{isOwner && pending && (
<button
type="button"
onClick={() => handleCancel(member.user_id)}
disabled={cancellingId === member.user_id}
className="shrink-0 text-[11px] font-medium px-2 py-1 rounded-md text-content-faint hover:text-danger hover:bg-danger-soft transition-colors disabled:opacity-50"
>
{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>
)
})}
</div>
</div>
const roleOptions = ROLE_ORDER.map(r => ({ value: r, label: t(`collections.role.${r}`) }))
{isOwner ? (
/* Owner: invite UI */
<div className="pt-1 border-t border-edge-secondary">
<h3 className="text-[11px] font-semibold uppercase tracking-wider text-content-faint mt-4 mb-2">
{t('collections.share.invite')}
</h3>
<p className="text-[12px] text-content-muted mb-3">{t('collections.share.inviteHint')}</p>
return (
<>
<DialogShell
onClose={onClose}
labelledBy={labelId}
width="detail"
// While the leave question is up, Escape and the backdrop answer it, not this dialog.
blocked={confirmLeave}
header={(
<DialogHeader
tile={<DialogTile><Share2 size={20} strokeWidth={1.9} className="text-content-muted" /></DialogTile>}
tint={NEUTRAL_TINT}
labelId={labelId}
onClose={onClose}
eyebrow={t('collections.share.title')}
title={collectionName}
/>
)}
// A member's way out sits where an editor keeps its delete: bottom left.
footer={isOwner ? undefined : (
<DialogFooter>
<button type="button" onClick={() => setConfirmLeave(true)} disabled={leaving} className={DANGER_BUTTON} style={fs(13, 'body')}>
{leaving ? <Loader2 size={14} className="animate-spin" /> : <LogOut size={14} strokeWidth={2.2} />}
{t('collections.share.leave')}
</button>
<FooterSpacer />
</DialogFooter>
)}
>
{isOwner && (
<DialogSection label={t('collections.share.invite')}>
<p className="m-0 mb-2.5 leading-normal text-content-faint" style={fs(11.5)}>{t('collections.share.inviteHint')}</p>
{availableUsers.length === 0 ? (
<p className="text-[12px] text-content-faint text-center py-3">{t('collections.share.noUsers')}</p>
<p className="m-0 rounded-[12px] border border-dashed border-edge px-3 py-3 text-center text-content-faint" style={fs(12, 'body')}>
{t('collections.share.noUsers')}
</p>
) : (
<div className="flex items-stretch gap-2">
<div className="flex-1 min-w-0">
<div className="flex items-center gap-2">
<div className="min-w-0 flex-1">
<CustomSelect
value={selectedUserId}
onChange={v => setSelectedUserId(v === '' ? '' : Number(v))}
options={availableUsers.map(u => ({ value: u.id, label: u.username }))}
placeholder={t('collections.share.inviteUser')}
searchable
/>
</div>
<div className="w-[128px] shrink-0">
<CustomSelect
size="sm"
value={inviteRole}
onChange={v => setInviteRole(v as CollectionRole)}
options={ROLE_ORDER.map(r => ({ value: r, label: t(`collections.role.${r}`) }))}
/>
</div>
<button
type="button"
onClick={handleInvite}
disabled={selectedUserId === '' || inviting}
className="shrink-0 inline-flex items-center gap-1.5 px-3 py-2 rounded-lg bg-accent text-accent-text text-[13px] font-semibold hover:bg-accent-hover transition-colors disabled:opacity-50"
>
{inviting ? <Loader2 size={14} className="animate-spin" /> : <UserPlus size={14} />}
<span className="hidden sm:inline">{t('collections.share.sendInvite')}</span>
</button>
</div>
)}
</div>
) : (
/* Member: read-only roster + leave */
<div className="pt-1 border-t border-edge-secondary">
<p className="text-[12px] text-content-muted mt-4 mb-3">{t('collections.share.memberHint')}</p>
{confirmLeave ? (
<div className="flex flex-col gap-2.5">
<p className="text-[13px] text-content-secondary">{t('collections.share.leaveConfirm')}</p>
<div className="flex justify-end gap-2">
<button
type="button"
onClick={() => setConfirmLeave(false)}
className="px-3 py-1.5 rounded-lg border border-edge text-content-secondary text-[13px] hover:bg-surface-hover transition-colors"
>
{t('common.cancel')}
</button>
<button
type="button"
onClick={handleLeave}
disabled={leaving}
className="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-danger text-white text-[13px] font-semibold hover:opacity-90 transition-opacity disabled:opacity-50"
>
{leaving ? <Loader2 size={14} className="animate-spin" /> : <LogOut size={14} />}
{t('collections.share.leave')}
</button>
<div className="w-[128px] flex-none">
<CustomSelect size="sm" value={inviteRole} onChange={v => setInviteRole(v as CollectionRole)} options={roleOptions} />
</div>
<DialogButton
variant="primary"
onClick={() => void handleInvite()}
disabled={selectedUserId === '' || inviting}
icon={inviting ? <Loader2 size={14} className="animate-spin" /> : <UserPlus size={14} strokeWidth={2.2} />}
>
{t('collections.share.sendInvite')}
</DialogButton>
</div>
) : (
<button
type="button"
onClick={() => setConfirmLeave(true)}
className="w-full inline-flex items-center justify-center gap-1.5 px-3 py-2 rounded-lg border border-edge text-danger text-[13px] font-medium hover:bg-danger-soft transition-colors"
>
<LogOut size={14} /> {t('collections.share.leave')}
</button>
)}
</div>
</DialogSection>
)}
</div>
</Modal>
<DialogSection label={(
<span className="inline-flex items-center gap-2">
{t('collections.share.members')}
<span className={COUNT} style={fs(10)}>{sortedMembers.length}</span>
</span>
)}>
<div className={ROWS}>
{sortedMembers.map(member => {
const isSelf = member.user_id === currentUserId
const pending = member.status === 'pending'
let standing: ReactNode
if (member.is_owner) {
standing = <span className={`${BADGE} bg-warning-soft text-warning`} style={fs(10.5)}><Crown size={10} strokeWidth={2.4} />{t('collections.share.owner')}</span>
} else if (pending) {
standing = <span className={`${BADGE} bg-warning-soft text-warning`} style={fs(10.5)}><Clock size={10} strokeWidth={2.4} />{t('collections.share.pending')}</span>
} else if (isOwner) {
standing = (
<div className="w-[118px] flex-none">
<CustomSelect
size="sm"
value={member.role ?? 'editor'}
onChange={v => handleSetRole(member.user_id, v as CollectionRole)}
options={roleOptions}
disabled={settingRoleId === member.user_id}
/>
</div>
)
} else {
standing = <span className={`${BADGE} bg-surface-tertiary text-content-muted`} style={fs(10.5)}>{t(`collections.role.${member.role ?? 'editor'}`)}</span>
}
return (
<div key={member.user_id} className={ROW}>
<TripMemberAvatar username={member.username} avatarUrl={avatarSrc(member.avatar)} />
<div className="min-w-0 flex-1">
<div className="truncate font-semibold text-content" style={fs(13, 'body')}>
{member.username}
{isSelf && <span className="ml-1 font-normal text-content-faint">({t('collections.share.you')})</span>}
</div>
{member.email && !pending && (
<div className="truncate text-content-faint" style={fs(11.5)}>{member.email}</div>
)}
</div>
{standing}
{isOwner && pending && (
<RowAction label={t('collections.share.cancel')} onClick={() => handleCancel(member.user_id)} disabled={cancellingId === member.user_id}>
{cancellingId === member.user_id ? <Loader2 size={14} className="animate-spin" /> : <UserX size={15} />}
</RowAction>
)}
{isOwner && !member.is_owner && member.status === 'accepted' && (
<RowAction label={t('collections.share.remove')} onClick={() => handleRemove(member.user_id)} disabled={removingId === member.user_id}>
{removingId === member.user_id ? <Loader2 size={14} className="animate-spin" /> : <UserMinus size={15} />}
</RowAction>
)}
</div>
)
})}
</div>
{!isOwner && <p className="m-0 mt-2.5 leading-normal text-content-faint" style={fs(11.5)}>{t('collections.share.memberHint')}</p>}
</DialogSection>
</DialogShell>
<ConfirmDialog
isOpen={confirmLeave}
onClose={() => setConfirmLeave(false)}
onConfirm={() => void handleLeave()}
title={t('collections.share.leave')}
message={t('collections.share.leaveConfirm')}
confirmLabel={t('collections.share.leave')}
/>
</>
)
}