Give the phone a native harbour scene with interruptible dermaga pans.

Replace stacked zone strips with one water scene per dermaga, a shore sheet, and a continuous Prod↔Staging camera pan; closing Perlu kamu clears the dim filter.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-11-08 02:33:25 +07:00
parent 1b246afdde
commit 9c66b83e41
5 changed files with 449 additions and 122 deletions

View File

@@ -41,7 +41,7 @@
todo: '<svg width="12" height="12" viewBox="0 0 12 12"><path d="M3 6h6M6.5 3.5L9 6l-2.5 2.5" fill="none" stroke="#6B4206" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg>',
};
const state = { cols: null, data: null, sel: null, filter: 'all', listOpen: false, seen: new Set(), first: true, failedAt: null, shown: null, composing: null, busy: false, error: null, releaseTag: null };
const state = { cols: null, data: null, sel: null, lane: null, laneDir: 0, filter: 'all', listOpen: false, seen: new Set(), first: true, failedAt: null, shown: null, composing: null, busy: false, error: null, releaseTag: null };
const $ = (id) => document.getElementById(id);
const phone = window.matchMedia('(max-width: 899px)');
const shortTitle = (t, n = 28) => {
@@ -169,15 +169,15 @@
const duration = Math.min(3200, 1300 + dist * 2.4);
const lift = Math.min(22, dist / 14);
const tilt = Math.abs(dx) < 4 ? 0 : dx < 0 ? 2.5 : -2.5;
const zone = b.closest('.zone');
zone.style.zIndex = '3';
const berth = b.closest('.zone, .band');
if (berth) berth.style.zIndex = '3';
const move = b.animate([{ transform: `translate(${dx}px, ${dy}px)` }, { transform: 'translate(0, 0)' }], { duration, easing: SAIL_EASE });
b.animate([
{ transform: 'translateY(0) rotate(0deg)', easing: SWELL_EASE },
{ transform: `translateY(${-lift}px) rotate(${tilt}deg)`, offset: 0.5, easing: SWELL_EASE },
{ transform: 'translateY(0) rotate(0deg)' },
], { duration, composite: 'add' });
move.onfinish = move.oncancel = () => { zone.style.zIndex = ''; };
move.onfinish = move.oncancel = () => { if (berth) berth.style.zIndex = ''; };
}
}
@@ -289,26 +289,259 @@
}
}
// Interruptible motion (phone dermaga pan) — reuse this pattern for later board animations.
//
// Goal: a reverse tap mid-flight continues from the pixels on screen (UIKit / UIViewPropertyAnimator),
// never jumps back to a rest pose, and never tears the moving layer down early.
//
// Do:
// 1. Animate whole layers (here: two `.phone-harbour` scenes), not clones of children.
// 2. Keep both layers mounted for the whole pan (`#lanes.lane-panning`). On interrupt, swap
// which one is "stay" vs "leave" and retarget — do not replaceChildren / remove ghosts.
// 3. Retarget with commitStyles → cancel → animate from getComputedStyle().transform to the
// new end. That presentation value is the continuous join point.
// 4. Use one long ease-in-ease-out (Apple CAMediaTimingFunction easeInEaseOut below), no stagger,
// so it reads as a camera pan. Bump lanePanGen so stale finished callbacks no-op.
// 5. Clip at the real screen edge (full-bleed `#lanes`); padding belongs inside the scene.
//
// Don't:
// - Snapshot boats into absolute ghosts and delete the live tree (killing in-flight work).
// - Start a new keyframe from translate(0) / off-screen while an old animation still owns the node.
// - clear() or cancel without commitStyles first (causes a visible snap).
//
// Reference implementation: interruptiblePan + panPhoneHarbour below.
const LANE_SLIDE_MS = 920;
const LANE_SLIDE_EASE = 'cubic-bezier(0.42, 0, 0.58, 1)'; // CAMediaTimingFunction easeInEaseOut
let lanePanGen = 0;
function interruptiblePan(el, to, { onDone } = {}) {
for (const a of el.getAnimations()) {
try { a.commitStyles(); } catch { /* not fill:forwards yet */ }
a.cancel();
}
const from = getComputedStyle(el).transform;
const anim = el.animate(
[{ transform: from === 'none' ? 'matrix(1, 0, 0, 1, 0, 0)' : from }, { transform: to }],
{ duration: LANE_SLIDE_MS, easing: LANE_SLIDE_EASE, fill: 'forwards' },
);
const gen = lanePanGen;
anim.finished.then(() => {
if (gen !== lanePanGen) return;
try { anim.commitStyles(); } catch { /* already cancelled */ }
anim.cancel();
if (to === 'translateX(0px)') el.style.transform = '';
if (onDone) onDone();
}).catch(() => {});
return anim;
}
function buildPhoneScene(laneName) {
const scene = el('div', { class: 'harbour-scene' });
for (const z of ZONES) {
const items = zoneItems(state.data, laneName, z);
scene.append(
el('div', { class: `band band-${z.key}`, 'aria-label': z.label },
el('div', { class: 'boats' }, items.map((a) => boat(a))),
),
);
}
scene.append(el('div', { class: 'beach', 'aria-hidden': 'true' }));
return el('section', { class: 'lane phone-harbour', 'aria-label': laneName }, scene);
}
function settlePhoneHarbour(main, keep) {
for (const child of [...main.children]) {
if (child === keep) continue;
for (const a of child.getAnimations()) a.cancel();
child.remove();
}
for (const a of keep.getAnimations()) {
try { a.commitStyles(); } catch { /* ignore */ }
a.cancel();
}
keep.classList.remove('lane-pan', 'lane-in', 'lane-out');
keep.style.transform = '';
main.classList.remove('lane-panning');
main.style.height = '';
}
function panPhoneHarbour(main, dir) {
const target = state.lane;
if (!target) {
main.replaceChildren();
main.classList.remove('lane-panning');
return;
}
if (calm.matches) {
main.classList.remove('lane-panning');
main.replaceChildren(buildPhoneScene(target));
return;
}
lanePanGen += 1;
const gen = lanePanGen;
const scenes = [...main.querySelectorAll('.phone-harbour')];
let stay = scenes.find((s) => s.getAttribute('aria-label') === target) || null;
let leave = scenes.find((s) => s !== stay) || null;
// Mid-pan interrupt: both scenes stay mounted; only the targets change.
if (stay && leave && main.classList.contains('lane-panning')) {
stay.classList.add('lane-pan', 'lane-in');
stay.classList.remove('lane-out');
leave.classList.add('lane-pan', 'lane-out');
leave.classList.remove('lane-in');
interruptiblePan(leave, dir > 0 ? 'translateX(-100%)' : 'translateX(100%)', {
onDone: () => { if (gen === lanePanGen && leave.isConnected) leave.remove(); },
});
interruptiblePan(stay, 'translateX(0px)', {
onDone: () => { if (gen === lanePanGen) settlePhoneHarbour(main, stay); },
});
return;
}
// Fresh pan from a settled harbour.
const current = main.querySelector('.phone-harbour');
if (!current) {
main.replaceChildren(buildPhoneScene(target));
return;
}
if (current.getAttribute('aria-label') === target) return;
main.style.height = `${Math.max(main.offsetHeight, 280)}px`;
main.classList.add('lane-panning');
current.classList.add('lane-pan', 'lane-out');
current.classList.remove('lane-in');
const next = buildPhoneScene(target);
next.classList.add('lane-pan', 'lane-in');
next.style.transform = dir > 0 ? 'translateX(100%)' : 'translateX(-100%)';
main.append(next);
interruptiblePan(current, dir > 0 ? 'translateX(-100%)' : 'translateX(100%)', {
onDone: () => { if (gen === lanePanGen && current.isConnected) current.remove(); },
});
interruptiblePan(next, 'translateX(0px)', {
onDone: () => { if (gen === lanePanGen) settlePhoneHarbour(main, next); },
});
}
function visibleLanes(data) {
const used = new Set(data.ajuan.map((a) => a.lane));
return data.lanes.filter((l, i) => used.has(l) || (l !== 'Lainnya' && i < 2));
}
function zoneItems(data, lane, z) {
let items = data.ajuan.filter((a) => a.lane === lane && META[a.status].zone === z.key);
// Beres in the order boats docked, so the first in is the first out.
if (z.key === 'beres') items = items.slice().sort((x, y) => Date.parse(x.dockedAt) - Date.parse(y.dockedAt));
return items;
}
function drawToolbar(lanes) {
const bar = $('toolbar');
if (!phone.matches) {
bar.hidden = true;
bar.replaceChildren();
return;
}
const { data } = state;
const mine = data.ajuan.filter((a) => a.needsYou).length;
bar.hidden = false;
bar.replaceChildren(
el('div', { class: 'dermaga', role: 'group', 'aria-label': 'Dermaga' },
lanes.map((name) => el('button', {
type: 'button',
class: 'chip-pill',
'aria-pressed': String(state.lane === name),
onclick: () => {
if (state.lane === name) return;
const from = lanes.indexOf(state.lane);
const to = lanes.indexOf(name);
state.laneDir = to >= 0 && from >= 0 && to !== from ? (to > from ? 1 : -1) : 1;
state.lane = name;
state.sel = null;
state.listOpen = false;
history.replaceState(null, '', location.pathname);
drawnLanes = '';
draw();
},
}, name)),
),
el('button', {
type: 'button',
class: 'chip-pill filter',
'aria-pressed': String(state.filter === 'mine'),
onclick: () => {
// Toggle off restores the full harbour; only open the list when turning the filter on.
if (state.filter === 'mine') {
state.filter = 'all';
state.listOpen = false;
} else {
state.filter = 'mine';
state.sel = null;
state.listOpen = true;
history.replaceState(null, '', location.pathname);
}
draw();
},
}, 'Perlu kamu', el('span', { class: 'count' }, mine)),
);
}
// Phone: one dermaga as a single water scene (no zone-card chrome).
function resolvePhoneLane(data, lanes) {
const selected = state.sel && data.ajuan.find((a) => a.id === state.sel);
if (selected && lanes.includes(selected.lane)) state.lane = selected.lane;
else if (!state.lane || !lanes.includes(state.lane))
state.lane = lanes.find((l) => data.ajuan.some((a) => a.lane === l)) || lanes[0] || null;
}
function drawPhoneHarbour(main, data, lanes) {
resolvePhoneLane(data, lanes);
drawToolbar(lanes);
main.classList.remove('lane-panning');
if (!state.lane) {
main.replaceChildren();
return;
}
main.replaceChildren(buildPhoneScene(state.lane));
}
let drawnLanes = '';
function drawLanes() {
const { data } = state;
const used = new Set(data.ajuan.map((a) => a.lane));
const lanes = data.lanes.filter((l, i) => used.has(l) || (l !== 'Lainnya' && i < 2));
const lanes = visibleLanes(data);
const main = $('lanes');
// A refresh that changes nothing on the water leaves the boats alone, so none restarts mid-glide.
const key = JSON.stringify([lanes, state.sel, state.filter, data.ajuan.map((a) => [a.id, a.lane, a.status, a.label, a.title, a.needsYou, state.seen.has(a.id)])]);
if (key === drawnLanes && main.childElementCount) return;
const key = JSON.stringify([phone.matches, state.lane, lanes, state.sel, state.filter, data.ajuan.map((a) => [a.id, a.lane, a.status, a.label, a.title, a.needsYou, state.seen.has(a.id)])]);
if (key === drawnLanes && main.childElementCount) {
if (phone.matches) drawToolbar(lanes);
return;
}
drawnLanes = key;
const before = new Map([...main.querySelectorAll('.boat[data-id]')].map((b) => [b.dataset.id, { rect: b.getBoundingClientRect(), node: b }]));
const shown = new Set();
if (phone.matches) {
const dir = state.laneDir;
state.laneDir = 0;
if (dir) {
resolvePhoneLane(data, lanes);
drawToolbar(lanes);
panPhoneHarbour(main, dir);
return;
}
// Don't tear down a live pan when the queue merely refreshes.
if (main.classList.contains('lane-panning')) {
drawToolbar(lanes);
return;
}
drawPhoneHarbour(main, data, lanes);
for (const b of main.querySelectorAll('.boat[data-id]')) shown.add(b.dataset.id);
sail(new Map([...before].map(([id, b]) => [id, b.rect])));
depart(before, shown);
return;
}
$('toolbar').hidden = true;
$('toolbar').replaceChildren();
main.replaceChildren();
lanes.forEach((name, li) => {
// A redrawn row starts at the widths it had, so the change to new widths can transition.
const zones = el('div', { class: 'zones', style: state.cols ? { gridTemplateColumns: state.cols } : null });
for (const z of ZONES) {
let items = data.ajuan.filter((a) => a.lane === name && META[a.status].zone === z.key);
// Beres in the order boats docked, so the first in is the first out.
if (z.key === 'beres') items = items.slice().sort((x, y) => Date.parse(x.dockedAt) - Date.parse(y.dockedAt));
const items = zoneItems(data, name, z);
zones.append(
el('div', { class: `zone ${z.key}` },
z.key !== 'cek' && el('div', { class: 'floats', 'aria-hidden': 'true' }),
@@ -329,14 +562,12 @@
main.append(lane);
});
// A full Beres lets its earliest finished boats go; deploys still running or failed stay.
if (!phone.matches) {
const room = ROWS * BERES_PER_ROW;
for (const boats of main.querySelectorAll('.zone.beres .boats')) {
const docked = [...boats.children];
const finished = docked.filter((b) => b.finished);
finished.slice(0, Math.max(0, Math.min(finished.length, docked.length - room))).forEach((b) => b.remove());
boats.parentElement.querySelector('.zone-label .n').textContent = boats.childElementCount;
}
const room = ROWS * BERES_PER_ROW;
for (const boats of main.querySelectorAll('.zone.beres .boats')) {
const docked = [...boats.children];
const finished = docked.filter((b) => b.finished);
finished.slice(0, Math.max(0, Math.min(finished.length, docked.length - room))).forEach((b) => b.remove());
boats.parentElement.querySelector('.zone-label .n').textContent = boats.childElementCount;
}
for (const b of main.querySelectorAll('.boat[data-id]')) shown.add(b.dataset.id);
// Boats take their new slots at once; the columns then widen or narrow through their
@@ -517,24 +748,27 @@
el('div', {}, el('span', { class: 'word' }, m.word), el('span', { class: 'reason' }, a.reason)),
),
);
// Decide first (Gas under the thumb), then findings and history below the fold.
if (a.actions.length || a.gasAt || a.closeAt) card.append(actions(a));
if (a.release) card.append(releaseBox(a));
if (a.deployUrl) card.append(el('p', { class: 'note' }, el('a', { href: a.deployUrl, target: '_blank', rel: 'noopener' }, 'Pipeline deploy')));
const more = el('div', { class: 'more' });
if (a.release) more.append(releaseBox(a));
if (a.deployUrl) more.append(el('p', { class: 'note' }, el('a', { href: a.deployUrl, target: '_blank', rel: 'noopener' }, 'Pipeline deploy')));
if (a.findings.length)
card.append(el('ul', { class: 'findings' }, a.findings.map((f) => el('li', {}, el('span', { class: `k ${f.kind}`, 'aria-hidden': 'true', html: KIND[f.kind] }), el('span', {}, f.text, evidenceLinks(f.evidence))))));
more.append(el('ul', { class: 'findings' }, a.findings.map((f) => el('li', {}, el('span', { class: `k ${f.kind}`, 'aria-hidden': 'true', html: KIND[f.kind] }), el('span', {}, f.text, evidenceLinks(f.evidence))))));
if (a.postDeploy.length) {
card.append(el('p', { class: 'section-title' }, 'Habis deploy'));
card.append(el('ul', { class: 'findings' }, a.postDeploy.map((p) => el('li', {}, el('span', { class: 'k todo', 'aria-hidden': 'true', html: KIND.todo }), el('span', {}, p.text, evidenceLinks(p.evidence))))));
more.append(el('p', { class: 'section-title' }, 'Habis deploy'));
more.append(el('ul', { class: 'findings' }, a.postDeploy.map((p) => el('li', {}, el('span', { class: 'k todo', 'aria-hidden': 'true', html: KIND.todo }), el('span', {}, p.text, evidenceLinks(p.evidence))))));
}
for (const o of a.overrides) card.append(el('p', { class: 'note' }, `Aturan Labuh: ${o}`));
if (a.reviewedSha) card.append(el('p', { class: 'stamp' }, `${state.data.reviewer} · commit ${a.reviewedSha.slice(0, 8)} · ${a.tokens.toLocaleString('id-ID')} token`));
for (const o of a.overrides) more.append(el('p', { class: 'note' }, `Aturan Labuh: ${o}`));
if (a.reviewedSha) more.append(el('p', { class: 'stamp' }, `${state.data.reviewer} · commit ${a.reviewedSha.slice(0, 8)} · ${a.tokens.toLocaleString('id-ID')} token`));
const history = el('ol', {}, a.timeline.map((t) => el('li', {}, el('span', {}, clock(t.at)), el('span', {}, t.text))));
card.append(
more.append(
el('div', { class: 'foot' },
el('details', {}, el('summary', {}, 'Riwayat'), history),
el('a', { class: 'open', href: a.webUrl, target: '_blank', rel: 'noopener', html: 'Buka MR <svg width="14" height="14" viewBox="0 0 16 16" aria-hidden="true"><path d="M6 3h7v7M13 3L5 11" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>' }),
),
);
if (more.childElementCount) card.append(more);
return card;
}
@@ -595,13 +829,17 @@
state.shown = key;
const mine = data.ajuan.filter((x) => x.needsYou).length;
$('mine-count').textContent = mine;
const mineCount = $('mine-count');
if (mineCount) mineCount.textContent = mine;
$('show-all').setAttribute('aria-pressed', String(state.filter === 'all'));
$('show-mine').setAttribute('aria-pressed', String(state.filter === 'mine'));
const v = data.viewer;
$('avatar').textContent = (v.name || v.username).charAt(0).toUpperCase();
$('avatar').title = `Keluar (@${v.username})`;
$('avatar').setAttribute('aria-label', `Keluar dari akun @${v.username}`);
const initial = (v.name || v.username).charAt(0).toUpperCase();
for (const av of document.querySelectorAll('[data-avatar]')) {
av.textContent = initial;
av.title = `Keluar (@${v.username})`;
av.setAttribute('aria-label', `Keluar dari akun @${v.username}`);
}
}
function drawHeadline() {
@@ -636,6 +874,8 @@
}
function closeSheet() {
// Closing the "Perlu kamu" list exits the filter so boats are not left dimmed.
if (state.listOpen) state.filter = 'all';
state.listOpen = false;
if (state.sel) pick(null);
else draw();
@@ -718,12 +958,17 @@
}
}, 1000);
document.addEventListener('visibilitychange', () => { if (!document.hidden) load(); });
window.addEventListener('resize', () => {
const onViewport = () => {
drawnLanes = '';
if (state.data) {
if (!phone.matches) state.listOpen = false;
if (!phone.matches) {
state.listOpen = false;
state.lane = null;
}
draw();
}
});
};
window.addEventListener('resize', onViewport);
phone.addEventListener('change', onViewport);
});
})();