feat(signage): gallery widget (pictures and videos one after another, from a list or a media folder); media folders on the Media page
Folders are only a grouping in the database (media_folders, media.folder_id, Alembic 0046): made, renamed, deleted (files stay) on the Media page, a file filed from its details, uploads go into the folder shown, the picker filters by folder. The gallery widget: its own pictures/videos in order or a folder as it is now, seconds each, fade / slide / zoom, cover / contain. Plan 6R.16, F-114. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,11 +6,11 @@ import toast from 'react-hot-toast'
|
||||
import { Trash2 } from 'lucide-react'
|
||||
import { errorMessage } from '@xenia/api'
|
||||
import { useFormat, useTranslation } from '@xenia/i18n'
|
||||
import { Button, Dialog, Field, Input, Spinner, cx } from '@xenia/ui'
|
||||
import { deleteMedia, getMedia, renameMedia } from './mediaApi'
|
||||
import { Button, Dialog, Dropdown, Field, Input, Spinner, cx } from '@xenia/ui'
|
||||
import { deleteMedia, getMedia, renameMedia, setFolder } from './mediaApi'
|
||||
import { duration, fileSize, preparing, resolution, VARIANT_ORDER, videoState } from './mediaLogic'
|
||||
|
||||
export default function MediaDetails({ id, onClose, onChanged, onDeleted }) {
|
||||
export default function MediaDetails({ id, onClose, onChanged, onDeleted, folders = [] }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const { formatDateTime, formatNumber } = useFormat()
|
||||
const [item, setItem] = useState(null)
|
||||
@@ -43,6 +43,10 @@ export default function MediaDetails({ id, onClose, onChanged, onDeleted }) {
|
||||
catch (err) { toast.error(errorMessage(err, t)) }
|
||||
setBusy(false)
|
||||
}
|
||||
const fileIn = async folderId => {
|
||||
try { const m = await setFolder(id, folderId); setItem(it => ({ ...it, ...m })); onChanged?.(m); toast.success(t('media.folders.moved')) }
|
||||
catch (err) { toast.error(errorMessage(err, t)) }
|
||||
}
|
||||
const remove = async () => {
|
||||
setBusy(true)
|
||||
try { await deleteMedia(id); toast.success(t('media.deleted')); onDeleted?.(id); onClose() }
|
||||
@@ -93,6 +97,11 @@ export default function MediaDetails({ id, onClose, onChanged, onDeleted }) {
|
||||
<p className="text-caption text-ink-3">{t(item.builtin ? 'media.builtinHint' : 'media.displayNameHint')}</p>
|
||||
</div>
|
||||
|
||||
<Field label={t('media.folders.folder')} className="max-w-sm">
|
||||
<Dropdown value={item.folder_id ?? ''} onChange={v => fileIn(v === '' ? null : Number(v))} data-testid="media-folder-pick"
|
||||
options={[{ value: '', label: t('media.folders.none') }, ...folders.map(f => ({ value: f.id, label: f.name }))]} />
|
||||
</Field>
|
||||
|
||||
<dl className="grid gap-x-4 gap-y-1 text-label" style={{ gridTemplateColumns: 'max-content 1fr' }}>
|
||||
{rows.map(([k, v]) => <div key={k} className="contents"><dt className="text-ink-3">{k}</dt><dd className="text-ink break-all">{v}</dd></div>)}
|
||||
</dl>
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
// The media library's folders (6R.16, owner 2026-11-22): only a grouping in the database, the files
|
||||
// stay where they are. The bar picks what the page shows (everything, the files in no folder, a
|
||||
// folder) and where uploads go; a folder is made, renamed or deleted here (its files stay, in no folder).
|
||||
import { useState } from 'react'
|
||||
import toast from 'react-hot-toast'
|
||||
import { FolderPlus, Pencil, Trash2 } from 'lucide-react'
|
||||
import { errorMessage } from '@xenia/api'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { Button, Dialog, Field, FilterChip, IconButton, Input, useConfirm } from '@xenia/ui'
|
||||
import { createFolder, deleteFolder, renameFolder } from './mediaApi'
|
||||
|
||||
/** value: '' (all) | 'none' | a folder id as a string. */
|
||||
export default function MediaFolders({ folders, none, total, value, onChange, onChanged }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const [naming, setNaming] = useState(null) // { id?, name }
|
||||
const [confirm, confirmDialog] = useConfirm()
|
||||
const current = folders?.find(f => String(f.id) === value)
|
||||
const save = async () => {
|
||||
try {
|
||||
const f = naming.id ? await renameFolder(naming.id, naming.name.trim()) : await createFolder(naming.name.trim())
|
||||
setNaming(null)
|
||||
await onChanged?.()
|
||||
onChange(String(f.id))
|
||||
} catch (err) { toast.error(errorMessage(err, t)) }
|
||||
}
|
||||
const remove = async () => {
|
||||
if (!await confirm({ title: t('media.folders.deleteTitle', { name: current.name }), body: t('media.folders.deleteBody'), confirmLabel: t('media.delete'), tone: 'danger', testId: 'media-folder-delete-confirm' })) return
|
||||
try { await deleteFolder(current.id); onChange(''); await onChanged?.() } catch (err) { toast.error(errorMessage(err, t)) }
|
||||
}
|
||||
return (
|
||||
<div className="flex flex-wrap items-center gap-1.5" data-testid="media-folders" role="toolbar" aria-label={t('media.folders.title')}>
|
||||
<FilterChip pressed={value === ''} count={total} onClick={() => onChange('')} data-testid="media-folder-all">{t('media.folders.all')}</FilterChip>
|
||||
<FilterChip pressed={value === 'none'} count={none} onClick={() => onChange('none')} data-testid="media-folder-none">{t('media.folders.none')}</FilterChip>
|
||||
{(folders || []).map(f => (
|
||||
<FilterChip key={f.id} pressed={value === String(f.id)} count={f.count} onClick={() => onChange(String(f.id))} data-testid="media-folder" data-name={f.name}>{f.name}</FilterChip>
|
||||
))}
|
||||
<Button size="sm" variant="ghost" icon={<FolderPlus size={15} />} onClick={() => setNaming({ name: '' })} data-testid="media-folder-new">{t('media.folders.new')}</Button>
|
||||
{current && <>
|
||||
<IconButton size="sm" label={t('media.folders.rename')} onClick={() => setNaming({ id: current.id, name: current.name })} data-testid="media-folder-rename"><Pencil size={15} /></IconButton>
|
||||
<IconButton size="sm" tone="danger" label={t('media.folders.delete')} onClick={remove} data-testid="media-folder-delete"><Trash2 size={15} /></IconButton>
|
||||
</>}
|
||||
{naming && (
|
||||
<Dialog open size="sm" title={t(naming.id ? 'media.folders.rename' : 'media.folders.new')} onClose={() => setNaming(null)}
|
||||
footer={<>
|
||||
<Button variant="secondary" onClick={() => setNaming(null)}>{t('fees.cancel')}</Button>
|
||||
<Button disabled={!naming.name.trim()} onClick={save} data-testid="media-folder-save">{t('fees.save')}</Button>
|
||||
</>}>
|
||||
<Field label={t('media.folders.name')}>
|
||||
<Input value={naming.name} autoFocus maxLength={60} onChange={e => setNaming(n => ({ ...n, name: e.target.value }))}
|
||||
onKeyDown={e => { if (e.key === 'Enter' && naming.name.trim()) save() }} data-testid="media-folder-name" />
|
||||
</Field>
|
||||
</Dialog>
|
||||
)}
|
||||
{confirmDialog}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -2,13 +2,15 @@
|
||||
// library. Batch upload (pick many files or drop them on the page) to use later anywhere that
|
||||
// takes media (products, categories; the customer display and signage next). The backend names
|
||||
// and stores the files; here people see a display name, the details and the sizes made.
|
||||
// Backend: /api/media (routers/media.py).
|
||||
// Folders (6R.16): the bar under the toolbar picks a folder (uploads go into it); a file's folder is
|
||||
// changed in its details. Backend: /api/media (routers/media.py).
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||||
import { Upload } from 'lucide-react'
|
||||
import { errorMessage } from '@xenia/api'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { Button, EmptyState, Input, Page, Select, Spinner, cx } from '@xenia/ui'
|
||||
import { listMedia } from './mediaApi'
|
||||
import { listFolders, listMedia } from './mediaApi'
|
||||
import MediaFolders from './MediaFolders'
|
||||
import { ACCEPT, preparing } from './mediaLogic'
|
||||
import MediaDetails from './MediaDetails'
|
||||
import { MediaGrid, UploadQueue } from './MediaParts'
|
||||
@@ -24,13 +26,17 @@ export default function MediaPage() {
|
||||
const [error, setError] = useState(null)
|
||||
const [open, setOpen] = useState(null)
|
||||
const [dragging, setDragging] = useState(false)
|
||||
const [folder, setFolder] = useState('') // '' all | 'none' | a folder id
|
||||
const [folders, setFolders] = useState(null) // { folders, none }
|
||||
const loadFolders = useCallback(async () => { try { setFolders(await listFolders()) } catch { /* the bar waits */ } }, [])
|
||||
useEffect(() => { loadFolders() }, [loadFolders])
|
||||
const input = useRef(null)
|
||||
|
||||
useEffect(() => { const h = setTimeout(() => setSearch(q.trim()), 250); return () => clearTimeout(h) }, [q])
|
||||
|
||||
const load = useCallback(async () => {
|
||||
try { setPage(await listMedia({ kind, q: search, collection })); setError(null) } catch (err) { setError(errorMessage(err, t)) }
|
||||
}, [kind, search, collection, t])
|
||||
try { setPage(await listMedia({ kind, q: search, collection, folder })); setError(null) } catch (err) { setError(errorMessage(err, t)) }
|
||||
}, [kind, search, collection, folder, t])
|
||||
useEffect(() => { load() }, [load])
|
||||
// Videos are prepared for screens in the background (5.4e): read the list again while any is.
|
||||
const busy = preparing(page?.items)
|
||||
@@ -45,16 +51,18 @@ export default function MediaPage() {
|
||||
setPage(p => (p && !p.items.some(x => x.id === item.id) ? { ...p, items: [item, ...p.items], total: p.total + 1 } : p))
|
||||
}, []))
|
||||
const wasBusy = useRef(false)
|
||||
useEffect(() => { if (wasBusy.current && !summary.busy) load(); wasBusy.current = summary.busy }, [summary.busy, load])
|
||||
useEffect(() => { if (wasBusy.current && !summary.busy) { load(); loadFolders() } wasBusy.current = summary.busy }, [summary.busy, load, loadFolders])
|
||||
|
||||
const onDrop = e => {
|
||||
e.preventDefault(); setDragging(false)
|
||||
if (e.dataTransfer.files?.length) add(e.dataTransfer.files)
|
||||
if (e.dataTransfer.files?.length) add(e.dataTransfer.files, upTo)
|
||||
}
|
||||
const kinds = useMemo(() => [
|
||||
{ value: '', label: t('media.kinds.all') }, { value: 'image', label: t('media.kinds.images') }, { value: 'video', label: t('media.kinds.videos') },
|
||||
], [t])
|
||||
const closeDetails = useCallback(() => setOpen(null), [])
|
||||
const upTo = /^\d+$/.test(folder) ? Number(folder) : null // uploads go into the folder shown
|
||||
const allCount = folders ? folders.none + folders.folders.reduce((n, f) => n + f.count, 0) : undefined
|
||||
|
||||
return (
|
||||
<Page className={cx(dragging && 'outline-2 outline-dashed outline-accent -outline-offset-8')}
|
||||
@@ -70,7 +78,7 @@ export default function MediaPage() {
|
||||
<div className="flex flex-wrap gap-2 items-center">
|
||||
<Button icon={<Upload size={16} />} onClick={() => input.current?.click()} data-testid="media-upload">{t('media.upload')}</Button>
|
||||
<input ref={input} type="file" multiple accept={ACCEPT} className="sr-only" data-testid="media-file-input"
|
||||
onChange={e => { if (e.target.files?.length) add(e.target.files); e.target.value = '' }} />
|
||||
onChange={e => { if (e.target.files?.length) add(e.target.files, upTo); e.target.value = '' }} />
|
||||
<span className="text-label text-ink-3 hidden md:inline">{t('media.dropHint')}</span>
|
||||
<div className="flex gap-2 ml-auto w-full sm:w-auto">
|
||||
<Input value={q} onChange={e => setQ(e.target.value)} placeholder={t('media.search')} aria-label={t('media.search')}
|
||||
@@ -81,6 +89,8 @@ export default function MediaPage() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<MediaFolders folders={folders?.folders} none={folders?.none} total={allCount} value={folder} onChange={setFolder} onChanged={loadFolders} />
|
||||
|
||||
<UploadQueue queue={queue} summary={summary} onClear={clear} />
|
||||
|
||||
{error ? <EmptyState title={error} />
|
||||
@@ -92,8 +102,8 @@ export default function MediaPage() {
|
||||
{page.total > page.items.length && <p className="text-label text-ink-3">{t('media.more', { shown: page.items.length, total: page.total })}</p>}
|
||||
</>}
|
||||
|
||||
{open && <MediaDetails id={open} onClose={closeDetails}
|
||||
onChanged={m => setPage(p => p && { ...p, items: p.items.map(x => (x.id === m.id ? { ...x, ...m } : x)) })}
|
||||
{open && <MediaDetails id={open} onClose={closeDetails} folders={folders?.folders || []}
|
||||
onChanged={m => { setPage(p => p && { ...p, items: p.items.map(x => (x.id === m.id ? { ...x, ...m } : x)) }); loadFolders() }}
|
||||
onDeleted={id => setPage(p => p && { ...p, items: p.items.filter(x => x.id !== id), total: p.total - 1 })} />}
|
||||
</Page>
|
||||
)
|
||||
|
||||
@@ -6,7 +6,7 @@ import { Upload } from 'lucide-react'
|
||||
import { errorMessage } from '@xenia/api'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { Button, Dialog, EmptyState, Input, Select, Spinner } from '@xenia/ui'
|
||||
import { listMedia } from './mediaApi'
|
||||
import { listFolders, listMedia } from './mediaApi'
|
||||
import { ACCEPT } from './mediaLogic'
|
||||
import { MediaGrid, UploadQueue } from './MediaParts'
|
||||
import { useUploadQueue } from './mediaHooks'
|
||||
@@ -22,13 +22,16 @@ export default function MediaPicker({ open, onClose, onPick, onPickMany, multipl
|
||||
const [chosen, setChosen] = useState([]) // multiple: the items picked so far, in order
|
||||
const toggle = item => setChosen(c => (c.some(x => x.id === item.id) ? c.filter(x => x.id !== item.id) : [...c, item]))
|
||||
|
||||
const [folder, setFolder] = useState('') // 6R.16: '' all | 'none' | a folder id
|
||||
const [folders, setFolders] = useState([])
|
||||
useEffect(() => { if (open) listFolders().then(r => setFolders(r.folders)).catch(() => {}) }, [open])
|
||||
useEffect(() => { const h = setTimeout(() => setSearch(q.trim()), 250); return () => clearTimeout(h) }, [q])
|
||||
useEffect(() => {
|
||||
if (!open) return
|
||||
let live = true
|
||||
listMedia({ kind, q: search, collection }).then(p => { if (live) { setPage(p); setError(null) } }).catch(err => live && setError(errorMessage(err, t)))
|
||||
listMedia({ kind, q: search, collection, folder }).then(p => { if (live) { setPage(p); setError(null) } }).catch(err => live && setError(errorMessage(err, t)))
|
||||
return () => { live = false }
|
||||
}, [open, kind, search, collection, t])
|
||||
}, [open, kind, search, collection, folder, t])
|
||||
|
||||
const { queue, add, clear, summary } = useUploadQueue(useCallback(item => {
|
||||
setPage(p => (p && !p.items.some(x => x.id === item.id) ? { ...p, items: [item, ...p.items], total: p.total + 1 } : p))
|
||||
@@ -49,9 +52,13 @@ export default function MediaPicker({ open, onClose, onPick, onPickMany, multipl
|
||||
className="flex-1 min-w-[10rem]" data-testid="media-picker-search" />
|
||||
<Select value={collection} onChange={e => setCollection(e.target.value)} aria-label={t('media.collection')} data-testid="media-picker-collection"
|
||||
options={[{ value: '', label: t('media.collections.all') }, { value: 'own', label: t('media.collections.own') }, { value: 'builtin', label: t('media.collections.builtin') }]} />
|
||||
{folders.length > 0 && (
|
||||
<Select value={folder} onChange={e => setFolder(e.target.value)} aria-label={t('media.folders.folder')} data-testid="media-picker-folder"
|
||||
options={[{ value: '', label: t('media.folders.all') }, { value: 'none', label: t('media.folders.none') }, ...folders.map(f => ({ value: String(f.id), label: f.name }))]} />
|
||||
)}
|
||||
<Button variant="secondary" icon={<Upload size={16} />} onClick={() => input.current?.click()} disabled={summary.busy}>{t('media.uploadNew')}</Button>
|
||||
<input ref={input} type="file" accept={kind === 'image' ? ACCEPT.split(',').filter(a => a.startsWith('image/')).join(',') : ACCEPT}
|
||||
className="sr-only" data-testid="media-picker-file" multiple={multiple} onChange={e => { if (e.target.files?.length) add(multiple ? e.target.files : [e.target.files[0]]); e.target.value = '' }} />
|
||||
className="sr-only" data-testid="media-picker-file" multiple={multiple} onChange={e => { if (e.target.files?.length) add(multiple ? e.target.files : [e.target.files[0]], /^\d+$/.test(folder) ? Number(folder) : null); e.target.value = '' }} />
|
||||
</div>
|
||||
<UploadQueue queue={queue} summary={summary} onClear={clear} />
|
||||
{error ? <EmptyState title={error} />
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
// The media library's API (backend: local_backend/routers/media.py, plan steps 5.1 / 5.2).
|
||||
import client from '../../api/client'
|
||||
|
||||
export const listMedia = ({ kind, q, collection, limit = 500 } = {}) =>
|
||||
client.get('/api/media', { params: { kind: kind || undefined, q: q || undefined, collection: collection || undefined, limit } }).then(r => r.data)
|
||||
export const listMedia = ({ kind, q, collection, folder, limit = 500 } = {}) =>
|
||||
client.get('/api/media', { params: { kind: kind || undefined, q: q || undefined, collection: collection || undefined, folder: folder || undefined, limit } }).then(r => r.data)
|
||||
|
||||
export const getMedia = id => client.get(`/api/media/${id}`).then(r => r.data)
|
||||
|
||||
/** Upload one file → the library item (`existing: true` when the same file was already there). */
|
||||
export function uploadMedia(file, { name, onProgress } = {}) {
|
||||
export function uploadMedia(file, { name, folderId, onProgress } = {}) {
|
||||
const fd = new FormData()
|
||||
fd.append('file', file)
|
||||
if (name) fd.append('name', name)
|
||||
if (folderId) fd.append('folder_id', String(folderId))
|
||||
return client.post('/api/media', fd, {
|
||||
onUploadProgress: e => { if (onProgress && e.total) onProgress(Math.round((e.loaded / e.total) * 100)) },
|
||||
}).then(r => r.data)
|
||||
@@ -19,3 +20,11 @@ export function uploadMedia(file, { name, onProgress } = {}) {
|
||||
export const renameMedia = (id, name) => client.patch(`/api/media/${id}`, { name }).then(r => r.data)
|
||||
|
||||
export const deleteMedia = id => client.delete(`/api/media/${id}`)
|
||||
|
||||
// folders (6R.16): only a grouping in the database; the files stay where they are
|
||||
export const listFolders = () => client.get('/api/media/folders').then(r => r.data)
|
||||
export const createFolder = name => client.post('/api/media/folders', { name }).then(r => r.data)
|
||||
export const renameFolder = (id, name) => client.patch(`/api/media/folders/${id}`, { name }).then(r => r.data)
|
||||
export const deleteFolder = id => client.delete(`/api/media/folders/${id}`)
|
||||
export const moveMedia = (ids, folderId) => client.post('/api/media/move', { ids, folder_id: folderId ?? null }).then(r => r.data)
|
||||
export const setFolder = (id, folderId) => client.patch(`/api/media/${id}`, { folder_id: folderId ?? null }).then(r => r.data)
|
||||
|
||||
@@ -27,8 +27,8 @@ export function useUploadQueue(onDone) {
|
||||
useEffect(() => { done.current = onDone })
|
||||
const counter = useRef(0)
|
||||
|
||||
const add = useCallback(files => {
|
||||
const list = queueFrom(files, counter.current)
|
||||
const add = useCallback((files, folderId = null) => {
|
||||
const list = queueFrom(files, counter.current).map(x => ({ ...x, folderId }))
|
||||
counter.current += list.length
|
||||
setQueue(q => [...q, ...list])
|
||||
}, [])
|
||||
@@ -41,7 +41,7 @@ export function useUploadQueue(onDone) {
|
||||
running.current = true
|
||||
const set = patch => setQueue(q => q.map(x => (x.key === next.key ? { ...x, ...patch } : x)))
|
||||
set({ status: 'uploading' })
|
||||
uploadMedia(next.file, { onProgress: progress => set({ progress }) })
|
||||
uploadMedia(next.file, { folderId: next.folderId, onProgress: progress => set({ progress }) })
|
||||
.then(item => { set({ status: item.existing ? 'existing' : 'added', progress: 100, item }); done.current?.(item, !!item.existing) })
|
||||
.catch(err => set({ status: 'failed', error: errorMessage(err, t) }))
|
||||
.finally(() => { running.current = false; setQueue(q => [...q]) })
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
// The settings of the widgets added in 6R.15 (owner 2026-11-22): a shape, a scrolling text, a
|
||||
// countdown, the opening hours, the guests' Wi-Fi and the contact details; the reviews (6R.19). The last three read the
|
||||
// countdown, the opening hours, the guests' Wi-Fi and the contact details; the reviews (6R.19); a gallery (6R.16). The last three read the
|
||||
// venue (Settings → Identity, the Schedule page's opening hours): when that is missing the card says
|
||||
// so with a link to where it is set. Used by WidgetsEditor (its row and the part under it).
|
||||
import { useEffect, useState } from 'react'
|
||||
import { ArrowLeft, ArrowRight, Film, Plus, X } from 'lucide-react'
|
||||
import { Link } from 'react-router-dom'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { ColourField, Dropdown, Field, Input, Notice, NumberInput, Segmented, Slider, Switch } from '@xenia/ui'
|
||||
import { Button, ColourField, Dropdown, Field, IconButton, Input, Notice, NumberInput, Segmented, Slider, Switch } from '@xenia/ui'
|
||||
import { listFolders } from '../media/mediaApi'
|
||||
import MediaPicker from '../media/MediaPicker'
|
||||
import { useHours, useIdentity } from '../../shell/useIdentity'
|
||||
import * as api from './signageApi'
|
||||
import { CONTACT_KEYS, WIDGET_COLOURS } from './signageLogic'
|
||||
import { CONTACT_KEYS, moved, WIDGET_COLOURS } from './signageLogic'
|
||||
|
||||
const SHAPES = ['rectangle', 'circle', 'triangle', 'polygon', 'star', 'custom']
|
||||
const isDate = v => !!v && v.length > 5
|
||||
@@ -79,6 +82,25 @@ export function MoreInlineFields({ w, set }) {
|
||||
</Field>
|
||||
)
|
||||
}
|
||||
if (w.kind === 'gallery') {
|
||||
return (<>
|
||||
<Field label={t(`${k}.gallery.source`)}>
|
||||
<Segmented fill value={w.gallery_source || 'pictures'} onChange={gallery_source => set({ gallery_source })} data-testid="signage-widget-gallery-source"
|
||||
options={['pictures', 'folder'].map(v => ({ value: v, label: t(`${k}.gallery.sources.${v}`) }))} />
|
||||
</Field>
|
||||
<Field label={t(`${k}.gallery.seconds`)}>
|
||||
<NumberInput value={w.gallery_seconds ?? 5} min={3} max={120} suffix="s" onChange={v => set({ gallery_seconds: v ?? 3 })} />
|
||||
</Field>
|
||||
<Field label={t('signage.transition')}>
|
||||
<Dropdown value={w.gallery_transition || 'fade'} onChange={gallery_transition => set({ gallery_transition })}
|
||||
options={['fade', 'slide', 'zoom', 'none'].map(x => ({ value: x, label: t(`signage.transitions.${x}`) }))} />
|
||||
</Field>
|
||||
<Field label={t('signage.fit')}>
|
||||
<Dropdown value={w.gallery_fit || 'cover'} onChange={gallery_fit => set({ gallery_fit })}
|
||||
options={[{ value: 'cover', label: t('signage.fits.cover') }, { value: 'contain', label: t('signage.fits.contain') }]} />
|
||||
</Field>
|
||||
</>)
|
||||
}
|
||||
if (w.kind === 'reviews') {
|
||||
return (<>
|
||||
<Field label={t(`${k}.reviews.min`)}>
|
||||
@@ -102,7 +124,7 @@ export function MoreInlineFields({ w, set }) {
|
||||
}
|
||||
|
||||
/** Under the row: what needs more room, and what the venue still has to set. */
|
||||
export function MoreBelowFields({ w, set }) {
|
||||
export function MoreBelowFields({ w, set, media = {}, onMedia }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const { data: identity } = useIdentity()
|
||||
const { data: hours } = useHours()
|
||||
@@ -172,6 +194,7 @@ export function MoreBelowFields({ w, set }) {
|
||||
</div>
|
||||
)
|
||||
}
|
||||
if (w.kind === 'gallery') return <GalleryItems w={w} set={set} media={media} onMedia={onMedia} />
|
||||
if (w.kind === 'reviews') {
|
||||
return (
|
||||
<div className="grid gap-3">
|
||||
@@ -206,3 +229,54 @@ function ReviewsNote() {
|
||||
? <Notice tone="warning" title={t('signage.widgets.reviews.missing')} data-testid="signage-widget-reviews-missing">{link}</Notice>
|
||||
: <p className="text-caption text-ink-3 -mt-2">{t('signage.widgets.reviews.hint')} {link}</p>
|
||||
}
|
||||
|
||||
/** A gallery's pictures and videos (its own list, in order) or the media folder it shows (6R.16). */
|
||||
function GalleryItems({ w, set, media, onMedia }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const [picking, setPicking] = useState(false)
|
||||
const [folders, setFolders] = useState(null)
|
||||
const folder = w.gallery_source === 'folder'
|
||||
useEffect(() => { if (folder) listFolders().then(r => setFolders(r.folders)).catch(() => setFolders([])) }, [folder])
|
||||
const k = 'signage.widgets.gallery'
|
||||
if (folder) {
|
||||
return (
|
||||
<div className="grid gap-2">
|
||||
<Field label={t(`${k}.folder`)} hint={t(`${k}.folderHint`)} className="max-w-sm">
|
||||
<Dropdown value={w.gallery_folder ?? ''} onChange={v => set({ gallery_folder: v === '' ? null : Number(v) })} data-testid="signage-widget-gallery-folder"
|
||||
options={[{ value: '', label: t(`${k}.noFolder`) }, ...(folders || []).map(f => ({ value: f.id, label: f.name, hint: String(f.count) }))]} />
|
||||
</Field>
|
||||
{folders && folders.length === 0 && (
|
||||
<Notice tone="warning" title={t(`${k}.noFolders`)}><Link to="/management/media" className="text-accent-ink font-medium underline">{t(`${k}.toMedia`)}</Link></Notice>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
const ids = w.media_ids || []
|
||||
return (
|
||||
<div className="grid gap-2" data-testid="signage-widget-gallery-items">
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{ids.map((id, i) => {
|
||||
const m = media[String(id)]
|
||||
return (
|
||||
<div key={`${id}-${i}`} className="relative w-24 h-16 rounded-control border border-line bg-surface-3 overflow-hidden group" data-testid="signage-gallery-item">
|
||||
{m?.thumb ? <img src={m.thumb} alt={m.name || ''} className="w-full h-full object-cover" /> : <Film size={18} className="m-auto mt-5 text-ink-3" aria-hidden="true" />}
|
||||
<div className="absolute inset-x-0 bottom-0 flex justify-between bg-surface/80 opacity-0 group-hover:opacity-100 focus-within:opacity-100">
|
||||
<IconButton size="sm" label={t('signage.widgets.backward')} disabled={i === 0} onClick={() => set({ media_ids: moved(ids, i, i - 1) })}><ArrowLeft size={13} /></IconButton>
|
||||
<IconButton size="sm" tone="danger" label={t('fees.delete')} onClick={() => set({ media_ids: ids.filter((_, j) => j !== i) })}><X size={13} /></IconButton>
|
||||
<IconButton size="sm" label={t('signage.widgets.forward')} disabled={i === ids.length - 1} onClick={() => set({ media_ids: moved(ids, i, i + 1) })}><ArrowRight size={13} /></IconButton>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
{ids.length < 100 && (
|
||||
<Button variant="secondary" icon={<Plus size={14} />} onClick={() => setPicking(true)} className="h-16" data-testid="signage-widget-gallery-add">{t(`${k}.add`)}</Button>
|
||||
)}
|
||||
</div>
|
||||
{ids.length === 0 && <p className="text-caption text-ink-3">{t(`${k}.empty`)}</p>}
|
||||
{picking && (
|
||||
<MediaPicker open multiple kind="" onClose={() => setPicking(false)}
|
||||
onPickMany={items => { items.forEach(it => onMedia?.(it)); set({ media_ids: [...ids, ...items.map(it => it.id)].slice(0, 100) }); setPicking(false) }} />
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ import { Fragment, useEffect, useRef, useState } from 'react'
|
||||
import {
|
||||
AlignCenter, AlignLeft, AlignRight, AlignVerticalJustifyCenter, AlignVerticalJustifyEnd, AlignVerticalJustifyStart, ArrowDown, ArrowUp, Bold, Italic, Palette, RotateCcw, Underline, BookImage, CalendarDays, ChevronDown, Clock, CloudSun, Columns3, GripVertical,
|
||||
ImageIcon, LayoutList, MessageSquare, Plus, QrCode, Rows3, Store, Trash2, Type, UtensilsCrossed,
|
||||
CalendarClock, Contact, MessageSquareQuote, MoveHorizontal, Shapes, Timer, Wifi,
|
||||
CalendarClock, Contact, GalleryHorizontal, MessageSquareQuote, MoveHorizontal, Shapes, Timer, Wifi,
|
||||
} from 'lucide-react'
|
||||
import { cellWidgets, evenShares, setShare } from '@xenia/signage'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
@@ -44,8 +44,8 @@ import {
|
||||
} from './signageLogic'
|
||||
|
||||
const ICON = { logo: ImageIcon, name: Store, date: CalendarDays, clock: Clock, message: MessageSquare, text: Type, qr: QrCode, weather: CloudSun, menu: UtensilsCrossed, hstack: Columns3, vstack: Rows3,
|
||||
shape: Shapes, ticker: MoveHorizontal, countdown: Timer, hours: CalendarClock, wifi: Wifi, contact: Contact, reviews: MessageSquareQuote }
|
||||
const MORE_KINDS = ['shape', 'ticker', 'countdown', 'hours', 'wifi', 'contact', 'reviews'] // MoreWidgetFields
|
||||
shape: Shapes, ticker: MoveHorizontal, countdown: Timer, hours: CalendarClock, wifi: Wifi, contact: Contact, reviews: MessageSquareQuote, gallery: GalleryHorizontal }
|
||||
const MORE_KINDS = ['shape', 'ticker', 'countdown', 'hours', 'wifi', 'contact', 'reviews', 'gallery'] // MoreWidgetFields
|
||||
const iconOf = w => (w.kind === 'stack' ? (w.direction === 'column' ? Rows3 : Columns3) : ICON[w.kind] || LayoutList)
|
||||
const kindLabel = (t, w) => t(`signage.widgets.kinds.${w.kind === 'stack' ? (w.direction === 'column' ? 'vstack' : 'hstack') : w.kind}`)
|
||||
const ROW = 'grid gap-4 items-end grid-cols-[repeat(auto-fill,minmax(11rem,1fr))]'
|
||||
@@ -307,7 +307,7 @@ function InlineFields({ w, set }) {
|
||||
/** What needs more room, under the row: the picture, hints, the QR's own link, a menu's list, a stack's parts. */
|
||||
function BelowFields({ w, set, media, onMedia, extras, path, depth, selected, onSelect }) {
|
||||
const { t } = useTranslation('manager')
|
||||
if (MORE_KINDS.includes(w.kind)) return <MoreBelow w={w} set={set} />
|
||||
if (MORE_KINDS.includes(w.kind)) return <MoreBelow w={w} set={set} media={media} onMedia={onMedia} />
|
||||
if (w.kind === 'logo') {
|
||||
return <MediaPick kind="image" value={w.media_id} entry={media[String(w.media_id)]} testid="signage-widget-logo"
|
||||
onChange={item => { onMedia(item); set({ media_id: item.id }) }} />
|
||||
|
||||
@@ -137,9 +137,9 @@ export function mediaLookup(map) {
|
||||
|
||||
// ── menu boards and widgets (5.6b) ───────────────────────────────────────────
|
||||
|
||||
export const WIDGET_KINDS = ['logo', 'name', 'date', 'clock', 'message', 'text', 'qr', 'weather', 'menu', 'shape', 'ticker', 'countdown', 'hours', 'wifi', 'contact', 'reviews']
|
||||
export const WIDGET_KINDS = ['logo', 'name', 'date', 'clock', 'message', 'text', 'qr', 'weather', 'menu', 'shape', 'ticker', 'countdown', 'hours', 'wifi', 'contact', 'reviews', 'gallery']
|
||||
/** What a stack's part can show (2026-11-21): a widget, a stack one level deep, a library slide. */
|
||||
export const CELL_KINDS = ['logo', 'name', 'date', 'clock', 'message', 'text', 'qr', 'weather', 'menu', 'shape', 'ticker', 'countdown', 'hours', 'wifi', 'contact', 'reviews']
|
||||
export const CELL_KINDS = ['logo', 'name', 'date', 'clock', 'message', 'text', 'qr', 'weather', 'menu', 'shape', 'ticker', 'countdown', 'hours', 'wifi', 'contact', 'reviews', 'gallery']
|
||||
|
||||
/** A new widget of a kind ('hstack' / 'vstack': a stack side by side / one over the other), where it
|
||||
* usually goes: a menu or a stack in a box of its own (they fill a box). */
|
||||
@@ -152,6 +152,7 @@ export function newWidget(kind) {
|
||||
return { kind, position: 'custom', size: 'custom', align: 'auto', box: { x: 55, y: 10, w: 40, h: 80 }, board: { select: 'all', columns: 1, sales_point: 'in_store' } }
|
||||
}
|
||||
if (kind === 'shape') return { kind, position: 'custom', size: 'custom', align: 'auto', box: { x: 40, y: 30, w: 20, h: 35 }, shape: 'rectangle', radius: 10 }
|
||||
if (kind === 'gallery') return { kind, position: 'custom', size: 'custom', align: 'auto', box: { x: 55, y: 15, w: 40, h: 50 }, media_ids: [] }
|
||||
if (kind === 'reviews') return { kind, position: 'custom', size: 'custom', align: 'auto', box: { x: 25, y: 55, w: 50, h: 32 } }
|
||||
return { kind, position: NEW_PLACE[kind] || 'top-right', size: 'medium', align: 'auto',
|
||||
...(kind === 'text' || kind === 'ticker' ? { text: '' } : {}), ...(kind === 'countdown' ? { countdown_to: '17:00' } : {}) }
|
||||
|
||||
Reference in New Issue
Block a user