Files
priority-horizon/public/index.html
2026-02-26 03:05:45 +00:00

361 lines
10 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Priority Horizon</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=Caveat:wght@400;600&family=Inter:wght@300;400;500&display=swap');
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: 'Inter', sans-serif;
background: #f5f0e8;
min-height: 100vh;
color: #3a3330;
}
header {
text-align: center;
padding: 2rem 1rem 1rem;
}
header h1 {
font-family: 'Caveat', cursive;
font-size: 2.4rem;
font-weight: 600;
color: #5a4a3a;
letter-spacing: 0.02em;
}
header p {
font-size: 0.8rem;
color: #9a8a7a;
margin-top: 0.25rem;
font-weight: 300;
}
.board {
display: flex;
gap: 1.25rem;
padding: 1rem 1.5rem 2rem;
max-width: 1200px;
margin: 0 auto;
align-items: flex-start;
}
.column {
flex: 1;
min-width: 0;
}
.column-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 0.75rem;
padding: 0 0.25rem;
}
.column-header h2 {
font-family: 'Caveat', cursive;
font-size: 1.5rem;
font-weight: 600;
}
.col-now .column-header h2 { color: #c44; }
.col-soon .column-header h2 { color: #b87a2a; }
.col-eventually .column-header h2 { color: #5a8a5a; }
.add-btn {
background: none;
border: 1.5px dashed #ccc;
border-radius: 50%;
width: 28px; height: 28px;
font-size: 1.2rem;
color: #aaa;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.2s;
line-height: 1;
}
.add-btn:hover { border-color: #999; color: #666; background: rgba(0,0,0,0.03); }
.notes-list {
min-height: 60px;
display: flex;
flex-direction: column;
gap: 0.6rem;
}
.notes-list.drag-over { background: rgba(0,0,0,0.03); border-radius: 12px; }
.note {
background: #fffdf5;
border-radius: 6px;
padding: 0.75rem 0.9rem;
box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 1px rgba(0,0,0,0.04);
cursor: grab;
position: relative;
transition: box-shadow 0.2s, transform 0.15s;
user-select: none;
}
.note:hover { box-shadow: 0 3px 8px rgba(0,0,0,0.1); }
.note.dragging { opacity: 0.5; transform: rotate(2deg); }
.col-now .note { border-left: 3px solid #e8a0a0; }
.col-soon .note { border-left: 3px solid #e8c88a; }
.col-eventually .note { border-left: 3px solid #a0c8a0; }
.note-text {
font-size: 0.88rem;
line-height: 1.45;
min-height: 1.3em;
outline: none;
word-break: break-word;
}
.note-text:focus {
background: #fefcf0;
border-radius: 3px;
padding: 2px 4px;
margin: -2px -4px;
}
.note-text[contenteditable="true"] { cursor: text; }
.note-delete {
position: absolute;
top: 4px; right: 6px;
background: none;
border: none;
color: #ccc;
font-size: 0.85rem;
cursor: pointer;
opacity: 0;
transition: opacity 0.15s, color 0.15s;
padding: 2px 4px;
}
.note:hover .note-delete { opacity: 1; }
.note-delete:hover { color: #c44; }
/* Mobile */
@media (max-width: 700px) {
.board { flex-direction: column; padding: 0.75rem; gap: 1.5rem; }
.column { width: 100%; }
header h1 { font-size: 2rem; }
.note-delete { opacity: 0.6; }
}
</style>
</head>
<body>
<header>
<h1>Priority Horizon</h1>
<p>drag to reorder · click to edit</p>
</header>
<div class="board" id="board"></div>
<script>
const COLUMNS = [
{ key: 'now', label: 'Now' },
{ key: 'soon', label: 'Soon' },
{ key: 'eventually', label: 'Eventually' }
];
let dragItem = null;
async function api(path, opts = {}) {
const res = await fetch('/api' + path, {
headers: { 'Content-Type': 'application/json' },
...opts,
body: opts.body ? JSON.stringify(opts.body) : undefined
});
return res.json();
}
function createNoteEl(note, colKey) {
const el = document.createElement('div');
el.className = 'note';
el.draggable = true;
el.dataset.id = note.id;
const text = document.createElement('div');
text.className = 'note-text';
text.contentEditable = true;
text.textContent = note.text;
text.addEventListener('focus', () => el.draggable = false);
text.addEventListener('blur', async () => {
el.draggable = true;
const newText = text.textContent.trim();
if (newText && newText !== note.text) {
note.text = newText;
await api('/notes/' + note.id, { method: 'PATCH', body: { text: newText } });
} else if (!newText) {
text.textContent = note.text;
}
});
text.addEventListener('keydown', e => {
if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); text.blur(); }
});
const del = document.createElement('button');
del.className = 'note-delete';
del.textContent = '✕';
del.onclick = async () => {
el.style.transform = 'scale(0.9)'; el.style.opacity = '0';
setTimeout(() => el.remove(), 150);
await api('/notes/' + note.id, { method: 'DELETE' });
};
el.appendChild(text);
el.appendChild(del);
el.addEventListener('dragstart', e => {
dragItem = { el, id: note.id, fromCol: colKey };
el.classList.add('dragging');
e.dataTransfer.effectAllowed = 'move';
});
el.addEventListener('dragend', () => {
el.classList.remove('dragging');
dragItem = null;
});
return el;
}
async function render() {
const data = await api('/notes');
const board = document.getElementById('board');
board.innerHTML = '';
COLUMNS.forEach(col => {
const colEl = document.createElement('div');
colEl.className = 'column col-' + col.key;
const header = document.createElement('div');
header.className = 'column-header';
const h2 = document.createElement('h2');
h2.textContent = col.label;
const addBtn = document.createElement('button');
addBtn.className = 'add-btn';
addBtn.textContent = '+';
addBtn.onclick = async () => {
const note = await api('/notes', { method: 'POST', body: { column: col.key, text: 'New note...' } });
const noteEl = createNoteEl(note, col.key);
list.appendChild(noteEl);
const textEl = noteEl.querySelector('.note-text');
textEl.focus();
document.execCommand('selectAll');
};
header.appendChild(h2);
header.appendChild(addBtn);
const list = document.createElement('div');
list.className = 'notes-list';
list.dataset.column = col.key;
list.addEventListener('dragover', e => {
e.preventDefault();
e.dataTransfer.dropEffect = 'move';
list.classList.add('drag-over');
// Position indicator
const afterEl = getDragAfterElement(list, e.clientY);
const dragging = document.querySelector('.dragging');
if (dragging) {
if (afterEl) list.insertBefore(dragging, afterEl);
else list.appendChild(dragging);
}
});
list.addEventListener('dragleave', () => list.classList.remove('drag-over'));
list.addEventListener('drop', async e => {
e.preventDefault();
list.classList.remove('drag-over');
if (!dragItem) return;
// Save new order
const items = [];
document.querySelectorAll('.notes-list').forEach(nl => {
const colKey = nl.dataset.column;
nl.querySelectorAll('.note').forEach((n, i) => {
items.push({ id: parseInt(n.dataset.id), column: colKey, order: i });
});
});
await api('/reorder', { method: 'PUT', body: { items } });
});
(data[col.key] || []).forEach(note => {
list.appendChild(createNoteEl(note, col.key));
});
colEl.appendChild(header);
colEl.appendChild(list);
board.appendChild(colEl);
});
}
function getDragAfterElement(container, y) {
const els = [...container.querySelectorAll('.note:not(.dragging)')];
return els.reduce((closest, child) => {
const box = child.getBoundingClientRect();
const offset = y - box.top - box.height / 2;
if (offset < 0 && offset > closest.offset) return { offset, element: child };
return closest;
}, { offset: Number.NEGATIVE_INFINITY }).element;
}
// Touch drag support for mobile
let touchDragEl = null, touchClone = null, touchStartY = 0, touchStartX = 0;
document.addEventListener('touchstart', e => {
const note = e.target.closest('.note');
if (!note || e.target.closest('.note-text:focus') || e.target.closest('.note-delete')) return;
touchStartX = e.touches[0].clientX;
touchStartY = e.touches[0].clientY;
touchDragEl = note;
}, { passive: true });
document.addEventListener('touchmove', e => {
if (!touchDragEl) return;
const dx = e.touches[0].clientX - touchStartX;
const dy = e.touches[0].clientY - touchStartY;
if (!touchClone && (Math.abs(dx) > 10 || Math.abs(dy) > 10)) {
touchClone = touchDragEl.cloneNode(true);
touchClone.style.cssText = 'position:fixed;pointer-events:none;z-index:1000;opacity:0.8;width:' + touchDragEl.offsetWidth + 'px;transform:rotate(2deg);';
document.body.appendChild(touchClone);
touchDragEl.style.opacity = '0.3';
}
if (touchClone) {
e.preventDefault();
touchClone.style.left = (e.touches[0].clientX - 20) + 'px';
touchClone.style.top = (e.touches[0].clientY - 20) + 'px';
}
}, { passive: false });
document.addEventListener('touchend', async e => {
if (!touchClone || !touchDragEl) { touchDragEl = null; return; }
const x = e.changedTouches[0].clientX, y = e.changedTouches[0].clientY;
touchClone.remove(); touchClone = null;
touchDragEl.style.opacity = '1';
// Find target column
const lists = document.querySelectorAll('.notes-list');
let targetList = null;
lists.forEach(l => {
const r = l.getBoundingClientRect();
if (x >= r.left && x <= r.right && y >= r.top - 50 && y <= r.bottom + 50) targetList = l;
});
if (targetList) {
const afterEl = getDragAfterElement(targetList, y);
if (afterEl) targetList.insertBefore(touchDragEl, afterEl);
else targetList.appendChild(touchDragEl);
// Save
const items = [];
document.querySelectorAll('.notes-list').forEach(nl => {
nl.querySelectorAll('.note').forEach((n, i) => {
items.push({ id: parseInt(n.dataset.id), column: nl.dataset.column, order: i });
});
});
await api('/reorder', { method: 'PUT', body: { items } });
}
touchDragEl = null;
});
render();
</script>
</body>
</html>