Give the phone its own harbour UI instead of a squeezed desktop.
Full-screen water with a floating dock and bottom sheet for detail, clearer boats and Gas actions, plus a branded gate and a fixed sheet-over-scrim stack. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
133
board/board.js
133
board/board.js
@@ -41,8 +41,14 @@
|
||||
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', 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, 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) => {
|
||||
const s = String(t || '').trim().replace(/\s+/g, ' ');
|
||||
if (!s) return '';
|
||||
return s.length <= n ? s : `${s.slice(0, n - 1).trimEnd()}…`;
|
||||
};
|
||||
|
||||
function el(tag, attrs, ...children) {
|
||||
const n = document.createElement(tag);
|
||||
@@ -113,7 +119,7 @@
|
||||
const m = META[a.status];
|
||||
const picked = state.sel === a.id;
|
||||
const dim = state.filter === 'mine' && !a.needsYou;
|
||||
const cls = ['boat', picked && 'picked', dim && 'dim', (a.status === 'done' || a.status === 'rejected') && 'done', a.status === 'sailing' && 'sailing', !state.first && !state.seen.has(a.id) && 'new'].filter(Boolean).join(' ');
|
||||
const cls = ['boat', picked && 'picked', dim && 'dim', a.needsYou && 'needs', (a.status === 'done' || a.status === 'rejected') && 'done', a.status === 'sailing' && 'sailing', !state.first && !state.seen.has(a.id) && 'new'].filter(Boolean).join(' ');
|
||||
// The bobbing phase comes from the clock and the boat, not its place in the list, so a boat
|
||||
// drawn again carries on mid-swell instead of jumping back to the start of its loop.
|
||||
const seed = hash(`${a.repo}${a.iid}`);
|
||||
@@ -122,7 +128,8 @@
|
||||
const delay = `-${(now % secs).toFixed(2)}s`;
|
||||
const flagDelay = `-${(now % 2.2).toFixed(2)}s`;
|
||||
const dur = `${secs.toFixed(1)}s`;
|
||||
const b = el('button', { type: 'button', class: cls, 'data-id': a.id, 'aria-label': `${a.label}, ${m.aria}`, 'aria-pressed': picked ? 'true' : 'false', onclick: () => pick(a.id) });
|
||||
const title = shortTitle(a.title, phone.matches ? 24 : 28);
|
||||
const b = el('button', { type: 'button', class: cls, 'data-id': a.id, 'aria-label': `${a.label}${a.title ? `, ${a.title}` : ''}, ${m.aria}`, 'aria-pressed': picked ? 'true' : 'false', onclick: () => pick(a.id) });
|
||||
const hull = el('span', { class: 'hull', style: { animationDelay: delay, animationDuration: dur } });
|
||||
const h = hullOf(a);
|
||||
hull.innerHTML = `<svg width="96" height="72" viewBox="0 0 96 72" aria-hidden="true" style="overflow:visible"><line x1="48" y1="5" x2="48" y2="44" stroke="#172B33" stroke-width="2.5" stroke-linecap="round"/><g class="flag" style="animation-delay:${flagDelay}"><path d="M50 6 Q60 8 72 7 Q67 12.5 72 18 Q60 17 50 19 Z" fill="${m.flag}"/></g><rect x="34" y="29" width="28" height="16" rx="4" fill="#FFFDF8"/><circle cx="42" cy="37" r="2.6" fill="${h}"/><circle cx="54" cy="37" r="2.6" fill="${h}"/><path d="M6 44 H90 L81 61 Q79 65 73 65 H23 Q17 65 15 61 Z" fill="${h}"/><path d="M13 51 H83" stroke="#FFFDF8" stroke-opacity="0.45" stroke-width="2" stroke-linecap="round"/></svg>`;
|
||||
@@ -134,6 +141,7 @@
|
||||
if (a.status === 'done')
|
||||
b.append(el('span', { class: 'rope', 'aria-hidden': 'true', html: '<svg width="20" height="12" viewBox="0 0 20 12"><path d="M0 2 Q10 12 20 4" fill="none" stroke="#7A5A33" stroke-width="1.8" stroke-linecap="round"/></svg>' }));
|
||||
b.append(el('span', { class: 'chip' }, a.label));
|
||||
if (title) b.append(el('span', { class: 'boat-title' }, title));
|
||||
const marks = el('span', { class: 'marks', 'aria-hidden': 'true' });
|
||||
if (a.status === 'checking' || a.status === 'sailing' || a.status === 'gas') marks.innerHTML = ICON.dots;
|
||||
if (a.status === 'blocked') marks.innerHTML = '<svg width="16" height="16" viewBox="0 0 16 16"><path d="M7 9.5l2-2M5.5 11.5l-1 1a2.1 2.1 0 0 1-3-3l2-2a2.1 2.1 0 0 1 3 0M10.5 4.5l1-1a2.1 2.1 0 0 1 3 3l-2 2a2.1 2.1 0 0 1-3 0" fill="none" stroke="#3E4E53" stroke-width="1.8" stroke-linecap="round"/></svg>';
|
||||
@@ -184,7 +192,6 @@
|
||||
const SHARE = { cek: 3, siap: 2 };
|
||||
// Beres is a fixed berth: two boats per row, so four boats in all.
|
||||
const BERES_PER_ROW = 2;
|
||||
const phone = window.matchMedia('(max-width: 899px)');
|
||||
|
||||
// Dicek and Siap gas share what Beres leaves: each its share, or what its boats need if more.
|
||||
function splitWidth(total, needs, least, weights) {
|
||||
@@ -289,7 +296,7 @@
|
||||
const lanes = data.lanes.filter((l, i) => used.has(l) || (l !== 'Lainnya' && i < 2));
|
||||
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.needsYou, state.seen.has(a.id)])]);
|
||||
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;
|
||||
drawnLanes = key;
|
||||
const before = new Map([...main.querySelectorAll('.boat[data-id]')].map((b) => [b.dataset.id, { rect: b.getBoundingClientRect(), node: b }]));
|
||||
@@ -376,6 +383,24 @@
|
||||
await load();
|
||||
}
|
||||
|
||||
function actionLabel(a, k) {
|
||||
if (k === 'undo' && a.status === 'gas') return 'Batalkan gas';
|
||||
if (k === 'undo' && a.closeAt) return 'Batal tutup';
|
||||
if (k === 'undo' && a.status === 'rejected') return 'Batalkan tolak';
|
||||
if (k === 'gas' && a.dry) return 'Gas (uji coba)';
|
||||
if (k === 'close' && a.dry) return 'Tutup MR (uji coba)';
|
||||
return ACTION_LABEL[k];
|
||||
}
|
||||
|
||||
function actionButton(a, k) {
|
||||
return el('button', {
|
||||
type: 'button',
|
||||
class: `act ${k === 'gas' ? 'primary' : k === 'tolak' || k === 'close' ? 'danger' : 'quiet'}`,
|
||||
disabled: state.busy,
|
||||
onclick: () => (k === 'tunda' || k === 'tolak' ? (state.composing = { id: a.id, action: k, note: '' }, draw()) : act(a, k)),
|
||||
}, actionLabel(a, k));
|
||||
}
|
||||
|
||||
function actions(a) {
|
||||
const box = el('div', { class: 'actions' });
|
||||
if (a.gasAt || a.closeAt) box.append(el('p', { class: 'countdown', role: 'status', 'data-id': a.id }, countdownText(a)));
|
||||
@@ -387,19 +412,17 @@
|
||||
box.append(
|
||||
el('label', { class: 'note-label', for: 'decision-note' }, compose.action === 'tolak' ? 'Tolak ajuan ini' : 'Tunda ajuan ini'),
|
||||
input,
|
||||
el('div', { class: 'buttons' },
|
||||
el('div', { class: 'buttons main' },
|
||||
el('button', { type: 'button', class: `act ${compose.action === 'tolak' ? 'danger' : 'quiet'}`, disabled: state.busy, onclick: () => act(a, compose.action, compose.note) }, compose.action === 'tolak' ? 'Tolak' : 'Tunda'),
|
||||
el('button', { type: 'button', class: 'act quiet', onclick: () => { state.composing = null; draw(); } }, 'Batal'),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
box.append(el('div', { class: 'buttons' }, a.actions.map((k) =>
|
||||
el('button', {
|
||||
type: 'button',
|
||||
class: `act ${k === 'gas' ? 'primary' : k === 'tolak' || k === 'close' ? 'danger' : 'quiet'}`,
|
||||
disabled: state.busy,
|
||||
onclick: () => (k === 'tunda' || k === 'tolak' ? (state.composing = { id: a.id, action: k, note: '' }, draw()) : act(a, k)),
|
||||
}, k === 'undo' && a.status === 'gas' ? 'Batalkan gas' : k === 'undo' && a.closeAt ? 'Batal tutup' : k === 'undo' && a.status === 'rejected' ? 'Batalkan tolak' : k === 'gas' && a.dry ? 'Gas (uji coba)' : k === 'close' && a.dry ? 'Tutup MR (uji coba)' : ACTION_LABEL[k]))));
|
||||
// Gas / undo / close first and full-width on a phone; Tunda and Tolak sit apart so a thumb misses Gas less often.
|
||||
const main = a.actions.filter((k) => k === 'gas' || k === 'undo' || k === 'close');
|
||||
const side = a.actions.filter((k) => k === 'tunda' || k === 'tolak');
|
||||
if (main.length) box.append(el('div', { class: 'buttons main' }, main.map((k) => actionButton(a, k))));
|
||||
if (side.length) box.append(el('div', { class: 'buttons side' }, side.map((k) => actionButton(a, k))));
|
||||
}
|
||||
if (state.error) box.append(el('p', { class: 'act-error', role: 'alert' }, state.error));
|
||||
return box;
|
||||
@@ -517,18 +540,32 @@
|
||||
|
||||
function needsYouCard() {
|
||||
const list = state.data.ajuan.filter((a) => a.needsYou);
|
||||
const card = el('div', { class: 'card' }, el('h2', {}, 'Perlu kamu'));
|
||||
const card = el('div', { class: 'card' });
|
||||
const head = el('div', { class: 'card-head' }, el('h2', {}, 'Perlu kamu'));
|
||||
if (phone.matches)
|
||||
head.append(el('button', { type: 'button', class: 'close', 'aria-label': 'Tutup', onclick: () => closeSheet(), html: '<svg width="16" height="16" viewBox="0 0 16 16" aria-hidden="true"><path d="M3 3l10 10M13 3L3 13" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>' }));
|
||||
card.append(head);
|
||||
if (!list.length) card.append(el('p', { class: 'note' }, state.data.viewer.approver ? 'Belum ada. Santai dulu.' : 'Nggak ada ajuanmu yang ditahan.'));
|
||||
else
|
||||
card.append(el('div', { class: 'todo-list' }, list.map((a) =>
|
||||
el('button', { type: 'button', class: 'todo-item', onclick: () => pick(a.id) },
|
||||
el('span', { class: 'dot', 'aria-hidden': 'true' }, el('i'), el('i')),
|
||||
el('strong', {}, a.label),
|
||||
el('span', { class: 'todo-copy' },
|
||||
el('strong', {}, a.label),
|
||||
a.title ? el('span', {}, shortTitle(a.title, 42)) : null,
|
||||
),
|
||||
el('span', { class: 'age' }, age(a.since)),
|
||||
))));
|
||||
return card;
|
||||
}
|
||||
|
||||
function sheetMode(a) {
|
||||
if (!phone.matches) return '';
|
||||
if (a) return 'detail';
|
||||
if (state.listOpen) return 'list';
|
||||
return 'closed';
|
||||
}
|
||||
|
||||
function drawShore() {
|
||||
const { data } = state;
|
||||
const a = data.ajuan.find((x) => x.id === state.sel);
|
||||
@@ -536,12 +573,27 @@
|
||||
// Keep a half-written Tunda or Tolak note across refreshes.
|
||||
if (a && state.composing && state.composing.id === a.id && document.activeElement && document.activeElement.id === 'decision-note') return;
|
||||
if (a && document.activeElement && document.activeElement.id === 'release-tag') return;
|
||||
const card = a ? detail(a) : needsYouCard();
|
||||
// Animate only when what the shore shows changes, not on every refresh.
|
||||
const key = a ? `a${a.id}` : 'todo';
|
||||
if (key === state.shown) card.classList.add('still');
|
||||
|
||||
const mode = sheetMode(a);
|
||||
const harbour = $('harbour');
|
||||
harbour.dataset.sheet = mode || 'closed';
|
||||
document.body.classList.toggle('sheet-open', mode === 'detail' || mode === 'list');
|
||||
const scrim = $('scrim');
|
||||
scrim.hidden = !(mode === 'detail' || mode === 'list');
|
||||
|
||||
let card = null;
|
||||
if (a) card = detail(a);
|
||||
else if (!phone.matches || state.listOpen) card = needsYouCard();
|
||||
|
||||
const key = a ? `a${a.id}` : state.listOpen || !phone.matches ? 'todo' : 'closed';
|
||||
if (card) {
|
||||
if (key === state.shown) card.classList.add('still');
|
||||
$('detail').replaceChildren(card);
|
||||
} else {
|
||||
$('detail').replaceChildren();
|
||||
}
|
||||
state.shown = key;
|
||||
$('detail').replaceChildren(card);
|
||||
|
||||
const mine = data.ajuan.filter((x) => x.needsYou).length;
|
||||
$('mine-count').textContent = mine;
|
||||
$('show-all').setAttribute('aria-pressed', String(state.filter === 'all'));
|
||||
@@ -583,6 +635,12 @@
|
||||
state.first = false;
|
||||
}
|
||||
|
||||
function closeSheet() {
|
||||
state.listOpen = false;
|
||||
if (state.sel) pick(null);
|
||||
else draw();
|
||||
}
|
||||
|
||||
function pick(id) {
|
||||
if (id !== state.sel) {
|
||||
state.composing = null;
|
||||
@@ -590,10 +648,11 @@
|
||||
state.releaseTag = null;
|
||||
}
|
||||
state.sel = id;
|
||||
if (id) state.listOpen = false;
|
||||
history.replaceState(null, '', id ? `#a${id}` : location.pathname);
|
||||
draw();
|
||||
// A new ajuan opens at its top: the sheet scrolls on a phone, the detail column on a laptop.
|
||||
if (id) (window.matchMedia('(max-width: 899px)').matches ? $('shore') : $('detail')).scrollTop = 0;
|
||||
if (id) $('detail').scrollTop = 0;
|
||||
}
|
||||
|
||||
async function load() {
|
||||
@@ -618,9 +677,27 @@
|
||||
drawSea();
|
||||
const m = location.hash.match(/^#a(\d+)$/);
|
||||
if (m) state.sel = Number(m[1]);
|
||||
$('show-all').addEventListener('click', () => { state.filter = 'all'; draw(); });
|
||||
$('show-mine').addEventListener('click', () => { state.filter = 'mine'; draw(); });
|
||||
document.addEventListener('keydown', (e) => { if (e.key === 'Escape' && state.sel) pick(null); });
|
||||
$('show-all').addEventListener('click', () => {
|
||||
state.filter = 'all';
|
||||
state.listOpen = false;
|
||||
draw();
|
||||
});
|
||||
$('show-mine').addEventListener('click', () => {
|
||||
state.filter = 'mine';
|
||||
// On a phone the list is a sheet; on a laptop it lives in the shore panel.
|
||||
if (phone.matches) {
|
||||
state.sel = null;
|
||||
state.listOpen = true;
|
||||
history.replaceState(null, '', location.pathname);
|
||||
}
|
||||
draw();
|
||||
});
|
||||
$('scrim').addEventListener('click', () => closeSheet());
|
||||
document.addEventListener('keydown', (e) => {
|
||||
if (e.key !== 'Escape') return;
|
||||
if (state.sel) pick(null);
|
||||
else if (state.listOpen) closeSheet();
|
||||
});
|
||||
load();
|
||||
// Faster while a Gas waits or a boat is sailing, so the harbour follows it.
|
||||
let last = 0;
|
||||
@@ -641,6 +718,12 @@
|
||||
}
|
||||
}, 1000);
|
||||
document.addEventListener('visibilitychange', () => { if (!document.hidden) load(); });
|
||||
window.addEventListener('resize', () => { drawnLanes = ''; if (state.data) drawLanes(); });
|
||||
window.addEventListener('resize', () => {
|
||||
drawnLanes = '';
|
||||
if (state.data) {
|
||||
if (!phone.matches) state.listOpen = false;
|
||||
draw();
|
||||
}
|
||||
});
|
||||
});
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user