The three the handoff named as next. They are one commit because they are one mechanism: all three end in something being dragged, and a drop target cannot tell what is coming without the module they now share. Groups are foldable headings over the projects in the sidebar. A table rather than a `group_name` column on the project, because a group has to be renamable in one write, has to survive being emptied, and has to remember whether it is folded — none of which a string repeated on every project row can do. Folded state lives on the row, not in localStorage. The sidebar's *width* is a property of the screen you are sitting at, which is why that one is per browser; a folded group is a statement about the group — "this is the part of my work I am not in right now" — and it is true on the laptop and on the desktop. There is nobody else's answer to disagree with either: a group belongs to exactly one person. A shared project cannot be filed. `group_id` is a column on the project row, so a member grouping somebody else's project would move it in the owner's sidebar too — the same reason `sort_order` is owner-scoped. The listing reports the column only to the owner, so a viewer is never told where somebody else keeps it. Deleting a group takes the heading and leaves the projects, and the sidebar decides where a project renders by whether its group still exists rather than by the id alone. A group deleted in another tab arrives as one event and not one per project, so for a moment the projects still name a heading that is no longer drawn — filing by the raw id would drop them out of the sidebar entirely. Kommende gains the month grid the project pages already had, behind a Liste/Kalender toggle. The two views ask for different things — seven days from today against six whole weeks around an arbitrary month — so each loads its own, and the grid reports which dates it is showing rather than having the page guess. Which view is remembered in localStorage: a month of seven columns needs room, and the answer on a phone is not the answer on a wide monitor. And a task can now be dropped on a project in the sidebar, on a day in Kommende, or on a cell in any month grid. Onto a project it is a *move*, not a field: `sort_order` belongs to the project, so it has to find a place among that project's tasks and leave its old section behind. Each drag now carries its own MIME type. `getData` is deliberately unreadable while a drag is in the air — the browser hands the payload over on drop and not before, so a page cannot read what is being dragged across it — and `dataTransfer.types` is all a target has to decide with. Deciding is the point: calling preventDefault on a drag you cannot accept is what turns "no" into a silent, wrong drop. The sidebar takes a project and a task on the same row and has to tell them apart. Two things fell out of building it. The month grid has always had one cell narrower than the other six: `.today` styled the "I dag" button in the header, and the day cell for today wears the same class, so `margin-left: auto` was shrinking a grid item to its content. It is scoped to the header now. And a project page listed whatever was in the store rather than what belonged to that project, which did not matter until a task could leave a project while you were looking at it. Covered by eight new API tests and two new smoke tests, and the smoke tests drive the drags for real — the type check they exercise exists only while a drag is in flight, so nothing else can reach it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
228 lines
5.7 KiB
Svelte
228 lines
5.7 KiB
Svelte
<script>
|
|
/**
|
|
* Kanban: one column per section, plus one for everything not filed under a
|
|
* section. Dragging a card between columns moves the task.
|
|
*
|
|
* The drag uses the native HTML drag-and-drop API rather than pointer events.
|
|
* It is fiddlier to style, but it is the one that works with a trackpad, a
|
|
* mouse and a screen reader's drag affordance without reimplementing any of
|
|
* them — and it gives keyboard users the browser's own behaviour for free.
|
|
*/
|
|
import { app } from '$lib/stores.svelte.js';
|
|
import { api } from '$lib/api.js';
|
|
import { TASK, startDrag, carries, accept } from '$lib/dnd.js';
|
|
import TaskRow from './TaskRow.svelte';
|
|
|
|
let { project, sections, canEdit } = $props();
|
|
|
|
let draggingId = $state(null);
|
|
let overColumn = $state(null);
|
|
|
|
// The unsectioned column comes first, as it does in the list view: it is where
|
|
// quick add puts things, so it is where new work appears.
|
|
let columns = $derived([
|
|
{ id: '', name: 'Uden sektion' },
|
|
...sections.map((s) => ({ id: s.id, name: s.name }))
|
|
]);
|
|
|
|
// Scoped to this project, not just to the section: the store holds whatever the
|
|
// last view loaded, and a task that has left the project would otherwise turn
|
|
// up in the "no section" column, which is exactly where a task with no section
|
|
// belongs — in some other project.
|
|
const tasksIn = (sectionId) =>
|
|
app.tasks
|
|
.filter(
|
|
(t) =>
|
|
!t.completed &&
|
|
!t.parent_id &&
|
|
t.project_id === project.id &&
|
|
(t.section_id ?? '') === sectionId
|
|
)
|
|
.sort((a, b) => a.sort_order - b.sort_order);
|
|
|
|
function onDragStart(event, task) {
|
|
if (!canEdit) return;
|
|
draggingId = task.id;
|
|
startDrag(event, TASK, task.id);
|
|
}
|
|
|
|
function onDragOver(event, sectionId) {
|
|
if (!canEdit || !carries(event, TASK) || !draggingId) return;
|
|
accept(event);
|
|
overColumn = sectionId;
|
|
}
|
|
|
|
async function onDrop(event, sectionId) {
|
|
event.preventDefault();
|
|
overColumn = null;
|
|
const id = draggingId;
|
|
draggingId = null;
|
|
if (!id || !canEdit) return;
|
|
|
|
const task = app.get(id);
|
|
if (!task || (task.section_id ?? '') === sectionId) return;
|
|
|
|
// Optimistic: the card is in the new column before the request goes out,
|
|
// because a card that snaps back for 200ms reads as a failed drop.
|
|
const previous = { ...task };
|
|
app.replace(id, { ...task, section_id: sectionId });
|
|
|
|
try {
|
|
// Dropped at the end of the column: the task after it is nothing, and
|
|
// the one before it is whatever was last there.
|
|
const existing = tasksIn(sectionId).filter((t) => t.id !== id);
|
|
const after = existing.at(-1);
|
|
app.replace(
|
|
id,
|
|
await api.moveTask(id, {
|
|
project_id: project.id,
|
|
section_id: sectionId,
|
|
after_id: after?.id ?? ''
|
|
})
|
|
);
|
|
} catch {
|
|
app.replace(id, previous);
|
|
app.toast('Kunne ikke flytte opgaven.');
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<div class="board">
|
|
{#each columns as column (column.id)}
|
|
{@const tasks = tasksIn(column.id)}
|
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
<section
|
|
class="column"
|
|
class:over={overColumn === column.id}
|
|
ondragover={(e) => onDragOver(e, column.id)}
|
|
ondragleave={() => (overColumn = null)}
|
|
ondrop={(e) => onDrop(e, column.id)}
|
|
>
|
|
<header>
|
|
<h2>{column.name}</h2>
|
|
<span class="count">{tasks.length}</span>
|
|
</header>
|
|
|
|
<div class="cards">
|
|
{#each tasks as task (task.id)}
|
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
<div
|
|
class="card"
|
|
class:dragging={draggingId === task.id}
|
|
draggable={canEdit}
|
|
ondragstart={(e) => onDragStart(e, task)}
|
|
ondragend={() => (draggingId = null)}
|
|
>
|
|
<TaskRow {task} />
|
|
</div>
|
|
{/each}
|
|
|
|
{#if !tasks.length}
|
|
<p class="empty">Tom</p>
|
|
{/if}
|
|
</div>
|
|
</section>
|
|
{/each}
|
|
</div>
|
|
|
|
<style>
|
|
.board {
|
|
display: flex;
|
|
gap: var(--s3);
|
|
align-items: flex-start;
|
|
overflow-x: auto;
|
|
padding-bottom: var(--s4);
|
|
/* Columns snap as you swipe on a phone, so a half-column never sits at
|
|
the edge looking like a rendering fault. */
|
|
scroll-snap-type: x proximity;
|
|
}
|
|
|
|
.column {
|
|
flex: 0 0 300px;
|
|
max-width: 300px;
|
|
background: var(--surface-sunken);
|
|
border: 1px solid var(--line);
|
|
border-radius: var(--radius-lg);
|
|
padding: var(--s3);
|
|
scroll-snap-align: start;
|
|
transition: border-color var(--fast) var(--ease);
|
|
}
|
|
|
|
/* The drop target is shown by the column it would land in, not by a line
|
|
between cards: the column is the decision being made here. */
|
|
.column.over {
|
|
border-color: var(--accent);
|
|
background: var(--accent-sunken);
|
|
}
|
|
|
|
header {
|
|
display: flex;
|
|
align-items: baseline;
|
|
justify-content: space-between;
|
|
gap: var(--s2);
|
|
padding: 0 var(--s2) var(--s3);
|
|
}
|
|
|
|
h2 {
|
|
font-size: var(--text-xs);
|
|
font-weight: 560;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.06em;
|
|
color: var(--ink-faint);
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
white-space: nowrap;
|
|
}
|
|
|
|
.count {
|
|
font-size: var(--text-xs);
|
|
color: var(--ink-faint);
|
|
flex: none;
|
|
}
|
|
|
|
.cards {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: var(--s2);
|
|
min-height: 60px;
|
|
}
|
|
|
|
.card {
|
|
background: var(--surface);
|
|
border: 1px solid var(--line);
|
|
border-radius: var(--radius);
|
|
padding: 0 var(--s2);
|
|
cursor: grab;
|
|
transition:
|
|
opacity var(--fast) var(--ease),
|
|
border-color var(--fast) var(--ease);
|
|
}
|
|
|
|
.card:hover {
|
|
border-color: var(--line-strong);
|
|
}
|
|
|
|
.card.dragging {
|
|
opacity: 0.4;
|
|
cursor: grabbing;
|
|
}
|
|
|
|
/* The row draws its own bottom border for the list view, which is a stray
|
|
line inside a card. */
|
|
.card :global(.row) {
|
|
border-bottom: none;
|
|
}
|
|
|
|
.card :global(.row:hover) {
|
|
background: transparent;
|
|
}
|
|
|
|
.empty {
|
|
margin: 0;
|
|
padding: var(--s3) var(--s2);
|
|
color: var(--ink-faint);
|
|
font-size: var(--text-sm);
|
|
text-align: center;
|
|
}
|
|
</style>
|