/* TMD Portal — Content calendar and per-brand content tracker.
One month grid showing when every piece of content goes out (tmd_deliverables.publish_on,
falling back to the due date), coloured by brand (tmd_brands.colour). Below it, a tracker
for the selected brand. Reminders for high-priority work live here too and are shown on Today. */
const { useState: uSk, useMemo: uMk } = React;
const DAYS_SHORT = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
const brandColour = b => (b && b.colour) || '#0C0C0C';
function BrandDot({ b }) { return ; }
// The date a piece of content "goes out": publish_on if set, otherwise the due date.
const outDate = d => d.publish_on || d.due || null;
/* ================= Reminders (Today + My tasks) ================= */
// High-priority tasks that have not been started and are due tomorrow (or already today / overdue).
function Reminders({ app, everyone }) {
const { work, me, go } = app;
const mine = t => (t.assignee || '').toLowerCase() === me;
const blockedIds = new Set(work.dels.filter(blocked).map(d => d.id));
const tasks = work.tasks.filter(t => t.state === 'todo' && t.priority === 'High' && t.due && dayDiff(t.due) <= 1 && (everyone || mine(t)) && !(t.deliverable_id && blockedIds.has(t.deliverable_id)));
const dels = work.dels.filter(d => d.stage_sem === 'todo' && d.priority === 'High' && d.due && dayDiff(d.due) <= 1 && (everyone || mine(d)) && !blocked(d));
const items = tasks.map(t => ({ id: 't' + t.id, title: t.title, due: t.due, who: t.assignee, del: work.dels.find(d => d.id === t.deliverable_id), brand: t.brand_slug, kind: 'task' }))
.concat(dels.map(d => ({ id: 'd' + d.id, title: d.title, due: d.due, who: d.assignee, del: d, brand: d.brand_slug, kind: 'deliverable' })))
.sort((a, b) => a.due.localeCompare(b.due));
if (!items.length) return null;
const when = iso => { const n = dayDiff(iso); return n < 0 ? Math.abs(n) + 'd overdue' : n === 0 ? 'due today' : 'due tomorrow'; };
return (
RemindersHigh priority, not started yet.
{items.map(r => (
))}
);
}
/* ================= Calendar ================= */
function Calendar({ app, preset }) {
const { work, go } = app;
const brands = work.brands.filter(b => b.status !== 'Ended');
const [off, setOff] = useRemembered(app, 'cal.off', 0);
const [brand, setBrand] = useRemembered(app, 'cal.brand', preset || 'all', !!preset);
const [showDone, setShowDone] = useRemembered(app, 'cal.done', true);
const start = monthStart(off), end = monthEnd(off);
const first = new Date(start + 'T00:00:00');
const lead = (first.getDay() + 6) % 7; // Monday-first grid
const days = Number(end.slice(8, 10));
const cells = [];
for (let i = 0; i < lead; i++) cells.push(null);
for (let d = 1; d <= days; d++) cells.push(start.slice(0, 8) + String(d).padStart(2, '0'));
while (cells.length % 7) cells.push(null);
const inMonth = uMk(() => work.dels.filter(d => { const o = outDate(d); return o && !blocked(d) && o >= start && o <= end && (brand === 'all' || d.brand_slug === brand) && (showDone || d.stage_sem !== 'done'); }), [work.dels, start, end, brand, showDone]);
const byDay = {};
inMonth.forEach(d => { const o = outDate(d); (byDay[o] = byDay[o] || []).push(d); });
const tracker = work.dels.filter(d => !blocked(d) && (brand === 'all' || d.brand_slug === brand) && (showDone || d.stage_sem !== 'done')).slice().sort((a, b) => (outDate(a) || '9999').localeCompare(outDate(b) || '9999'));
const sel = brand === 'all' ? null : brandOf(brands, brand);
return (
go('board:new')}>New deliverable} />
{DAYS_SHORT.map(d =>
{d}
)}
{cells.map((iso, i) => {
if (!iso) return
;
const items = byDay[iso] || [];
const isToday = iso === T.TODAY;
return (
{Number(iso.slice(8, 10))}
{items.map(d => {
const b = brandOf(brands, d.brand_slug);
return (
);
})}
);
})}
{!inMonth.length ? Nothing is scheduled to go out in {monthLabel(off)}{sel ? ' for ' + sel.name : ''}. Open a deliverable and set “Goes out on”.
: null}
Blocked work is not shown here; it comes back when it is unblocked. Scheduled work turns to Published on its goes-out date.
{sel ? sel.name + ' content tracker' : 'Content tracker'}
{tracker.length ? (
app.mobile ? (
{tracker.map(d => { const b = brandOf(brands, d.brand_slug); return (
); })}
) : (
| Ref | Content | Brand | Type | Stage | Owner | Goes out | Due |
{tracker.map(d => { const b = brandOf(brands, d.brand_slug); return (
go('del:' + d.id)}>
| {d.ref} |
{d.title} |
{b.name} |
{typeOf(d.type).name} |
|
|
{d.publish_on ? fmtDate(d.publish_on) : —} |
|
); })}
)
) : go('board:new')}>New deliverable} />}
);
}
Object.assign(window, { Calendar, Reminders, BrandDot, brandColour, outDate });