mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 17:03:15 +00:00
feat(studio): add photos from Immich and Synology like the journey gallery (#2271)
This commit is contained in:
@@ -4,12 +4,13 @@ import { normalizeImageFiles } from '../../utils/convertHeic'
|
||||
import { isVideoFile } from '../../utils/videoPoster'
|
||||
import { useJourneyStore } from '../../store/journeyStore'
|
||||
import { useTranslation } from '../../i18n'
|
||||
import { journeyApi, addonsApi, memoriesApi } from '../../api/client'
|
||||
import { journeyApi } from '../../api/client'
|
||||
import { useToast } from '../shared/Toast'
|
||||
import { getApiErrorMessage } from '../../types'
|
||||
import type { JourneyEntry, GalleryPhoto, JourneyTrip } from '../../store/journeyStore'
|
||||
import { photoUrl, posterlessVideo } from '../../pages/journeyDetail/JourneyDetailPage.helpers'
|
||||
import { ProviderPicker, type ProviderPhotoGroup } from './JourneyDetailPageProviderPicker'
|
||||
import { useConnectedPhotoProviders } from './useConnectedPhotoProviders'
|
||||
import { ScrollTrigger } from './JourneyDetailPageScrollTrigger'
|
||||
import EmptyState from '../shared/EmptyState'
|
||||
|
||||
@@ -22,7 +23,7 @@ export function GalleryView({ entries, gallery, journeyId, userId, trips, onPhot
|
||||
onPhotoClick: (photos: GalleryPhoto[], index: number) => void
|
||||
onRefresh: () => void
|
||||
/** What the picker's Add does: the host's useProviderPhotoAdds, shared with the phone screen. */
|
||||
onAddProviderPhotos: (journeyId: number, provider: string, groups: ProviderPhotoGroup[], entryId: number | null) => Promise<void>
|
||||
onAddProviderPhotos: (journeyId: number, provider: string, groups: ProviderPhotoGroup[], entryId: number | null) => Promise<unknown>
|
||||
onRegisterUpload?: (fn: () => void) => void
|
||||
onRegisterProviders?: (providers: { id: string; name: string }[], browse: (provider: string) => void) => void
|
||||
}) {
|
||||
@@ -33,26 +34,13 @@ export function GalleryView({ entries, gallery, journeyId, userId, trips, onPhot
|
||||
const galleryUploading = galleryProgress !== null
|
||||
const toast = useToast()
|
||||
|
||||
// check which providers are enabled AND connected for the current user, then
|
||||
// hand them up: the page header renders the provider buttons next to Upload
|
||||
// The providers enabled AND connected for the current user, handed up: the page
|
||||
// header renders the provider buttons next to Upload.
|
||||
const connectedProviders = useConnectedPhotoProviders()
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
try {
|
||||
const addonsData = await addonsApi.enabled()
|
||||
const enabledProviders = (addonsData.addons || []).filter(
|
||||
(a: any) => a.type === 'photo_provider' && a.enabled
|
||||
)
|
||||
const connected: { id: string; name: string }[] = []
|
||||
for (const p of enabledProviders) {
|
||||
try {
|
||||
const status = await memoriesApi.status(p.id)
|
||||
if (status.connected) connected.push({ id: p.id, name: p.name })
|
||||
} catch { }
|
||||
}
|
||||
onRegisterProviders?.(connected, browseProvider)
|
||||
} catch { }
|
||||
})()
|
||||
}, [])
|
||||
onRegisterProviders?.(connectedProviders, browseProvider)
|
||||
// browseProvider only sets state; registering on the list alone is the old behaviour.
|
||||
}, [connectedProviders])
|
||||
|
||||
const allPhotos = gallery
|
||||
// A long trip's gallery is hundreds of tiles, and rendering them all at once is
|
||||
@@ -174,7 +162,7 @@ export function GalleryView({ entries, gallery, journeyId, userId, trips, onPhot
|
||||
)}
|
||||
{/* Delete button */}
|
||||
<button type="button"
|
||||
onClick={(e) => { e.stopPropagation(); handleDeletePhoto(photo.id) }}
|
||||
onClick={(e) => { e.stopPropagation(); void handleDeletePhoto(photo.id) }}
|
||||
className="absolute top-1.5 right-1.5 w-6 h-6 rounded-full bg-black/60 backdrop-blur text-white flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity z-10"
|
||||
>
|
||||
<X size={12} />
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
// FE-JRN-PROVIDERS-001
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { http, HttpResponse } from 'msw'
|
||||
import { renderHook, waitFor } from '@testing-library/react'
|
||||
import { server } from '../../../tests/helpers/msw/server'
|
||||
import { useConnectedPhotoProviders } from './useConnectedPhotoProviders'
|
||||
|
||||
describe('useConnectedPhotoProviders (#2271)', () => {
|
||||
it('FE-JRN-PROVIDERS-001: keeps enabled providers that report connected, drops the rest', async () => {
|
||||
server.use(
|
||||
http.get('/api/addons', () => HttpResponse.json({ addons: [
|
||||
{ id: 'immich', name: 'Immich', type: 'photo_provider', enabled: true },
|
||||
{ id: 'synology', name: 'Synology Photos', type: 'photo_provider', enabled: true },
|
||||
{ id: 'broken', name: 'Broken', type: 'photo_provider', enabled: true },
|
||||
{ id: 'vacay', name: 'Vacay', type: 'trip', enabled: true },
|
||||
] })),
|
||||
http.get('/api/integrations/memories/immich/status', () => HttpResponse.json({ connected: true })),
|
||||
http.get('/api/integrations/memories/synology/status', () => HttpResponse.json({ connected: false })),
|
||||
http.get('/api/integrations/memories/broken/status', () => HttpResponse.json({}, { status: 500 })),
|
||||
)
|
||||
const { result } = renderHook(() => useConnectedPhotoProviders())
|
||||
await waitFor(() => expect(result.current).toEqual([{ id: 'immich', name: 'Immich' }]))
|
||||
})
|
||||
|
||||
it('FE-JRN-PROVIDERS-002: asks nothing while switched off', () => {
|
||||
const { result } = renderHook(() => useConnectedPhotoProviders(false))
|
||||
expect(result.current).toEqual([])
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,36 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { addonsApi, memoriesApi } from '../../api/client'
|
||||
|
||||
export interface ConnectedPhotoProvider { id: string; name: string }
|
||||
|
||||
/**
|
||||
* The photo providers (Immich, Synology Photos) that are switched on for the
|
||||
* instance AND connected for this user, for every place that offers to pick
|
||||
* from them: the journey gallery and Studio (#2271). A provider whose status
|
||||
* cannot be read is left out rather than offered and then failing.
|
||||
*/
|
||||
export function useConnectedPhotoProviders(enabled = true): ConnectedPhotoProvider[] {
|
||||
const [providers, setProviders] = useState<ConnectedPhotoProvider[]>([])
|
||||
useEffect(() => {
|
||||
if (!enabled) return
|
||||
let cancelled = false
|
||||
void (async () => {
|
||||
try {
|
||||
const addonsData = await addonsApi.enabled()
|
||||
const enabledProviders = (addonsData.addons || []).filter(
|
||||
(a: { type?: string; enabled?: boolean }) => a.type === 'photo_provider' && a.enabled,
|
||||
) as { id: string; name: string }[]
|
||||
const connected: ConnectedPhotoProvider[] = []
|
||||
for (const p of enabledProviders) {
|
||||
try {
|
||||
const status = await memoriesApi.status(p.id)
|
||||
if (status.connected) connected.push({ id: p.id, name: p.name })
|
||||
} catch { /* not reachable for this user: not offered */ }
|
||||
}
|
||||
if (!cancelled) setProviders(connected)
|
||||
} catch { /* no addon list: nothing to offer */ }
|
||||
})()
|
||||
return () => { cancelled = true }
|
||||
}, [enabled])
|
||||
return providers
|
||||
}
|
||||
@@ -9,6 +9,8 @@ import { useJourneyStudio } from '../../pages/journeyStudio/useJourneyStudio'
|
||||
import { PAGE_PRESET_ORDER, PAGE_PRESETS } from './pagePresets'
|
||||
import { foliosOf } from './bookSheets'
|
||||
import { StudioSidebar } from './StudioSidebar'
|
||||
import { ProviderPicker } from '../Journey/JourneyDetailPageProviderPicker'
|
||||
import { useAuthStore } from '../../store/authStore'
|
||||
import { StudioCanvas } from './StudioCanvas'
|
||||
import { StudioInspector } from './StudioInspector'
|
||||
import { StudioWordmark } from './StudioWordmark'
|
||||
@@ -82,6 +84,19 @@ export default function StudioShell() {
|
||||
aria-label={s.t('journey.studio.title')}
|
||||
>
|
||||
<StudioBar s={s} bookView={bookView} setBookView={setBookView} onExport={() => setExporting(true)} />
|
||||
{/* The journey gallery's picker, inside Studio's own layer (#2271). */}
|
||||
{s.providerPick && s.journey && (
|
||||
<ProviderPicker
|
||||
provider={s.providerPick.provider}
|
||||
userId={useAuthStore.getState().user?.id || 0}
|
||||
entries={s.journey.entries.filter(e => e.type !== 'skeleton' || e.title)}
|
||||
trips={s.journey.trips}
|
||||
existingAssetIds={new Set((s.journey.gallery ?? []).filter(p => p.asset_id).map(p => p.asset_id!))}
|
||||
initialEntryId={s.providerPick.entryId}
|
||||
onClose={s.closeProviderPick}
|
||||
onAdd={s.addFromProvider}
|
||||
/>
|
||||
)}
|
||||
|
||||
<div className="st-body">
|
||||
<StudioSidebar
|
||||
@@ -96,6 +111,8 @@ export default function StudioShell() {
|
||||
canEdit={s.canEdit}
|
||||
onUpload={s.uploadPhotos}
|
||||
onToggleStop={s.setStopExcluded}
|
||||
providers={s.photoProviders}
|
||||
onBrowseProvider={s.browseProvider}
|
||||
/>
|
||||
<Workbench s={s} bookView={bookView} />
|
||||
<StudioInspector
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useEffect, useMemo, useRef, useState } from 'react'
|
||||
import {
|
||||
Camera, Check, ChevronDown, ChevronUp, Compass, Copy, FileDown, Files, ImageIcon, LayoutTemplate,
|
||||
Camera, Check, ChevronDown, ImagePlus, ChevronUp, Compass, Copy, FileDown, Files, ImageIcon, LayoutTemplate,
|
||||
Plus, Search, Shapes, Trash2, Upload, X,
|
||||
} from 'lucide-react'
|
||||
import type { BookElement, BookPageSetup, JourneyStats } from '@trek/shared'
|
||||
@@ -86,7 +86,7 @@ const THUMB_CHROME = (2 + 3) * 2
|
||||
|
||||
export function StudioSidebar({
|
||||
page, pxPerMm, bookView, source, stats, path, t, locale,
|
||||
canEdit, onUpload, onToggleStop,
|
||||
canEdit, onUpload, onToggleStop, providers = [], onBrowseProvider,
|
||||
}: {
|
||||
page: BookPageSetup
|
||||
pxPerMm: number
|
||||
@@ -104,6 +104,10 @@ export function StudioSidebar({
|
||||
onUpload: StudioUploader
|
||||
/** Switch a stop on or off in the figures. Resolves false when it did not land. */
|
||||
onToggleStop: (entryId: number, excluded: boolean) => Promise<boolean>
|
||||
/** Photo providers connected for this user, each a way in next to the upload (#2271). */
|
||||
providers?: { id: string; name: string }[]
|
||||
/** Opens the provider picker; answers the photo ids that landed, none when closed. */
|
||||
onBrowseProvider?: (provider: string, entryId: number | null) => Promise<number[]>
|
||||
}) {
|
||||
const [section, setSection] = useState<Section>('pages')
|
||||
|
||||
@@ -135,7 +139,8 @@ export function StudioSidebar({
|
||||
<aside className="st-panel st-side">
|
||||
{section === 'pages' && <PagesPanel page={page} pxPerMm={pxPerMm} bookView={bookView} t={t} />}
|
||||
{section === 'content' && (
|
||||
<ContentPanel source={source} page={page} t={t} locale={locale} canEdit={canEdit} onUpload={onUpload} />
|
||||
<ContentPanel source={source} page={page} t={t} locale={locale} canEdit={canEdit} onUpload={onUpload}
|
||||
providers={providers} onBrowseProvider={onBrowseProvider} />
|
||||
)}
|
||||
{section === 'elements' && <StudioElementsPanel page={page} t={t} />}
|
||||
{section === 'travel' && (
|
||||
@@ -337,7 +342,7 @@ function PagesPanel({
|
||||
* sees it the moment the panel does.
|
||||
*/
|
||||
function ContentPanel({
|
||||
source, page, t, locale, canEdit, onUpload,
|
||||
source, page, t, locale, canEdit, onUpload, providers = [], onBrowseProvider,
|
||||
}: {
|
||||
source: JourneySource
|
||||
page: BookPageSetup
|
||||
@@ -345,6 +350,8 @@ function ContentPanel({
|
||||
locale: string
|
||||
canEdit: boolean
|
||||
onUpload: StudioUploader
|
||||
providers?: { id: string; name: string }[]
|
||||
onBrowseProvider?: (provider: string, entryId: number | null) => Promise<number[]>
|
||||
}) {
|
||||
const [tab, setTab] = useState<'photos' | 'text'>('photos')
|
||||
const [query, setQuery] = useState('')
|
||||
@@ -394,6 +401,19 @@ function ContentPanel({
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* From a photo provider (#2271): into the same place an upload goes, and the
|
||||
* new pictures shown the same way, under their own filter.
|
||||
*/
|
||||
const pickFromProvider = async (provider: string) => {
|
||||
if (!onBrowseProvider) return
|
||||
const photoIds = await onBrowseProvider(provider, filter.kind === 'entry' ? filter.id : null)
|
||||
if (photoIds.length) {
|
||||
setFilter({ kind: 'recent', photoIds })
|
||||
setQuery('')
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The whole scrolling area takes a drop, not just the dashed cell: a drag
|
||||
* from the desktop arrives with the pointer wherever it arrives, and a target
|
||||
@@ -587,6 +607,18 @@ function ContentPanel({
|
||||
</span>
|
||||
</button>
|
||||
)}
|
||||
{canEdit && onBrowseProvider && providers.map(p => (
|
||||
<button type="button"
|
||||
key={p.id}
|
||||
className="st-photo-cell is-upload"
|
||||
onClick={() => { void pickFromProvider(p.id) }}
|
||||
disabled={!!upload}
|
||||
title={t('journey.studio.fromProviderHint', { name: p.name })}
|
||||
>
|
||||
<ImagePlus size={18} strokeWidth={1.6} />
|
||||
<span>{t('journey.studio.fromProvider', { name: p.name })}</span>
|
||||
</button>
|
||||
))}
|
||||
{photos.map(p => (
|
||||
<button type="button"
|
||||
key={p.photoId}
|
||||
|
||||
Reference in New Issue
Block a user