|
|
|
@@ -258,6 +258,13 @@ const SLOTS = [['Daytime','06:00 to 17:00'],['Evening','17:00 to 22:00'],['Late'
|
|
|
|
|
const sameHours = (a, b) => JSON.stringify(a ?? null) === JSON.stringify(b ?? null);
|
|
|
|
|
function create() {
|
|
|
|
|
const c = state.create, d = c.draft;
|
|
|
|
|
if (c.done) return `<div style="text-align:center;padding:40px 8px 0"><div style="font-size:44px;color:var(--mint)">✓</div>
|
|
|
|
|
<div class="title" style="white-space:normal">${esc(c.done.name)} is ready on ${c.done.number}</div>
|
|
|
|
|
<div class="small" style="margin:8px 0 22px">${esc(c.done.message || '')}</div>
|
|
|
|
|
${c.watching ? `<div class="card small" style="margin-bottom:12px">${esc(c.watching)}</div>` : ''}
|
|
|
|
|
<button class="btn gold" data-cwatch="next" style="margin-bottom:8px">Watch after this programme</button>
|
|
|
|
|
<button class="btn" data-cwatch="now" style="margin-bottom:8px">Watch now</button>
|
|
|
|
|
<button class="btn" data-cdone="1" style="background:none;color:var(--muted)">Done</button></div>`;
|
|
|
|
|
const bar = `<div style="display:flex;gap:6px;margin:4px 0 4px">${STEPS.map((n, i) => `<div style="flex:1"><div style="height:4px;border-radius:2px;background:${i <= c.step ? 'var(--accent)' : 'var(--surface)'}"></div>
|
|
|
|
|
<div class="small" style="font-size:10px;margin-top:4px;${i === c.step ? 'color:var(--ink);font-weight:700' : ''}">${n}</div></div>`).join('')}</div>`;
|
|
|
|
|
const top = `<header><button data-cback="1" aria-label="Back" style="padding:4px 6px 4px 0">${I.chev('left')}</button><span class="title" style="font-size:20px;margin:0">${d.number ? 'Edit ' + esc(d.name) : 'Create a channel'}</span></header>` + bar;
|
|
|
|
@@ -374,11 +381,27 @@ async function suggestShows() {
|
|
|
|
|
catch (e) { c.note = e.message; }
|
|
|
|
|
c.busy = false; render();
|
|
|
|
|
}
|
|
|
|
|
// A new channel takes a moment to plan its first programmes, so the phone keeps asking until the TV can tune it.
|
|
|
|
|
async function watchNew(when) {
|
|
|
|
|
const c = state.create; if (!c?.done || c.trying) return;
|
|
|
|
|
c.trying = true; c.watching = 'Planning its first programmes…'; render();
|
|
|
|
|
for (let i = 0; i < 30; i++) {
|
|
|
|
|
try {
|
|
|
|
|
if (when === 'now') await api('/api/tune', {number: c.done.number});
|
|
|
|
|
else await api('/api/queue', {number: c.done.number});
|
|
|
|
|
state.create = null; tab = 'remote'; render(); load('now');
|
|
|
|
|
toast(when === 'now' ? 'On the TV now' : 'Switches when this programme ends'); return;
|
|
|
|
|
} catch (e) { if (!/isn't on this TV/.test(e.message)) { c.watching = e.message; break; } }
|
|
|
|
|
await new Promise(r => setTimeout(r, 3000));
|
|
|
|
|
}
|
|
|
|
|
c.trying = false; if (c.watching === 'Planning its first programmes…') c.watching = "It's still planning. Try again in a minute, or find it in the Guide."; render();
|
|
|
|
|
}
|
|
|
|
|
async function makeChannel() {
|
|
|
|
|
const c = state.create, d = c.draft; if (c.busy) return; c.busy = true; render();
|
|
|
|
|
try { const r = await api('/api/channels', {number: d.number, name: d.name, description: d.description, style: d.style, hours: d.hours, shows: d.shows,
|
|
|
|
|
slots: d.style === 'Shaped' ? d.slots : undefined, core: d.style === 'Shaped' ? d.core : undefined});
|
|
|
|
|
state.create = null; toast(r.message || 'Saved'); load('more'); }
|
|
|
|
|
// Made: offer to watch it now, or straight after the programme on the TV (Paul, 7 November 2026).
|
|
|
|
|
c.done = {number: r.number, name: d.name, message: r.message, edit: !!d.number}; c.busy = false; render(); load('more'); }
|
|
|
|
|
catch (e) { c.note = e.message; c.busy = false; render(); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -496,6 +519,8 @@ document.addEventListener('click', e => {
|
|
|
|
|
if (d.cout) { const dr = state.create.draft; dr.shows = dr.shows.filter(x => x.id !== d.cout); dr.core = dr.core.filter(x => x !== d.cout); delete dr.slots[d.cout];
|
|
|
|
|
if (!dr.shows.length) { state.create.step = 1; } render(); return; }
|
|
|
|
|
if (d.cmake) { makeChannel(); return; }
|
|
|
|
|
if (d.cdone) { state.create = null; render(); return; }
|
|
|
|
|
if (d.cwatch) { watchNew(d.cwatch); return; }
|
|
|
|
|
if (d.homedone) { try { localStorage.setItem('orbit.home', '1'); } catch {} closeSheet(); return; }
|
|
|
|
|
if (d.install) { installAsk?.prompt(); installAsk = null; try { localStorage.setItem('orbit.home', '1'); } catch {} closeSheet(); return; }
|
|
|
|
|
if (d.home) { openSheet(homeSteps()); return; }
|
|
|
|
|