/* views/list.js — /list My List (+ Continue Watching shortcut). */ import { h } from '../util.js'; import * as tmdb from '../tmdb.js'; import { href } from '../router.js'; import { myList } from '../storage.js'; import { grid, posterCard } from '../ui/card.js'; import { icon } from '../ui/icons.js'; export function render(root) { document.title = 'My List · bug tv'; const body = h('div'); const filters = h('div.tabs.tabs--pills', { role: 'tablist', 'aria-label': 'Filter' }); let filter = 'all'; const opts = [['all', 'All'], ['movie', 'Movies'], ['tv', 'Series']]; const tabs = opts.map(([k, label]) => h('button.tab', { type: 'button', role: 'tab', onclick: () => { filter = k; paint(); } }, label)); filters.append(...tabs); function paint() { tabs.forEach((t, i) => { t.classList.toggle('is-active', opts[i][0] === filter); t.setAttribute('aria-selected', opts[i][0] === filter ? 'true' : 'false'); }); const all = myList.all(); const items = all.filter((x) => filter === 'all' || x.type === filter).map((x) => tmdb.toItem(x, x.type)); filters.hidden = !all.length; if (!items.length) { body.replaceChildren(h('div.empty', h('div.empty__icon', icon('bookmark', { size: 28 })), h('h2.empty__title', all.length ? 'Nothing here' : 'Your list is empty'), h('p.empty__text', 'Add movies and series with the + My List button and they will show up here.'), h('a.btn.btn--primary', { href: href('/') }, 'Browse titles'))); return; } body.replaceChildren(grid(items, (it) => posterCard(it))); } root.append(h('div.page.page--padded.container', h('div.page__head', h('h1.page__title', 'My List'), filters), body)); paint(); window.addEventListener('bugtv:mylist', paint); return () => window.removeEventListener('bugtv:mylist', paint); }