af1a7d64c3
Co-authored-by: Tim Orme <TimothyOrme@gmail.com>
130 lines
5.5 KiB
TypeScript
130 lines
5.5 KiB
TypeScript
import { AssetType } from '../types'
|
|
import { ThemeScript } from './theme'
|
|
import { GalleryItem, LightboxConfig, MetadataConfig, GroupByDateMode } from '../shared/types'
|
|
import { ASSET_VERSION } from '../version'
|
|
|
|
export type { GalleryItem, LightboxConfig, MetadataConfig, GroupByDateMode }
|
|
|
|
export interface GalleryProps {
|
|
items: GalleryItem[]
|
|
title: string
|
|
description: string
|
|
publicBaseUrl: string
|
|
path: string
|
|
showDownloadZip: boolean
|
|
showTitle: boolean
|
|
// Formatted "available until" date shown in the subtitle, or undefined when
|
|
// ipp.gallery.showExpiryDate is off or the share never expires.
|
|
expiryDate?: string
|
|
openItem?: number
|
|
ogImageItem?: GalleryItem
|
|
lightboxConfig: LightboxConfig
|
|
metadataConfig: MetadataConfig
|
|
groupByDate: GroupByDateMode | false
|
|
metaBase?: string
|
|
}
|
|
|
|
export function Gallery (props: GalleryProps) {
|
|
const initJson = JSON.stringify({
|
|
items: props.items,
|
|
openItem: props.openItem,
|
|
lightboxConfig: props.lightboxConfig,
|
|
metadataConfig: props.metadataConfig,
|
|
groupByDate: props.groupByDate,
|
|
metaBase: props.metaBase
|
|
})
|
|
const firstItem = props.items[0]
|
|
// og:image prefers the album cover (passed via props); for videos, previewUrl
|
|
// points to the .mp4, so use thumbnailUrl to keep og:image a still JPEG.
|
|
const ogItem = props.ogImageItem || firstItem
|
|
const ogImageAsset = ogItem
|
|
? (ogItem.type === AssetType.video ? ogItem.thumbnailUrl : ogItem.previewUrl)
|
|
: ''
|
|
const ogImageUrl = ogItem ? props.publicBaseUrl + ogImageAsset : ''
|
|
// The title block also carries the subtitle (item count + optional expiry),
|
|
// so it renders when a title is wanted OR there's an expiry date to show.
|
|
const showHeaderText = props.showTitle || !!props.expiryDate
|
|
|
|
return (
|
|
<html lang="en">
|
|
<head>
|
|
<ThemeScript/>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
|
<title>{props.title}</title>
|
|
<meta property="og:title" content={props.title}/>
|
|
<meta name="twitter:title" content={props.title}/>
|
|
{props.description && <>
|
|
<meta name="description" content={props.description}/>
|
|
<meta property="og:description" content={props.description}/>
|
|
<meta property="twitter:description" content={props.description}/>
|
|
</>}
|
|
{firstItem && <>
|
|
<meta property="og:image" content={ogImageUrl}/>
|
|
<meta name="twitter:image" content={ogImageUrl}/>
|
|
<meta name="twitter:card" content="summary_large_image"/>
|
|
</>}
|
|
<link rel="icon" href="/share/static/favicon.ico" type="image/x-icon"/>
|
|
<link type="text/css" rel="stylesheet" href={`/share/static/${ASSET_VERSION}/style.css`}/>
|
|
<link type="text/css" rel="stylesheet" href="/share/static/photoswipe/photoswipe.css"/>
|
|
<link type="text/css" rel="stylesheet" href={`/share/static/${ASSET_VERSION}/photoswipe-overrides.css`}/>
|
|
</head>
|
|
<body>
|
|
{(showHeaderText || props.showDownloadZip) && (
|
|
<header id="header">
|
|
{showHeaderText && (
|
|
<div class="header-text">
|
|
{props.showTitle && <h1>{props.title || 'Gallery'}</h1>}
|
|
<p class="subtitle">
|
|
{props.items.length}{' '}
|
|
{props.items.length === 1 ? 'item' : 'items'}
|
|
{props.expiryDate && (
|
|
<>{' · available until '}{props.expiryDate}</>
|
|
)}
|
|
</p>
|
|
</div>
|
|
)}
|
|
{props.showDownloadZip && (
|
|
<a id="download-all" href={props.path + '/download'} title="Download all" aria-label="Download all">
|
|
<svg viewBox="0 0 24 24" aria-hidden="true">
|
|
<path fill="currentColor" d="M5,20H19V18H5M19,9H15V3H9V9H5L12,16L19,9Z"/>
|
|
</svg>
|
|
</a>
|
|
)}
|
|
</header>
|
|
)}
|
|
{props.description && (
|
|
<p id="album-description">{props.description}</p>
|
|
)}
|
|
{/* Container is intentionally empty - web.js's virtualisation manager
|
|
populates it with only the tiles within the viewport buffer. */}
|
|
<div id="gallery"></div>
|
|
{props.showDownloadZip && (
|
|
<div id="select-toolbar" hidden>
|
|
<button id="select-cancel" class="toolbar-btn" type="button" aria-label="Exit selection mode">
|
|
<svg viewBox="0 0 24 24" aria-hidden="true">
|
|
<path fill="currentColor" d="M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z"/>
|
|
</svg>
|
|
</button>
|
|
<span id="select-count">0 selected</span>
|
|
<button id="select-all" class="toolbar-btn-text" type="button">Select all</button>
|
|
<button id="select-download" class="toolbar-btn" type="button" aria-label="Download selected">
|
|
<svg viewBox="0 0 24 24" aria-hidden="true">
|
|
<path fill="currentColor" d="M5,20H19V18H5M19,9H15V3H9V9H5L12,16L19,9Z"/>
|
|
</svg>
|
|
</button>
|
|
</div>
|
|
)}
|
|
{/* Init params for web.js (read at module load). Using a JSON script
|
|
block avoids the cross-script-type coordination problems that come
|
|
with mixing classic and module scripts. */}
|
|
<script
|
|
type="application/json"
|
|
id="ipp-init"
|
|
dangerouslySetInnerHTML={{ __html: initJson }}
|
|
/>
|
|
<script type="module" src={`/share/static/${ASSET_VERSION}/js/client/init.js`}></script>
|
|
</body>
|
|
</html>
|
|
)
|
|
}
|