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:
2026-11-22 14:41:17 +02:00
co-authored by Claude Opus 5.5
parent 189bd2777b
commit 1eb7e5e3a9
24 changed files with 549 additions and 51 deletions
@@ -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' } : {}) }