feat(energy): Phase 3 — match-my-energy task sort + tri-state tag column
Closes Phase 3 of the 2026-04-23 feature-complete roadmap. Incorporates the Codex plan-review fixes from this session: profile-free index, tri- state update command, and de-prioritise-not-hide semantics. Storage (kon-storage): - Migration v11 adds `energy TEXT` to `tasks` with a CHECK constraint on `high | medium | brain_dead | NULL`. Index `(energy, created_at DESC)` — deliberately not per-profile because the tasks table carries no profile_id column yet (tracked as a separate gap in HANDOVER). - `TaskRow.energy: Option<String>` plus `task_row_from` read. - `insert_task` signature grows by one optional arg (`energy`). Allowed `too_many_arguments` with a rationale comment — the positional shape matches the column order and flipping to a params struct would have rippled through every caller for cosmetic benefit only. - New `set_task_energy(pool, id, Option<&str>) -> TaskRow`. Lives as its own function because `update_task` uses COALESCE to let `None` mean "preserve" — which would make clearing the tag impossible. - Two new tests: round-trip including explicit NULL clear, and CHECK constraint rejection of unknown values. - Tests updated for the v10 → v11 version bump. Tauri (src-tauri): - `TaskDto.energy`. `CreateTaskRequest.energy` (optional). Inline validation against the allowed set before hitting the DB, so frontend bugs surface as friendly errors instead of CHECK-constraint failures. - New `set_task_energy_cmd` command mirroring the storage tri-state API. Frontend (svelte): - `EnergyLevel` type added to `types/app.ts`. `TaskDto`, `TaskEntry`, and `TaskDraft` grow an `energy` field. - `SettingsState.currentEnergy` (persisted) + `matchMyEnergy` (persisted toggle). Defaults: null + false — no surface change until user opts in. - `setTaskEnergy(id, EnergyLevel | null)` action on the task store. Calls the dedicated Tauri command, updates local state, broadcasts to sibling windows. - `EnergyChip.svelte` — new component. Cycles unset → High → Medium → Brain-Dead → unset on click. Colour tokens: accent / warning / text-tertiary (deliberately not danger-red for Brain-Dead — the brief is explicit that this state must not feel pathologised). - Chip rendered on every task row in TasksPage and every row in WipTaskList. Hidden-until-hover when energy is unset so untagged rows stay calm; always visible once tagged because the colour is the signal. - Tasks page header gains a "I feel" segmented control and a "Match my energy" toggle. When both are active, matching tasks sort to the top — unset tasks are treated as Medium-equivalent. Nothing is ever hidden; this is a de-prioritisation, not a filter. Deferred / out of scope: - LLM-driven surfacing (brief says "The AI surfaces...") — deterministic client-side sort is v1; LLM layer is a later phase. - tasks.profile_id + per-profile energy sort — separate migration. All green: cargo build + 251 tests + clippy -D warnings (0 warnings) + fmt + svelte-check (0/0) + npm run build.
This commit is contained in:
@@ -1,14 +1,17 @@
|
||||
<script lang="ts">
|
||||
import { tick } from "svelte";
|
||||
import type { TaskBucket, TaskList } from "$lib/types/app";
|
||||
import type { EnergyLevel, TaskBucket, TaskEntry, TaskList } from "$lib/types/app";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import {
|
||||
tasks, addTask, completeTask, uncompleteTask, deleteTask, updateTask,
|
||||
setTaskEnergy,
|
||||
taskLists, addTaskList, renameTaskList, deleteTaskList,
|
||||
settings, saveSettings,
|
||||
} from "$lib/stores/page.svelte.js";
|
||||
import WipTaskList from '$lib/components/WipTaskList.svelte';
|
||||
import EmptyState from '$lib/components/EmptyState.svelte';
|
||||
import { SquareCheck, Search, ExternalLink, ChevronLeft, ArrowUpDown, Plus, X, ChevronRight } from 'lucide-svelte';
|
||||
import EnergyChip from '$lib/components/EnergyChip.svelte';
|
||||
import { SquareCheck, Search, ExternalLink, ChevronLeft, ArrowUpDown, Plus, X, ChevronRight, Zap } from 'lucide-svelte';
|
||||
import Card from "$lib/components/Card.svelte";
|
||||
import { formatTimestamp } from "$lib/utils/time.js";
|
||||
import { BUCKET_COLORS, EFFORT_LABELS, EFFORT_ORDER } from "$lib/utils/constants.js";
|
||||
@@ -47,6 +50,17 @@
|
||||
return EFFORT_LABELS[effort as keyof typeof EFFORT_LABELS] || effort;
|
||||
}
|
||||
|
||||
// Phase 3 energy sort: when the user has opted in and declared a
|
||||
// current energy, tasks matching that energy sort to the top. Tasks
|
||||
// with no energy tag are treated as Medium-equivalent, per the brief's
|
||||
// framing that unset is the normal case. Nothing is ever hidden —
|
||||
// "reserves" in the spec means de-prioritise, not filter.
|
||||
function energyMatchRank(task: TaskEntry, currentEnergy: EnergyLevel | null): number {
|
||||
if (!currentEnergy) return 0;
|
||||
const effective = task.energy ?? "medium";
|
||||
return effective === currentEnergy ? 0 : 1;
|
||||
}
|
||||
|
||||
let filteredTasks = $derived.by(() => {
|
||||
let list = tasks.filter((t) => !t.done);
|
||||
if (activeBucket !== "all") {
|
||||
@@ -68,9 +82,34 @@
|
||||
} else if (sortMode === "deep-first") {
|
||||
list.sort((a, b) => effortRank(b.effort) - effortRank(a.effort));
|
||||
}
|
||||
// Match-my-energy sort runs last (stable) so it reorders the result
|
||||
// of the effort-based sort rather than replacing it.
|
||||
if (settings.matchMyEnergy && settings.currentEnergy) {
|
||||
const energy = settings.currentEnergy;
|
||||
list.sort((a, b) => energyMatchRank(a, energy) - energyMatchRank(b, energy));
|
||||
}
|
||||
return list;
|
||||
});
|
||||
|
||||
function cycleCurrentEnergy(next: EnergyLevel | null) {
|
||||
settings.currentEnergy = next;
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
function toggleMatchMyEnergy() {
|
||||
settings.matchMyEnergy = !settings.matchMyEnergy;
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
function energyLabel(level: EnergyLevel | null): string {
|
||||
switch (level) {
|
||||
case "high": return "High";
|
||||
case "medium": return "Medium";
|
||||
case "brain_dead": return "Brain-Dead";
|
||||
default: return "Not set";
|
||||
}
|
||||
}
|
||||
|
||||
let completedTasks = $derived.by(() => {
|
||||
let list = tasks.filter((t) => t.done);
|
||||
if (activeBucket !== "all") {
|
||||
@@ -199,6 +238,49 @@
|
||||
<p class="text-[11px] text-text-tertiary mt-1">Add tasks manually. Automatic extraction from your transcripts is coming.</p>
|
||||
</div>
|
||||
<div class="flex-1"></div>
|
||||
|
||||
<!-- Phase 3 match-my-energy control. Three-state energy selector +
|
||||
toggle for the sort. Sits in the header so it is always visible
|
||||
from any bucket / list context. -->
|
||||
<div class="flex items-center gap-2 mr-2">
|
||||
<span class="text-[10px] text-text-tertiary hidden sm:inline" aria-hidden="true">I feel</span>
|
||||
<div class="flex items-center gap-0.5 bg-bg-input border border-border-subtle rounded-lg p-0.5"
|
||||
role="radiogroup"
|
||||
aria-label="My current energy">
|
||||
{#each [
|
||||
{ value: null, label: '—' },
|
||||
{ value: 'high' as EnergyLevel, label: 'High' },
|
||||
{ value: 'medium' as EnergyLevel, label: 'Med' },
|
||||
{ value: 'brain_dead' as EnergyLevel, label: 'Low' },
|
||||
] as opt}
|
||||
<button
|
||||
class="text-[10px] px-2 py-0.5 rounded-md
|
||||
{settings.currentEnergy === opt.value
|
||||
? 'bg-accent/15 text-accent'
|
||||
: 'text-text-tertiary hover:text-text-secondary'}"
|
||||
role="radio"
|
||||
aria-checked={settings.currentEnergy === opt.value}
|
||||
aria-label={opt.value ? `Set current energy to ${energyLabel(opt.value)}` : 'Clear current energy'}
|
||||
onclick={() => cycleCurrentEnergy(opt.value)}
|
||||
>{opt.label}</button>
|
||||
{/each}
|
||||
</div>
|
||||
<button
|
||||
class="flex items-center gap-1 btn-md rounded-lg text-[10px]
|
||||
{settings.matchMyEnergy
|
||||
? 'bg-accent/15 text-accent border border-accent/30'
|
||||
: 'text-text-tertiary hover:bg-hover hover:text-text border border-transparent'}"
|
||||
style="transition-duration: var(--duration-ui)"
|
||||
onclick={toggleMatchMyEnergy}
|
||||
aria-pressed={settings.matchMyEnergy}
|
||||
aria-label={settings.matchMyEnergy ? 'Match my energy is on — click to turn off' : 'Match my energy is off — click to turn on'}
|
||||
title="Sort matching tasks to the top (unset counts as Medium)"
|
||||
>
|
||||
<Zap size={12} aria-hidden="true" />
|
||||
Match my energy
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<button
|
||||
class="flex items-center gap-1.5 btn-md rounded-lg text-text-secondary hover:bg-hover hover:text-text"
|
||||
style="transition-duration: var(--duration-ui)"
|
||||
@@ -451,6 +533,13 @@
|
||||
onclick={() => setEffort(task.id, e)}
|
||||
>{effortLabel(e)}</button>
|
||||
{/each}
|
||||
<span class="text-border-subtle">·</span>
|
||||
<!-- Energy chip (Phase 3) -->
|
||||
<EnergyChip
|
||||
energy={task.energy}
|
||||
onSelect={(next) => setTaskEnergy(task.id, next)}
|
||||
size="md"
|
||||
/>
|
||||
<!-- Timestamp -->
|
||||
{#if task.createdAt}
|
||||
<span class="text-[10px] text-text-tertiary ml-auto">{formatTimestamp(task.createdAt)}</span>
|
||||
|
||||
Reference in New Issue
Block a user