mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 00:43:15 +00:00
fix(journey): give the entry photo picker its own dialog
The entry editor capped the provider picker in a small panel, so filters and competing footers displaced the photo grid. Open the picker over the editor at the available height on desktop and at full screen on mobile. Keep queued photos and draft edits in the editor until it is saved. Closes #3266
This commit is contained in:
@@ -469,7 +469,7 @@ describe('EntryEditor', () => {
|
||||
await user.click(screen.getByRole('button', { name: /Upload photos/ }))
|
||||
await user.click(screen.getByRole('button', { name: 'External photos' }))
|
||||
|
||||
expect(await screen.findByTestId('journey-external-provider-immich')).toBeInTheDocument()
|
||||
expect(await screen.findByRole('dialog', { name: 'Immich' })).toBeVisible()
|
||||
})
|
||||
|
||||
it('FE-JRN-EDITOR-020: queues photos picked from a connected provider and clears them again', async () => {
|
||||
@@ -478,8 +478,11 @@ describe('EntryEditor', () => {
|
||||
mountEditor(buildEntry({ id: 10, location_lat: 41.9, location_lng: 12.5, location_name: 'Rome' }))
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'External photos' }))
|
||||
expect(await screen.findByTestId('journey-external-provider-immich')).toBeInTheDocument()
|
||||
expect(screen.getByText('Nearby photos first: Rome')).toBeInTheDocument()
|
||||
const picker = await screen.findByRole('dialog', { name: 'Immich' })
|
||||
expect(picker).toHaveClass('h-full')
|
||||
expect(screen.getByRole('button', { name: 'Cancel' })).toBeVisible()
|
||||
expect(screen.queryByRole('button', { name: 'Save' })).not.toBeInTheDocument()
|
||||
expect(picker).toHaveTextContent('Nearby photos first Rome')
|
||||
expect(screen.getByText('Photos for Mar 15, 2026')).toBeInTheDocument()
|
||||
|
||||
await user.click(await screen.findByAltText(''))
|
||||
@@ -720,13 +723,15 @@ describe('EntryEditor', () => {
|
||||
await user.click(screen.getByRole('button', { name: 'Add (1)' }))
|
||||
await screen.findByRole('button', { name: /1 queued Clear/ })
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'External photos' }))
|
||||
await user.click(screen.getByTestId('journey-external-provider-photoprism'))
|
||||
expect(screen.getByTestId('journey-external-provider-photoprism').className).toContain('bg-accent')
|
||||
expect(screen.getByTestId('journey-external-provider-photoprism')).toHaveAttribute('aria-pressed', 'true')
|
||||
|
||||
// The picker's own cancel drops back to the first available provider.
|
||||
await user.click(screen.getAllByRole('button', { name: 'Cancel' })[0])
|
||||
expect(screen.getByTestId('journey-external-provider-photoprism').className).not.toContain('bg-accent')
|
||||
await user.keyboard('{Escape}')
|
||||
expect(screen.queryByRole('dialog', { name: 'PhotoPrism' })).not.toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: /1 queued Clear/ })).toBeInTheDocument()
|
||||
await user.click(screen.getByRole('button', { name: 'External photos' }))
|
||||
expect(screen.getByTestId('journey-external-provider-immich')).toHaveAttribute('aria-pressed', 'true')
|
||||
})
|
||||
|
||||
it('FE-JRN-EDITOR-033: merges a second pick into the already queued group', async () => {
|
||||
@@ -755,12 +760,14 @@ describe('EntryEditor', () => {
|
||||
await user.click(screen.getByRole('button', { name: 'Add (1)' }))
|
||||
await screen.findByRole('button', { name: /1 queued Clear/ })
|
||||
|
||||
// The first asset stays selected but is now greyed out, so the second Add
|
||||
// re-sends it and the merge has to skip the duplicate.
|
||||
const remaining = screen.getAllByAltText('').find(img => !img.parentElement!.className.includes('opacity-40'))!
|
||||
// The first asset is already queued, so it remains unavailable on reopening.
|
||||
await user.click(screen.getByRole('button', { name: 'External photos' }))
|
||||
const reopened = await screen.findAllByAltText('')
|
||||
expect(reopened.find(img => assetIdOf(img) === firstId)?.parentElement).toBeDisabled()
|
||||
const remaining = reopened.find(img => assetIdOf(img) !== firstId)!
|
||||
const secondId = assetIdOf(remaining)
|
||||
await user.click(remaining)
|
||||
await user.click(screen.getByRole('button', { name: 'Add (2)' }))
|
||||
await user.click(screen.getByRole('button', { name: 'Add (1)' }))
|
||||
expect(await screen.findByRole('button', { name: /2 queued Clear/ })).toBeInTheDocument()
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Save' }))
|
||||
@@ -782,7 +789,7 @@ describe('EntryEditor', () => {
|
||||
}))
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'External photos' }))
|
||||
await screen.findByTestId('journey-external-provider-immich')
|
||||
await screen.findByRole('dialog', { name: 'Immich' })
|
||||
|
||||
await waitFor(() => expect(document.querySelector('.opacity-40')).toBeInTheDocument())
|
||||
expect(screen.queryByRole('button', { name: /Select all/ })).not.toBeInTheDocument()
|
||||
@@ -796,7 +803,7 @@ describe('EntryEditor', () => {
|
||||
await user.click(screen.getByRole('button', { name: 'External photos' }))
|
||||
|
||||
expect(await screen.findByText('All photos from this day')).toBeInTheDocument()
|
||||
expect(await screen.findByTestId('journey-external-provider-immich')).toBeInTheDocument()
|
||||
expect(await screen.findByRole('dialog', { name: 'Immich' })).toBeVisible()
|
||||
})
|
||||
|
||||
it('FE-JRN-EDITOR-040: ignores a link call that comes back without a photo', async () => {
|
||||
|
||||
@@ -26,7 +26,7 @@ const CHIP_OFF = 'border-edge-faint bg-surface-card text-content-muted hover:tex
|
||||
const SOURCE = 'flex items-center justify-center gap-1.5 rounded-[12px] border py-4 font-medium disabled:cursor-default disabled:opacity-50'
|
||||
const SOURCE_OFF = 'border-dashed border-edge text-content-muted hover:border-content-faint hover:bg-surface-secondary hover:text-content'
|
||||
const SOURCE_ON = 'border-content bg-surface-secondary text-content'
|
||||
/** The panel a photo source opens under the buttons: the gallery grid, the provider browser. */
|
||||
/** The gallery grid under the source buttons. */
|
||||
const PHOTO_PANEL = 'mt-2 rounded-[12px] border border-edge-faint bg-surface-secondary'
|
||||
/** A control laid over a photo tile, raised on the card colour so it reads on any picture. */
|
||||
const ON_PHOTO = 'bg-surface-card text-content shadow-sm'
|
||||
@@ -148,7 +148,7 @@ export function EntryEditor({ entry, journeyId, tripDates, galleryPhotos, trips,
|
||||
mood, setMood, weather, setWeather, statsExcluded, setStatsExcluded, tripSuggestion, isDraft, setIsDraft,
|
||||
pros, setPros, cons, setCons, tags, setTags, tagInput, setTagInput, addTag, saving, uploadProgress, photos, photoOrder, canReorder,
|
||||
pendingFiles, setPendingFiles, pendingPreviews: pendingUrls,
|
||||
pendingProviderGroups, setPendingProviderGroups, showGalleryPick, setShowGalleryPick, isDirty,
|
||||
queuedProviderPhotos, setPendingProviderGroups, queueProviderPhotos, showGalleryPick, setShowGalleryPick, isDirty,
|
||||
availableGalleryPhotos, providerAssetIds, contextLocation, offersStatsToggle, addVerdictRow, verdictRowRef,
|
||||
handleSave, handleFileChange, pickGalleryPhoto, removePhoto, searchLocation, pickLocation, handleUseCurrentLocation,
|
||||
} = useJourneyEntryForm({
|
||||
@@ -193,6 +193,11 @@ export function EntryEditor({ entry, journeyId, tripDates, galleryPhotos, trips,
|
||||
|
||||
const activeExternalProvider = externalProvider || availableProviders[0]?.id || null
|
||||
const providerExistingAssetIds = providerAssetIds(activeExternalProvider)
|
||||
const providerPickerOpen = photoTab === 'external' && photoProvidersOn && !!activeExternalProvider
|
||||
const closeProviderPicker = () => {
|
||||
setPhotoTab('upload')
|
||||
setExternalProvider(null)
|
||||
}
|
||||
|
||||
// Every way out (Cancel, the close button, Escape, the dimmed backdrop) comes
|
||||
// through here, so none of them drops an edit without asking first.
|
||||
@@ -232,9 +237,7 @@ export function EntryEditor({ entry, journeyId, tripDates, galleryPhotos, trips,
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* Pinned at the top: the photo panels, the verdict rows and the photo
|
||||
strip all change the body's height while an entry is being written. */}
|
||||
<DialogShell onClose={handleClose} labelledBy={labelId} width="wide" blocked={confirmDiscard} header={header} footer={footer}>
|
||||
<DialogShell onClose={handleClose} labelledBy={labelId} width="wide" blocked={confirmDiscard} covered={providerPickerOpen} header={header} footer={footer}>
|
||||
<div className="grid grid-cols-1 items-stretch gap-x-6 gap-y-5 md:grid-cols-2">
|
||||
<div className="flex min-w-0 flex-col gap-5">
|
||||
<div>
|
||||
@@ -319,86 +322,18 @@ export function EntryEditor({ entry, journeyId, tripDates, galleryPhotos, trips,
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{photoTab === 'external' && photoProvidersOn && (
|
||||
<div className={`${PHOTO_PANEL} flex flex-col overflow-hidden`} style={{ height: 'min(56vh, 520px)' }}>
|
||||
<div className="flex items-center justify-between gap-2 border-b border-edge-faint px-3 py-2">
|
||||
<div className="min-w-0">
|
||||
<p className="truncate font-semibold text-content" style={fs(11.5)}>
|
||||
{t('journey.editor.externalPhotosFor', { date: new Date(entryDate + 'T00:00:00').toLocaleDateString(undefined, { year: 'numeric', month: 'short', day: 'numeric' }) })}
|
||||
</p>
|
||||
<p className="truncate text-content-faint" style={fs(10.5)}>
|
||||
{contextLocation?.name
|
||||
? `${t('journey.editor.externalPhotosNearby') || 'Nearby photos first'}: ${contextLocation.name}`
|
||||
: (t('journey.editor.externalPhotosNoLocation') || 'All photos from this day')}
|
||||
</p>
|
||||
</div>
|
||||
{pendingProviderGroups.length > 0 && (
|
||||
<button type="button" onClick={() => setPendingProviderGroups([])} className="inline-flex items-center gap-1.5 whitespace-nowrap text-content-muted hover:text-content" style={fs(10.5)}>
|
||||
<span>{pendingProviderGroups.reduce((sum, group) => sum + group.assetIds.length, 0)} {t('journey.editor.externalPhotosQueued') || 'queued'}</span>{' '}
|
||||
<span className="font-semibold text-content">{t('common.clear') || 'Clear'}</span>
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
{providersLoading ? (
|
||||
<div className="flex justify-center py-8"><Loader2 size={20} className="animate-spin text-content-faint" /></div>
|
||||
) : availableProviders.length === 0 ? (
|
||||
<div className="px-4 py-10 text-center text-content-muted" style={fs(12, 'body')}>{t('journey.editor.externalPhotosUnavailable') || 'No connected photo providers are available.'}</div>
|
||||
) : (
|
||||
<div className="flex h-full min-h-0 flex-col">
|
||||
<div className="flex gap-1 overflow-x-auto border-b border-edge-faint px-3 py-2" style={fs(11.5)}>
|
||||
{availableProviders.map(provider => (
|
||||
<button type="button"
|
||||
key={provider.id}
|
||||
data-testid={`journey-external-provider-${provider.id}`}
|
||||
onClick={() => setExternalProvider(provider.id)}
|
||||
aria-pressed={externalProvider === provider.id}
|
||||
className={`whitespace-nowrap rounded-[8px] px-2.5 py-1 font-medium ${externalProvider === provider.id ? 'bg-accent text-accent-text' : 'text-content-muted hover:bg-surface-hover hover:text-content'}`}
|
||||
>
|
||||
{provider.name}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
{activeExternalProvider && (
|
||||
<div className="min-h-0 flex-1">
|
||||
<ProviderPicker
|
||||
key={`${activeExternalProvider}-${entryDate}`}
|
||||
provider={activeExternalProvider}
|
||||
userId={userId}
|
||||
entries={[entry]}
|
||||
trips={trips}
|
||||
existingAssetIds={providerExistingAssetIds}
|
||||
initialDate={entryDate}
|
||||
contextLocation={contextLocation}
|
||||
initialEntryId={entry.id || null}
|
||||
embedded
|
||||
onClose={() => setExternalProvider(null)}
|
||||
onAdd={async groups => {
|
||||
setPendingProviderGroups(previous => {
|
||||
const next = [...previous]
|
||||
for (const group of groups) {
|
||||
const existing = next.find(item => item.provider === activeExternalProvider && item.passphrase === group.passphrase)
|
||||
if (existing) {
|
||||
const seen = new Set(existing.assetIds)
|
||||
group.assetIds.forEach((assetId, index) => {
|
||||
if (seen.has(assetId)) return
|
||||
seen.add(assetId)
|
||||
existing.assetIds.push(assetId)
|
||||
existing.mediaTypes?.push(group.mediaTypes?.[index] || 'image')
|
||||
})
|
||||
} else {
|
||||
next.push({ ...group, provider: activeExternalProvider })
|
||||
}
|
||||
}
|
||||
return next
|
||||
})
|
||||
setExternalProvider(null)
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{photoTab === 'external' && photoProvidersOn && !activeExternalProvider && (
|
||||
providersLoading ? (
|
||||
<div className="flex justify-center py-4"><Loader2 size={20} className="animate-spin text-content-faint" /></div>
|
||||
) : (
|
||||
<div className="py-3 text-center text-caption text-content-muted">{t('journey.editor.externalPhotosUnavailable')}</div>
|
||||
)
|
||||
)}
|
||||
{queuedProviderPhotos > 0 && (
|
||||
<button type="button" onClick={() => setPendingProviderGroups([])} className="mt-2 inline-flex items-center gap-1.5 whitespace-nowrap text-caption text-content-muted hover:text-content">
|
||||
<span>{queuedProviderPhotos} {t('journey.editor.externalPhotosQueued')}</span>{' '}
|
||||
<span className="font-semibold text-content">{t('common.clear')}</span>
|
||||
</button>
|
||||
)}
|
||||
{(photos.length > 0 || pendingFiles.length > 0) && (
|
||||
<div className="mt-3 flex flex-wrap gap-2">
|
||||
@@ -690,6 +625,26 @@ export function EntryEditor({ entry, journeyId, tripDates, galleryPhotos, trips,
|
||||
</div>
|
||||
</DialogShell>
|
||||
|
||||
{providerPickerOpen && activeExternalProvider && (
|
||||
<ProviderPicker
|
||||
key={`${activeExternalProvider}-${entryDate}`}
|
||||
provider={activeExternalProvider}
|
||||
userId={userId}
|
||||
entries={[entry]}
|
||||
trips={trips}
|
||||
existingAssetIds={providerExistingAssetIds}
|
||||
initialDate={entryDate}
|
||||
contextLocation={contextLocation}
|
||||
initialEntryId={entry.id || null}
|
||||
entryPicker={{ providers: availableProviders, onSelectProvider: setExternalProvider }}
|
||||
onClose={closeProviderPicker}
|
||||
onAdd={async groups => {
|
||||
queueProviderPhotos(activeExternalProvider, groups)
|
||||
closeProviderPicker()
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Mounted only while asked, over the editor, which ignores Escape and its
|
||||
backdrop until the question is answered. */}
|
||||
{confirmDiscard && (
|
||||
|
||||
@@ -392,11 +392,10 @@ describe('ProviderPicker', () => {
|
||||
}
|
||||
})
|
||||
|
||||
it('FE-JRN-PICKER-018: the embedded variant drops the header, the add-to bar and the date captions', async () => {
|
||||
mountPicker({ embedded: true, initialDate: '2026-03-15' })
|
||||
it('FE-JRN-PICKER-018: entry mode opens a taller picker and keeps the entry as its target', async () => {
|
||||
mountPicker({ entryPicker: { providers: [{ id: 'immich', name: 'Immich' }], onSelectProvider: vi.fn() }, initialDate: '2026-03-15' })
|
||||
|
||||
expect(await screen.findByTestId('journey-provider-picker-embedded')).toBeInTheDocument()
|
||||
expect(screen.queryByRole('heading', { name: 'Immich' })).not.toBeInTheDocument()
|
||||
expect(await screen.findByRole('dialog', { name: 'Immich' })).toHaveClass('h-full')
|
||||
expect(screen.queryByText('Add to')).not.toBeInTheDocument()
|
||||
expect(screen.queryByText('March 15, 2026')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ArrowRight, Calendar, Camera, Check, ChevronRight, Images, Loader2, Play, X } from 'lucide-react';
|
||||
import { useEffect, useId, useMemo, useRef, useState } from 'react';
|
||||
import { useEffect, useId, useMemo, useRef, useState, type ComponentType, type ReactNode } from 'react';
|
||||
import { memoriesApi } from '../../api/client';
|
||||
import { useTranslation } from '../../i18n';
|
||||
import { useIsPhone } from '../../mobile/useIsPhone';
|
||||
@@ -20,9 +20,18 @@ import type { JourneyEntry, JourneyTrip } from '../../store/journeyStore';
|
||||
import { DatePicker } from './JourneyDetailPageDatePicker';
|
||||
import { ScrollTrigger } from './JourneyDetailPageScrollTrigger';
|
||||
import { providerAssetUrl } from './providerAssetUrl';
|
||||
import type { ConnectedPhotoProvider } from './useConnectedPhotoProviders';
|
||||
|
||||
export type ProviderPhotoGroup = { assetIds: string[]; passphrase?: string; mediaTypes?: string[] };
|
||||
|
||||
export interface EntryPhotoPickerFrameProps {
|
||||
title: string;
|
||||
subtitle: ReactNode;
|
||||
onClose: () => void;
|
||||
footer: ReactNode;
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
/** A tile as the search and album routes answer it; only what a pick needs is spelled out. */
|
||||
type PickerAsset = ProviderPhotoAsset & { mediaType?: string };
|
||||
|
||||
@@ -50,7 +59,7 @@ export function ProviderPicker({
|
||||
initialDate,
|
||||
contextLocation,
|
||||
initialEntryId,
|
||||
embedded = false,
|
||||
entryPicker,
|
||||
}: {
|
||||
provider: string;
|
||||
userId: number;
|
||||
@@ -62,9 +71,13 @@ export function ProviderPicker({
|
||||
initialDate?: string;
|
||||
contextLocation?: (GeoPoint & { name?: string }) | null;
|
||||
initialEntryId?: number | null;
|
||||
embedded?: boolean;
|
||||
entryPicker?: {
|
||||
providers: ConnectedPhotoProvider[];
|
||||
onSelectProvider: (provider: string) => void;
|
||||
Frame?: ComponentType<EntryPhotoPickerFrameProps>;
|
||||
};
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const { t, locale } = useTranslation();
|
||||
const phone = useIsPhone();
|
||||
const labelId = useId();
|
||||
const [filter, setFilter] = useState<'day' | 'trip' | 'custom' | 'all' | 'album'>(initialDate ? 'day' : 'trip');
|
||||
@@ -329,7 +342,8 @@ export function ProviderPicker({
|
||||
t('journey.stats.entries')
|
||||
: t('journey.picker.newGallery');
|
||||
|
||||
const providerName = provider === 'immich' ? 'Immich' : provider === 'synologyphotos' ? 'Synology Photos' : provider;
|
||||
const providerName = entryPicker?.providers.find((source) => source.id === provider)?.name ??
|
||||
(provider === 'immich' ? 'Immich' : provider === 'synologyphotos' ? 'Synology Photos' : provider);
|
||||
|
||||
const addSelection = async () => {
|
||||
if (adding) return;
|
||||
@@ -357,15 +371,47 @@ export function ProviderPicker({
|
||||
}
|
||||
};
|
||||
|
||||
// Everything between the head and the foot, the same in all three frames below.
|
||||
const subtitle = entryPicker && (
|
||||
<>
|
||||
{initialDate && (
|
||||
<div>{t('journey.editor.externalPhotosFor', {
|
||||
date: new Date(`${initialDate}T00:00:00`).toLocaleDateString(locale, {
|
||||
year: 'numeric', month: 'short', day: 'numeric',
|
||||
}),
|
||||
})}</div>
|
||||
)}
|
||||
<div>
|
||||
{contextLocation?.name
|
||||
? <>{t('journey.editor.externalPhotosNearby')} <bdi>{contextLocation.name}</bdi></>
|
||||
: t('journey.editor.externalPhotosNoLocation')}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
|
||||
// The filters and selection are the same in each frame.
|
||||
const content = (
|
||||
<>
|
||||
{/* Filter bar. Embedded in the entry editor this sits in a panel a few hundred
|
||||
pixels tall, so its padding is the difference between three rows of
|
||||
thumbnails and two. */}
|
||||
<div className={`flex-shrink-0 border-b border-zinc-200 dark:border-zinc-700 ${embedded ? 'px-3 py-2' : 'px-6 py-3'}`}>
|
||||
<div className={`flex-shrink-0 border-b border-zinc-200 dark:border-zinc-700 ${entryPicker ? 'px-3 py-2' : 'px-6 py-3'}`}>
|
||||
{entryPicker && entryPicker.providers.length > 1 && (
|
||||
<div className="mb-2 flex gap-1 overflow-x-auto" role="group" aria-label={t('journey.editor.externalPhotos')}>
|
||||
{entryPicker.providers.map((source) => (
|
||||
<button
|
||||
type="button"
|
||||
key={source.id}
|
||||
data-testid={`journey-external-provider-${source.id}`}
|
||||
aria-pressed={provider === source.id}
|
||||
onClick={() => entryPicker.onSelectProvider(source.id)}
|
||||
className={`shrink-0 rounded-lg px-2.5 py-1 text-caption font-medium ${provider === source.id
|
||||
? 'bg-accent text-accent-text'
|
||||
: 'text-content-muted hover:bg-surface-hover hover:text-content'}`}
|
||||
>
|
||||
{source.name}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{/* Tabs */}
|
||||
<div className={`flex gap-1.5 ${embedded && filter === 'day' ? '' : 'mb-3'}`}>
|
||||
<div className={`flex gap-1.5 ${entryPicker ? 'overflow-x-auto' : ''} ${entryPicker && filter === 'day' ? '' : 'mb-3'}`}>
|
||||
{[
|
||||
...(initialDate ? [{ id: 'day' as const, label: t('journey.picker.day') || 'This day' }] : []),
|
||||
{ id: 'trip' as const, label: t('journey.picker.tripPeriod') },
|
||||
@@ -377,7 +423,7 @@ export function ProviderPicker({
|
||||
type="button"
|
||||
key={f.id}
|
||||
onClick={() => switchTab(f.id)}
|
||||
className={`rounded-lg px-3 py-1.5 text-[12px] font-medium transition-colors ${
|
||||
className={`rounded-lg px-3 py-1.5 text-[12px] font-medium transition-colors ${entryPicker ? 'shrink-0 whitespace-nowrap' : ''} ${
|
||||
filter === f.id
|
||||
? 'bg-zinc-900 text-white dark:bg-white dark:text-zinc-900'
|
||||
: 'text-zinc-500 hover:bg-zinc-100 dark:hover:bg-zinc-800'
|
||||
@@ -396,7 +442,7 @@ export function ProviderPicker({
|
||||
</div>
|
||||
|
||||
{/* Filter content — always visible row */}
|
||||
{(!embedded || filter !== 'day') && (
|
||||
{(!entryPicker || filter !== 'day') && (
|
||||
<div className="flex min-h-[36px] items-center">
|
||||
{filter === 'day' && initialDate && (
|
||||
<div className="flex items-center gap-2 text-[12px] text-zinc-500">
|
||||
@@ -531,7 +577,7 @@ export function ProviderPicker({
|
||||
</div>
|
||||
|
||||
{/* Add-to entry selector */}
|
||||
{!embedded && (
|
||||
{!entryPicker && (
|
||||
<div className="flex-shrink-0 border-b border-zinc-200 bg-zinc-50 px-6 py-2.5 dark:border-zinc-700 dark:bg-zinc-800/50">
|
||||
<div className="relative flex items-center gap-2">
|
||||
<span className="text-[10px] font-semibold tracking-[0.12em] text-zinc-500 uppercase">
|
||||
@@ -666,7 +712,7 @@ export function ProviderPicker({
|
||||
<div>
|
||||
{groupPhotosByDate(sortedPhotos).map((group) => (
|
||||
<div key={group.date}>
|
||||
{(!embedded || filter !== 'day') && (
|
||||
{(!entryPicker || filter !== 'day') && (
|
||||
<p className="mt-4 mb-2 text-[11px] font-medium text-zinc-500 first:mt-0 dark:text-zinc-400">
|
||||
{group.label}
|
||||
</p>
|
||||
@@ -741,9 +787,31 @@ export function ProviderPicker({
|
||||
</>
|
||||
);
|
||||
|
||||
// The desktop draws the standalone picker in the planner's dialog frame. The
|
||||
// phone keeps its sheet below, and the embedded picker has no frame at all.
|
||||
if (!embedded && !phone) {
|
||||
const footer = (
|
||||
<DialogFooter>
|
||||
<FooterSpacer />
|
||||
<DialogButton onClick={onClose}>{t('common.cancel')}</DialogButton>
|
||||
<DialogButton
|
||||
variant="primary"
|
||||
onClick={() => void addSelection()}
|
||||
disabled={addDisabled}
|
||||
icon={adding ? <Loader2 size={14} className="animate-spin" /> : undefined}
|
||||
>
|
||||
{t('common.add')} {selected.size > 0 ? `(${selected.size})` : ''}
|
||||
</DialogButton>
|
||||
</DialogFooter>
|
||||
);
|
||||
|
||||
const EntryFrame = entryPicker?.Frame;
|
||||
if (EntryFrame) {
|
||||
return (
|
||||
<EntryFrame title={providerName} subtitle={subtitle} onClose={onClose} footer={footer}>
|
||||
{content}
|
||||
</EntryFrame>
|
||||
);
|
||||
}
|
||||
|
||||
if (entryPicker || !phone) {
|
||||
return (
|
||||
<DialogShell
|
||||
// With the add-to menu open, Escape and a click beside the dialog close
|
||||
@@ -754,8 +822,9 @@ export function ProviderPicker({
|
||||
}}
|
||||
labelledBy={labelId}
|
||||
width="wide"
|
||||
fillHeight={!!entryPicker}
|
||||
// The tabs change how much the grid holds, so the upper edge stays put.
|
||||
align="top"
|
||||
align={entryPicker ? 'center' : 'top'}
|
||||
header={(
|
||||
<DialogHeader
|
||||
tile={<DialogTile><Images size={20} strokeWidth={1.9} className="text-content-muted" /></DialogTile>}
|
||||
@@ -763,24 +832,12 @@ export function ProviderPicker({
|
||||
labelId={labelId}
|
||||
onClose={onClose}
|
||||
title={providerName}
|
||||
sub={subtitle}
|
||||
/>
|
||||
)}
|
||||
// The bars stay pinned above the grid, which scrolls on its own.
|
||||
bodyClassName="flex min-h-0 flex-1 flex-col"
|
||||
footer={(
|
||||
<DialogFooter>
|
||||
<FooterSpacer />
|
||||
<DialogButton onClick={onClose}>{t('common.cancel')}</DialogButton>
|
||||
<DialogButton
|
||||
variant="primary"
|
||||
onClick={() => void addSelection()}
|
||||
disabled={addDisabled}
|
||||
icon={adding ? <Loader2 size={14} className="animate-spin" /> : undefined}
|
||||
>
|
||||
{t('common.add')} {selected.size > 0 ? `(${selected.size})` : ''}
|
||||
</DialogButton>
|
||||
</DialogFooter>
|
||||
)}
|
||||
footer={footer}
|
||||
>
|
||||
{content}
|
||||
</DialogShell>
|
||||
@@ -789,51 +846,36 @@ export function ProviderPicker({
|
||||
|
||||
return (
|
||||
<div
|
||||
data-testid={embedded ? 'journey-provider-picker-embedded' : undefined}
|
||||
className={
|
||||
embedded
|
||||
? 'flex h-full min-h-0 w-full flex-col overflow-hidden'
|
||||
: 'fixed inset-0 z-[9999] flex items-end justify-center overscroll-none bg-[rgba(9,9,11,0.75)] md:items-center md:p-5'
|
||||
}
|
||||
className="fixed inset-0 z-[9999] flex items-end justify-center overscroll-none bg-[rgba(9,9,11,0.75)] md:items-center md:p-5"
|
||||
role="presentation"
|
||||
onClick={embedded ? undefined : onClose}
|
||||
onClick={onClose}
|
||||
onTouchMove={(e) => {
|
||||
if (!embedded && e.target === e.currentTarget) e.preventDefault();
|
||||
if (e.target === e.currentTarget) e.preventDefault();
|
||||
}}
|
||||
>
|
||||
<div
|
||||
className={
|
||||
embedded
|
||||
? 'flex h-full w-full flex-col overflow-hidden bg-white dark:bg-zinc-900'
|
||||
: 'flex max-h-[calc(100dvh-var(--bottom-nav-h)-20px)] w-full max-w-[720px] flex-col overflow-hidden rounded-t-2xl bg-white shadow-[0_20px_40px_rgba(0,0,0,0.2)] md:max-h-[85vh] md:max-w-[960px] md:rounded-2xl dark:bg-zinc-900'
|
||||
}
|
||||
className="flex max-h-[calc(100dvh-var(--bottom-nav-h)-20px)] w-full max-w-[720px] flex-col overflow-hidden rounded-t-2xl bg-white shadow-[0_20px_40px_rgba(0,0,0,0.2)] md:max-h-[85vh] md:max-w-[960px] md:rounded-2xl dark:bg-zinc-900"
|
||||
style={{ paddingBottom: 'env(safe-area-inset-bottom, 0px)' }}
|
||||
role="presentation"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
{/* Header */}
|
||||
{!embedded && (
|
||||
<div className="flex flex-shrink-0 items-center justify-between border-b border-zinc-200 px-6 py-4 dark:border-zinc-700">
|
||||
<h2 className="text-[16px] font-bold text-zinc-900 dark:text-white">
|
||||
{providerName}
|
||||
</h2>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClose}
|
||||
className="flex h-8 w-8 items-center justify-center rounded-lg text-zinc-400 hover:bg-zinc-100 dark:hover:bg-zinc-800"
|
||||
>
|
||||
<X size={16} />
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
<div className="flex flex-shrink-0 items-center justify-between border-b border-zinc-200 px-6 py-4 dark:border-zinc-700">
|
||||
<h2 className="text-[16px] font-bold text-zinc-900 dark:text-white">
|
||||
{providerName}
|
||||
</h2>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClose}
|
||||
className="flex h-8 w-8 items-center justify-center rounded-lg text-zinc-400 hover:bg-zinc-100 dark:hover:bg-zinc-800"
|
||||
>
|
||||
<X size={16} />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{content}
|
||||
|
||||
{/* Footer. The count used to sit here as its own pill as well as on the Add
|
||||
button; one of the two was always saying it twice, and inside the entry
|
||||
editor the row it took cost the grid a row of thumbnails (discussion
|
||||
#2299). Embedded, the whole bar is tighter for the same reason. */}
|
||||
<div className={`flex flex-shrink-0 items-center justify-end border-t border-zinc-200 bg-zinc-50 dark:border-zinc-700 dark:bg-zinc-800/50 ${embedded ? 'px-3 py-2' : 'px-6 py-4'}`}>
|
||||
<div className="flex flex-shrink-0 items-center justify-end border-t border-zinc-200 bg-zinc-50 px-6 py-4 dark:border-zinc-700 dark:bg-zinc-800/50">
|
||||
<div className="flex items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
|
||||
@@ -181,6 +181,26 @@ export function useJourneyEntryForm({
|
||||
const availableGalleryPhotos = galleryPhotos.filter((gp) => !photos.some((p) => p.id === gp.id));
|
||||
const queuedProviderPhotos = pendingProviderGroups.reduce((sum, group) => sum + group.assetIds.length, 0);
|
||||
|
||||
const queueProviderPhotos = (provider: string, groups: ProviderPhotoGroup[]) => {
|
||||
setPendingProviderGroups((previous) => {
|
||||
const next = [...previous];
|
||||
for (const group of groups) {
|
||||
const index = next.findIndex((pick) => pick.provider === provider && pick.passphrase === group.passphrase);
|
||||
if (index < 0) {
|
||||
next.push({ ...group, provider });
|
||||
continue;
|
||||
}
|
||||
const existing = next[index]!;
|
||||
const assets = new Map(existing.assetIds.map((id, i) => [id, existing.mediaTypes?.[i] ?? 'image']));
|
||||
group.assetIds.forEach((id, i) => {
|
||||
if (!assets.has(id)) assets.set(id, group.mediaTypes?.[i] ?? 'image');
|
||||
});
|
||||
next[index] = { ...existing, assetIds: [...assets.keys()], mediaTypes: [...assets.values()] };
|
||||
}
|
||||
return next;
|
||||
});
|
||||
};
|
||||
|
||||
/** The provider assets already on the entry or queued for it, so the picker can mark them. */
|
||||
const providerAssetIds = (provider: string | null): Set<string> => {
|
||||
const ids = new Set<string>();
|
||||
@@ -625,6 +645,7 @@ export function useJourneyEntryForm({
|
||||
pendingPreviews,
|
||||
pendingProviderGroups,
|
||||
setPendingProviderGroups,
|
||||
queueProviderPhotos,
|
||||
showGalleryPick,
|
||||
setShowGalleryPick,
|
||||
isDirty,
|
||||
|
||||
@@ -26,10 +26,14 @@ export interface DialogShellProps {
|
||||
labelledBy: string
|
||||
/** 520 px for a single question, 600 px for a detail, 720 px for an editor, 960 px for one in two columns. */
|
||||
width?: keyof typeof PANEL_WIDTH
|
||||
/** Fill the available height when the body is a browser with its own scrolling area. */
|
||||
fillHeight?: boolean
|
||||
/** 'top' pins the upper edge, so a dialog whose content changes height does not jump. */
|
||||
align?: 'center' | 'top'
|
||||
/** True while a question opened from here is being answered: Escape and the backdrop leave the dialog alone. */
|
||||
blocked?: boolean
|
||||
/** A separate dialog is open in front of this one. */
|
||||
covered?: boolean
|
||||
header: ReactNode
|
||||
footer?: ReactNode
|
||||
/** Makes the scrolling body a form. */
|
||||
@@ -86,7 +90,7 @@ export function DialogShell({ open = true, ...frame }: DialogShellProps) {
|
||||
return open ? <DialogFrame {...frame} /> : null
|
||||
}
|
||||
|
||||
function DialogFrame({ onClose, labelledBy, width = 'detail', align = 'center', blocked = false, header, footer, onSubmit, children, bodyClassName, onPaste, discardGuard }: Omit<DialogShellProps, 'open'>) {
|
||||
function DialogFrame({ onClose, labelledBy, width = 'detail', fillHeight = false, align = 'center', blocked = false, covered = false, header, footer, onSubmit, children, bodyClassName, onPaste, discardGuard }: Omit<DialogShellProps, 'open'>) {
|
||||
const { t } = useTranslation()
|
||||
const panelRef = useRef<HTMLDivElement>(null)
|
||||
const pressedOn = useRef<EventTarget | null>(null)
|
||||
@@ -95,7 +99,7 @@ function DialogFrame({ onClose, labelledBy, width = 'detail', align = 'center',
|
||||
// The unsaved-changes question (#2253). The backdrop and Escape are the two
|
||||
// ways out a hand can take by accident; both go through requestClose.
|
||||
const { asking, markStart, requestClose, keepEditing, discard } = useDiscardGuard(discardGuard, onClose)
|
||||
const held = blocked || asking
|
||||
const held = blocked || covered || asking
|
||||
|
||||
useEffect(() => {
|
||||
if (held) return
|
||||
@@ -133,6 +137,8 @@ function DialogFrame({ onClose, labelledBy, width = 'detail', align = 'center',
|
||||
return createPortal(
|
||||
<div
|
||||
role="presentation"
|
||||
aria-hidden={covered || undefined}
|
||||
inert={covered || undefined}
|
||||
className={`${BACKDROP} ${align === 'top' ? 'items-start' : 'items-center'}`}
|
||||
style={{ paddingTop: 40, paddingBottom: 'calc(40px + var(--bottom-nav-h, 0px))' }}
|
||||
// Only a press that starts and ends on the backdrop closes: a selection
|
||||
@@ -157,7 +163,7 @@ function DialogFrame({ onClose, labelledBy, width = 'detail', align = 'center',
|
||||
}}
|
||||
onPointerDownCapture={markStart}
|
||||
onKeyDown={e => { if (panelRef.current) trapTab(e, panelRef.current) }}
|
||||
className={`trek-modal-enter relative flex max-h-full w-full ${PANEL_WIDTH[width]} flex-col overflow-hidden rounded-[22px] bg-surface-card shadow-2xl outline-none`}
|
||||
className={`trek-modal-enter relative flex max-h-full w-full ${PANEL_WIDTH[width]} flex-col overflow-hidden rounded-[22px] bg-surface-card shadow-2xl outline-none${fillHeight ? ' h-full' : ''}`}
|
||||
>
|
||||
{header}
|
||||
{body}
|
||||
|
||||
Reference in New Issue
Block a user