feat(journey): narrow an open photo album to a date range (#2859)

A shared Immich or Synology album can hold hundreds of photos from other
trips. Once an album is open the picker now offers a from/to range that
filters the already loaded assets by the day the grid files them under, so
Select all only takes the photos in range. No server change.
This commit is contained in:
Maurice
2026-11-13 09:17:23 +01:00
parent 11e4fe6ae3
commit 1f710bd217
32 changed files with 177 additions and 4 deletions
@@ -1,4 +1,4 @@
// FE-JRN-PICKER-001 to FE-JRN-PICKER-039
// FE-JRN-PICKER-001 to FE-JRN-PICKER-040
import { describe, it, expect, afterAll, afterEach, beforeAll, beforeEach, vi } from 'vitest'
import { http, HttpResponse, delay } from 'msw'
@@ -155,6 +155,48 @@ describe('ProviderPicker', () => {
expect(thumb.getAttribute('src')).toContain('passphrase=pw%201')
})
it('FE-JRN-PICKER-040: an open album can be narrowed to a date range, and Select all only takes what is shown (#2859)', async () => {
// The calendar opens on the current month, so the album's photos are dated
// in it: a fixed month would need paging the calendar there first.
const now = new Date()
const month = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}`
server.use(
http.get('/api/integrations/memories/immich/albums', () => HttpResponse.json({
albums: [{ id: 'alb1', albumName: 'Shared', assetCount: 3 }],
})),
http.get('/api/integrations/memories/immich/albums/alb1/photos', () => HttpResponse.json({
assets: [
asset('early', { localTakenAt: `${month}-02T10:00:00.000Z` }),
asset('inside', { localTakenAt: `${month}-05T10:00:00.000Z` }),
asset('late', { localTakenAt: `${month}-20T10:00:00.000Z` }),
],
})),
)
const user = userEvent.setup()
mountPicker()
await screen.findByText('March 15, 2026')
await user.click(screen.getByRole('button', { name: 'Albums' }))
// Nothing to narrow until an album is open.
expect(screen.queryByRole('group', { name: 'Taken between' })).toBeNull()
await user.click(await screen.findByRole('button', { name: 'Shared (3)' }))
expect(await screen.findByRole('button', { name: /Select all \(3\)/ })).toBeInTheDocument()
const range = screen.getByRole('group', { name: 'Taken between' })
const [fromTrigger, toTrigger] = within(range).getAllByRole('button')
await user.click(fromTrigger)
await user.click(screen.getByRole('button', { name: '3' }))
await user.click(toTrigger)
await user.click(screen.getByRole('button', { name: '9' }))
// Narrowed on the client: the album is not asked for again.
await user.click(await screen.findByRole('button', { name: /Select all \(1\)/ }))
expect(screen.getByRole('button', { name: 'Add (1)' })).toBeEnabled()
await user.click(within(range).getByRole('button', { name: 'Clear' }))
expect(screen.getByRole('button', { name: /Select all \(3\)/ })).toBeInTheDocument()
})
it('FE-JRN-PICKER-008: selects and deselects every selectable asset at once', async () => {
searchReturns([asset('a1'), asset('a2'), asset('a3')])
const user = userEvent.setup()
@@ -1,4 +1,4 @@
import { Calendar, Camera, Check, ChevronRight, Images, Loader2, Play, X } from 'lucide-react';
import { ArrowRight, Calendar, Camera, Check, ChevronRight, Images, Loader2, Play, X } from 'lucide-react';
import { useEffect, useId, useMemo, useRef, useState } from 'react';
import { memoriesApi } from '../../api/client';
import { useTranslation } from '../../i18n';
@@ -6,6 +6,7 @@ import { useIsPhone } from '../../mobile/useIsPhone';
import { DialogButton, DialogFooter, DialogHeader, DialogShell, DialogTile, FooterSpacer, NEUTRAL_TINT } from '../shared/DialogShell';
import {
fetchRemainingProviderPages,
filterPhotosByDayRange,
groupPhotosByDate,
PROVIDER_SEARCH_LAST_PAGE,
PROVIDER_SEARCH_PAGE_SIZE,
@@ -83,6 +84,10 @@ export function ProviderPicker({
const [draining, setDraining] = useState(false);
const [customFrom, setCustomFrom] = useState('');
const [customTo, setCustomTo] = useState('');
// The days an opened album is narrowed to (#2859). Kept across albums: the
// range describes the trip being looked for, not the album it is looked in.
const [albumFrom, setAlbumFrom] = useState('');
const [albumTo, setAlbumTo] = useState('');
const [targetEntryId, setTargetEntryId] = useState<number | null>(initialEntryId ?? null);
const [addToOpen, setAddToOpen] = useState(false);
const [adding, setAdding] = useState(false);
@@ -204,9 +209,13 @@ export function ProviderPicker({
// sort would leave the grid frozen while the caption already says "near Rome".
// It also keeps the ranking global instead of per page, which a sort inside
// the appending search cannot do.
//
// An open album is narrowed to its date range first. Everything downstream,
// "Select all" included, then only ever sees the photos in that range.
const albumOpen = filter === 'album' && selectedAlbum !== null;
const sortedPhotos = useMemo(
() => sortProviderPhotos(photos, contextLocation),
[photos, contextLocation?.lat, contextLocation?.lng],
() => sortProviderPhotos(albumOpen ? filterPhotosByDayRange(photos, albumFrom, albumTo) : photos, contextLocation),
[photos, albumOpen, albumFrom, albumTo, contextLocation?.lat, contextLocation?.lng],
);
// Albums come back whole, so they never page.
@@ -481,6 +490,43 @@ export function ProviderPicker({
)}
</div>
)}
{/* An album can hold far more than one trip, so once one is open its
photos can be narrowed to the days that matter (#2859). Its own row
under the album chips, which already fill theirs. The label only
fits beside the two pickers from sm up; the group still names it. */}
{albumOpen && (
<div
role="group"
aria-label={t('journey.picker.takenBetween')}
className="mt-2 flex min-h-[36px] items-center gap-2"
>
<span className="hidden flex-shrink-0 text-[12px] text-zinc-500 sm:inline">
{t('journey.picker.takenBetween')}
</span>
<div className="min-w-0 flex-1">
<DatePicker value={albumFrom} onChange={setAlbumFrom} />
</div>
<ArrowRight size={12} className="flex-shrink-0 text-zinc-400" aria-hidden="true" />
<div className="min-w-0 flex-1">
<DatePicker value={albumTo} onChange={setAlbumTo} />
</div>
{(albumFrom || albumTo) && (
<button
type="button"
onClick={() => {
setAlbumFrom('');
setAlbumTo('');
}}
aria-label={t('common.clear')}
title={t('common.clear')}
className="flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-lg text-zinc-400 hover:bg-zinc-100 dark:hover:bg-zinc-800"
>
<X size={14} />
</button>
)}
</div>
)}
</div>
{/* Add-to entry selector */}