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,5 +1,6 @@
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import type {
|
||||
EnergyLevel,
|
||||
PageState,
|
||||
Profile,
|
||||
Segment,
|
||||
@@ -68,6 +69,8 @@ const defaults: SettingsState = {
|
||||
globalHotkey: "Ctrl+Shift+R",
|
||||
sidebarCollapsed: false,
|
||||
microphoneDevice: "",
|
||||
currentEnergy: null,
|
||||
matchMyEnergy: false,
|
||||
};
|
||||
|
||||
function canUseStorage(): boolean {
|
||||
@@ -314,6 +317,7 @@ function mapTaskRow(row: TaskDto): TaskEntry {
|
||||
createdAt: row.createdAt ?? new Date().toISOString(),
|
||||
sourceTranscriptId: row.sourceTranscriptId ?? null,
|
||||
parentTaskId: row.parentTaskId ?? null,
|
||||
energy: row.energy ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -352,6 +356,7 @@ export async function addTask(task: TaskDraft) {
|
||||
sourceTranscriptId: task.sourceTranscriptId || null,
|
||||
listId: task.listId ?? null,
|
||||
effort: task.effort ?? null,
|
||||
energy: task.energy ?? null,
|
||||
},
|
||||
});
|
||||
tasks.unshift(mapTaskRow(row));
|
||||
@@ -396,6 +401,29 @@ export async function updateTask(id: string, updates: TaskUpdate) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Phase 3: explicit tri-state energy setter. Lives outside `updateTask`
|
||||
* because the backend uses a dedicated command for clearing — see
|
||||
* `set_task_energy_cmd` in src-tauri/src/commands/tasks.rs. Pass `null`
|
||||
* to clear the tag entirely; pass an `EnergyLevel` string to set it.
|
||||
*/
|
||||
export async function setTaskEnergy(id: string, energy: EnergyLevel | null) {
|
||||
if (!hasTauriRuntime()) {
|
||||
applyLocalTaskUpdate(id, { energy });
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const row = await invoke<TaskDto>("set_task_energy_cmd", { id, energy });
|
||||
const idx = tasks.findIndex((task) => task.id === id);
|
||||
if (idx >= 0) {
|
||||
tasks[idx] = mapTaskRow(row);
|
||||
broadcastTasks();
|
||||
}
|
||||
} catch (err) {
|
||||
toasts.error("Couldn't change energy", errorMessage(err));
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteTask(id: string) {
|
||||
if (!hasTauriRuntime()) return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user