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 */}
@@ -5,6 +5,7 @@ import {
entryForPlace,
distanceBetweenGeoPoints,
fetchRemainingProviderPages,
filterPhotosByDayRange,
groupPhotosByDate,
matchJourneyEntries,
posterlessVideo,
@@ -390,3 +391,33 @@ describe('sortByCaptureTimeAsc (#1587)', () => {
expect(items.map((i) => i.id)).toEqual(['b', 'a']);
});
});
describe('filterPhotosByDayRange (#2859)', () => {
const photos = [
{ id: 'before', takenAt: '2026-03-09T12:00:00.000Z' },
{ id: 'first', takenAt: '2026-03-10T08:00:00.000Z' },
// Taken late on the 12th by the photographer's wall clock, already the 13th in UTC.
{ id: 'wallclock', takenAt: '2026-03-13T01:00:00.000Z', localTakenAt: '2026-03-12T21:00:00.000Z' },
{ id: 'after', takenAt: '2026-03-13T09:00:00.000Z' },
{ id: 'undated' },
];
const ids = (list: { id: string }[]) => list.map((p) => p.id);
it('keeps the days between both ends, both included, by the day the grid files them under', () => {
expect(ids(filterPhotosByDayRange(photos, '2026-03-10', '2026-03-12'))).toEqual(['first', 'wallclock']);
});
it('reads an empty end as open', () => {
expect(ids(filterPhotosByDayRange(photos, '2026-03-12', ''))).toEqual(['wallclock', 'after']);
expect(ids(filterPhotosByDayRange(photos, '', '2026-03-09'))).toEqual(['before']);
});
it('reads ends given the wrong way round as the range they mean', () => {
expect(ids(filterPhotosByDayRange(photos, '2026-03-12', '2026-03-10'))).toEqual(['first', 'wallclock']);
});
it('is no filter at all without a range, and drops undated photos once there is one', () => {
expect(filterPhotosByDayRange(photos, '', '')).toBe(photos);
expect(ids(filterPhotosByDayRange(photos, '2000-01-01', '2100-01-01'))).not.toContain('undated');
});
});
@@ -126,6 +126,32 @@ export function photoLocalDay(asset: { takenAt?: string | null; localTakenAt?: s
return Number.isNaN(parsed.getTime()) ? taken.slice(0, 10) : localIsoDate(parsed);
}
/**
* The photos taken between two calendar days, both ends included.
*
* An album comes back from the provider whole, and a shared one can hold years
* of somebody else's photos, so the picker narrows what it already has rather
* than asking again (#2859). The day is the one the grid files a photo under,
* so a photo never shows under a heading the range excludes. Either end may be
* empty for an open range; with both empty the list comes back untouched, same
* reference. A photo with no readable date has nothing to compare and is left
* out once a range is set. Ends given the wrong way round are read as the
* range they obviously mean.
*/
export function filterPhotosByDayRange<T extends { takenAt?: string | null; localTakenAt?: string | null }>(
photos: T[],
from: string,
to: string,
): T[] {
if (!from && !to) return photos;
const [start, end] = from && to && from > to ? [to, from] : [from, to];
return photos.filter((photo) => {
const day = photoLocalDay(photo);
if (day === '__unknown__') return false;
return (!start || day >= start) && (!end || day <= end);
});
}
/**
* The reader's own UTC offset where a given calendar day starts, in minutes east
* of UTC.
+1
View File
@@ -71,6 +71,7 @@ const journey: TranslationStrings = {
'journey.picker.noAlbums': 'لم يتم العثور على ألبومات',
'journey.picker.selectDate': 'اختر تاريخ',
'journey.picker.search': 'بحث',
'journey.picker.takenBetween': 'التُقطت بين',
'journey.title': 'يوميات',
'journey.subtitle': 'وثّق رحلاتك أولًا بأول',
'journey.new': 'يوميات جديدة',
+1
View File
@@ -307,6 +307,7 @@ const journey: TranslationStrings = {
'journey.picker.noAlbums': 'Heç bir albom tapılmadı',
'journey.picker.selectDate': 'Tarix seç',
'journey.picker.search': 'Axtar',
'journey.picker.takenBetween': 'Çəkilmə tarixi aralığı',
'journey.studio.title': 'TREK Studio', // same-as-en
'journey.studio.open': 'Studio', // same-as-en
+1
View File
@@ -267,6 +267,7 @@ const journey: TranslationStrings = {
'journey.picker.noAlbums': 'Nenhum álbum encontrado',
'journey.picker.selectDate': 'Selecionar data',
'journey.picker.search': 'Pesquisar',
'journey.picker.takenBetween': 'Tennet etre',
'journey.detail.journeyTab': 'Jornada',
'journey.contributors.remove': 'Remover colaborador',
'journey.contributors.removeConfirm': 'Remover {username} desta jornada?',
+1
View File
@@ -266,6 +266,7 @@ const journey: TranslationStrings = {
'journey.picker.noAlbums': "No s'han trobat àlbums",
'journey.picker.selectDate': 'Selecciona una data',
'journey.picker.search': 'Cerca',
'journey.picker.takenBetween': 'Fetes entre',
'journey.detail.journeyTab': 'Travesia',
'journey.contributors.remove': 'Elimina el col·laborador',
'journey.contributors.removeConfirm': "Vols eliminar {username} d'aquesta travesia?",
+1
View File
@@ -271,6 +271,7 @@ const journey: TranslationStrings = {
'journey.picker.noAlbums': 'Žádná alba nenalezena',
'journey.picker.selectDate': 'Vyberte datum',
'journey.picker.search': 'Hledat',
'journey.picker.takenBetween': 'Pořízeno mezi',
'journey.detail.journeyTab': 'Cestovní deník',
'journey.contributors.remove': 'Odebrat přispěvatele',
'journey.contributors.removeConfirm': 'Odebrat uživatele {username} z tohoto deníku?',
+1
View File
@@ -275,6 +275,7 @@ const journey: TranslationStrings = {
'journey.picker.noAlbums': 'Keine Alben gefunden',
'journey.picker.selectDate': 'Datum wählen',
'journey.picker.search': 'Suchen',
'journey.picker.takenBetween': 'Aufgenommen zwischen',
'journey.detail.journeyTab': 'Journey',
'journey.editor.externalPhotos': 'Externe Fotos',
'journey.editor.externalPhotosFor': 'Fotos vom {date}',
+1
View File
@@ -282,6 +282,7 @@ const journey: TranslationStrings = {
'journey.picker.noAlbums': 'No albums found',
'journey.picker.selectDate': 'Select date',
'journey.picker.search': 'Search',
'journey.picker.takenBetween': 'Taken between',
'journey.studio.title': 'TREK Studio',
'journey.studio.open': 'Studio',
'journey.studio.openAria': 'Open the photo book studio',
+1
View File
@@ -267,6 +267,7 @@ const journey: TranslationStrings = {
'journey.picker.noAlbums': 'No se encontraron álbumes',
'journey.picker.selectDate': 'Seleccionar fecha',
'journey.picker.search': 'Buscar',
'journey.picker.takenBetween': 'Tomadas entre',
'journey.detail.journeyTab': 'Travesía',
'journey.contributors.remove': 'Quitar colaborador',
'journey.contributors.removeConfirm': '¿Quitar a {username} de esta travesía?',
+1
View File
@@ -284,6 +284,7 @@ const journey: TranslationStrings = {
'journey.picker.noAlbums': 'Albumeid ei leitud',
'journey.picker.selectDate': 'Vali kuupäev',
'journey.picker.search': 'Otsi',
'journey.picker.takenBetween': 'Tehtud vahemikus',
'journey.studio.title': 'TREK Studio', // same-as-en
'journey.studio.open': 'Stuudio',
'journey.studio.openAria': 'Ava fotoraamatu stuudio',
+1
View File
@@ -266,6 +266,7 @@ const journey: TranslationStrings = {
'journey.picker.noAlbums': 'Aucun album trouvé',
'journey.picker.selectDate': 'Sélectionner une date',
'journey.picker.search': 'Rechercher',
'journey.picker.takenBetween': 'Prises entre',
'journey.detail.journeyTab': 'Journal de voyage',
'journey.contributors.remove': 'Retirer le contributeur',
'journey.contributors.removeConfirm': 'Retirer {username} de ce journal de voyage ?',
+1
View File
@@ -278,6 +278,7 @@ const journey: TranslationStrings = {
'journey.picker.noAlbums': 'Δεν βρέθηκαν άλμπουμ',
'journey.picker.selectDate': 'Επιλογή ημερομηνίας',
'journey.picker.search': 'Αναζήτηση',
'journey.picker.takenBetween': 'Τραβήχτηκαν μεταξύ',
'journey.editor.externalPhotos': 'Εξωτερικές φωτογραφίες',
'journey.editor.externalPhotosFor': 'Φωτογραφίες για {date}',
'journey.editor.externalPhotosNearby': 'Πρώτα οι κοντινές φωτογραφίες',
+1
View File
@@ -285,6 +285,7 @@ const journey: TranslationStrings = {
'journey.picker.noAlbums': 'לא נמצאו אלבומים',
'journey.picker.selectDate': 'בחירת תאריך',
'journey.picker.search': 'חיפוש',
'journey.picker.takenBetween': 'צולמו בין',
'journey.studio.title': 'TREK Studio',
'journey.studio.open': 'סטודיו',
'journey.studio.openAria': 'פתיחת סטודיו אלבום התמונות',
+1
View File
@@ -266,6 +266,7 @@ const journey: TranslationStrings = {
'journey.picker.noAlbums': 'Nem található album',
'journey.picker.selectDate': 'Dátum választása',
'journey.picker.search': 'Keresés',
'journey.picker.takenBetween': 'Készítés időszaka',
'journey.detail.journeyTab': 'Útinapló',
'journey.contributors.remove': 'Közreműködő eltávolítása',
'journey.contributors.removeConfirm': 'Eltávolítod {username} felhasználót ebből az útinaplóból?',
+1
View File
@@ -259,6 +259,7 @@ const journey: TranslationStrings = {
'journey.picker.noAlbums': 'Tidak ada album ditemukan',
'journey.picker.selectDate': 'Pilih tanggal',
'journey.picker.search': 'Cari',
'journey.picker.takenBetween': 'Diambil antara',
'journey.detail.journeyTab': 'Jurnal',
'journey.contributors.remove': 'Hapus kontributor',
'journey.contributors.removeConfirm': 'Hapus {username} dari jurnal perjalanan ini?',
+1
View File
@@ -266,6 +266,7 @@ const journey: TranslationStrings = {
'journey.picker.noAlbums': 'Nessun album trovato',
'journey.picker.selectDate': 'Seleziona data',
'journey.picker.search': 'Cerca',
'journey.picker.takenBetween': 'Scattate tra',
'journey.detail.journeyTab': 'Diario',
'journey.contributors.remove': 'Rimuovi contributore',
'journey.contributors.removeConfirm': 'Rimuovere {username} da questo diario?',
+1
View File
@@ -261,6 +261,7 @@ const journey: TranslationStrings = {
'journey.picker.noAlbums': 'アルバムがありません',
'journey.picker.selectDate': '日付を選択',
'journey.picker.search': '検索',
'journey.picker.takenBetween': '撮影期間',
'journey.editor.uploadingProgress': 'アップロード中 {done}/{total}…',
'journey.editor.uploadFailed': '写真のアップロードに失敗しました',
'journey.editor.uploadPartialFailed':
+1
View File
@@ -259,6 +259,7 @@ const journey: TranslationStrings = {
'journey.picker.noAlbums': '앨범을 찾을 수 없습니다',
'journey.picker.selectDate': '날짜 선택',
'journey.picker.search': '검색',
'journey.picker.takenBetween': '촬영 기간',
'journey.editor.uploadingProgress': '업로드 중 {done}/{total}…',
'journey.editor.uploadFailed': '사진 업로드 실패',
'journey.editor.uploadPartialFailed':
+1
View File
@@ -267,6 +267,7 @@ const journey: TranslationStrings = {
'journey.picker.noAlbums': 'Geen albums gevonden',
'journey.picker.selectDate': 'Selecteer datum',
'journey.picker.search': 'Zoeken',
'journey.picker.takenBetween': 'Gemaakt tussen',
'journey.detail.journeyTab': 'Reisverslag',
'journey.contributors.remove': 'Bijdrager verwijderen',
'journey.contributors.removeConfirm': '{username} uit dit reisverslag verwijderen?',
+1
View File
@@ -279,6 +279,7 @@ const journey: TranslationStrings = {
'journey.picker.noAlbums': 'Nie znaleziono albumów',
'journey.picker.selectDate': 'Wybierz datę',
'journey.picker.search': 'Szukaj',
'journey.picker.takenBetween': 'Zrobione między',
'journey.detail.journeyTab': 'Podróż',
'journey.contributors.remove': 'Usuń współautora',
'journey.contributors.removeConfirm': 'Usunąć {username} z tej podróży?',
+1
View File
@@ -279,6 +279,7 @@ const journey: TranslationStrings = {
'journey.picker.noAlbums': 'Альбомы не найдены',
'journey.picker.selectDate': 'Выберите дату',
'journey.picker.search': 'Поиск',
'journey.picker.takenBetween': 'Сняты между',
'journey.detail.journeyTab': 'Путешествие',
'journey.contributors.remove': 'Удалить участника',
'journey.contributors.removeConfirm': 'Удалить {username} из этого путешествия?',
+1
View File
@@ -289,6 +289,7 @@ const journey: TranslationStrings = {
'journey.picker.noAlbums': 'Nenašli sa žiadne albumy',
'journey.picker.selectDate': 'Vyberte dátum',
'journey.picker.search': 'Hľadať',
'journey.picker.takenBetween': 'Odfotené medzi',
'journey.studio.title': 'TREK Studio', // same-as-en
'journey.studio.open': 'Studio', // same-as-en
'journey.studio.openAria': 'Otvoriť štúdio fotoknihy',
+1
View File
@@ -275,6 +275,7 @@ const journey: TranslationStrings = {
'journey.picker.noAlbums': 'Inga album hittades',
'journey.picker.selectDate': 'Välj datum',
'journey.picker.search': 'Sök',
'journey.picker.takenBetween': 'Tagna mellan',
'journey.editor.externalPhotos': 'Externa foton',
'journey.editor.externalPhotosFor': 'Foton för {date}',
'journey.editor.externalPhotosNearby': 'Foton i närheten först',
+1
View File
@@ -272,6 +272,7 @@ const journey: TranslationStrings = {
'journey.picker.noAlbums': 'ไม่พบอัลบั้ม',
'journey.picker.selectDate': 'เลือกวันที่',
'journey.picker.search': 'ค้นหา',
'journey.picker.takenBetween': 'ถ่ายระหว่าง',
'journey.studio.title': 'เทรค สตูดิโอ',
'journey.studio.open': 'สตูดิโอ',
'journey.studio.openAria': 'เปิดสตูดิโอสมุดภาพ',
+1
View File
@@ -269,6 +269,7 @@ const journey: TranslationStrings = {
'journey.picker.noAlbums': 'Albüm bulunamadı',
'journey.picker.selectDate': 'Tarih seç',
'journey.picker.search': 'Ara',
'journey.picker.takenBetween': 'Çekim tarihi aralığı',
'journey.editor.uploadingProgress': '{done}/{total} yükleniyor…',
'journey.editor.uploadFailed': 'Fotoğraf yüklenemedi',
'journey.editor.uploadPartialFailed': '{total} fotoğraftan {failed} tanesi başarısız — tekrar denemek için kaydedin',
+1
View File
@@ -284,6 +284,7 @@ const journey: TranslationStrings = {
'journey.picker.noAlbums': 'Альбомів не знайдено',
'journey.picker.selectDate': 'Оберіть дату',
'journey.picker.search': 'Пошук',
'journey.picker.takenBetween': 'Зроблені між',
'journey.editor.uploadingProgress': 'Завантаження {done}/{total}…',
'journey.editor.uploadFailed': 'Не вдалося завантажити фото',
'journey.editor.uploadPartialFailed':
+1
View File
@@ -269,6 +269,7 @@ const journey: TranslationStrings = {
'journey.picker.noAlbums': 'Không tìm thấy album nào',
'journey.picker.selectDate': 'Chọn ngày',
'journey.picker.search': 'Tìm kiếm',
'journey.picker.takenBetween': 'Chụp trong khoảng',
'journey.editor.externalPhotos': 'Ảnh bên ngoài',
'journey.editor.externalPhotosFor': 'Ảnh cho {date}',
'journey.editor.externalPhotosNearby': 'Ảnh gần đó trước',
+1
View File
@@ -254,6 +254,7 @@ const journey: TranslationStrings = {
'journey.picker.noAlbums': '未找到相簿',
'journey.picker.selectDate': '選擇日期',
'journey.picker.search': '搜尋',
'journey.picker.takenBetween': '拍攝日期範圍',
'journey.detail.journeyTab': '旅程',
'journey.contributors.remove': '移除參與者',
'journey.contributors.removeConfirm': '要將 {username} 從此旅程中移除嗎?',
+1
View File
@@ -254,6 +254,7 @@ const journey: TranslationStrings = {
'journey.picker.noAlbums': '未找到相册',
'journey.picker.selectDate': '选择日期',
'journey.picker.search': '搜索',
'journey.picker.takenBetween': '拍摄日期范围',
'journey.detail.journeyTab': '旅程',
'journey.contributors.remove': '移除贡献者',
'journey.contributors.removeConfirm': '要将 {username} 从此旅程中移除吗?',