;
const createModal = setModalOpen(false)} size='tiny'>
New Playlist
setName(value)}/>
setTagName(null)}
/>
;
return <>
{header}
{createModal}
>;
}
// Icon (name + color) for a playlist item. File items use the FileGroup's mimetype/model icon
// and color (video, pdf, ebook, image, ...) so they match the rest of the UI; zim/url are fixed.
function itemIcon(item) {
if (item.item_kind === 'file' && item.file_group) {
const fg = item.file_group;
const lowerPath = (fg.primary_path || '').toLowerCase();
return {name: mimetypeIconName(fg.mimetype, lowerPath), color: mimetypeColor(fg.mimetype, lowerPath)};
}
if (item.item_kind === 'zim') return {name: 'book'};
if (item.item_kind === 'url') {
// A map-location URL (e.g. /map?lat=&lon=) gets a map marker; other URLs get the link icon.
const u = (item.url || '').toLowerCase();
if (u.startsWith('/map')) return {name: 'map marker alternate'};
return {name: 'linkify'};
}
return {name: 'file'};
}
function itemLabel(item) {
if (item.item_kind === 'file' && item.file_group) {
return item.title || item.file_group.title || item.file_group.primary_path || 'File';
}
if (item.item_kind === 'zim' && item.zim) {
return item.title || item.zim.entry;
}
if (item.item_kind === 'url') {
return item.title || item.url;
}
return item.title || 'Item';
}
// Only http(s) and relative WROLPi paths are safe for an href; reject javascript:/data:/etc. so a
// shared playlist's url item cannot execute script when opened. Exported for tests.
export function safeHref(url) {
if (!url) return null;
try {
const u = new URL(url, window.location.origin);
if (u.protocol === 'http:' || u.protocol === 'https:') {
return url; // Keep the original (may be a relative WROLPi path).
}
} catch {
return null;
}
return null;
}
function itemLink(item) {
if (item.item_kind === 'url') {
return safeHref(item.url);
}
if (item.item_kind === 'zim' && item.zim) {
// Built from a numeric id + encoded entry — no user-supplied scheme.
return `/api/zim/${item.zim.id}/entry/${encodeURIComponent(item.zim.entry)}`;
}
return null;
}
// The in-app model page for a FileGroup, or null when there is none (image, audio, 3D, ...).
function fileModelUrl(fg) {
if (!fg) return null;
if (fg.model === 'video') return `/videos/${fg.id}`;
if (fg.model === 'archive') return `/archives/${fg.id}`;
if (fg.model === 'doc') return `/docs/${fg.id}`;
return null;
}
// Render a playlist item's title as the appropriate link:
// - file with a model page (video/archive/doc) -> in-app Link to that page
// - file without a model page (image, etc.) -> PreviewLink (opens the preview modal)
// - zim/url -> the entry/url in a new tab
function ItemTitle({item, label}) {
if (item.item_kind === 'file' && item.file_group) {
const url = fileModelUrl(item.file_group);
if (url) {
return {label};
}
return {label};
}
const link = itemLink(item);
return link
? {label}
: {label};
}
// The ordered items table, shared by the view and edit pages. When `editable`, the reorder/remove
// action buttons (and their column) are shown; otherwise the table is read-only.
function PlaylistItemsTable({items, editable, onMove, onRemove}) {
return