Skip to content

Commit 5b3f8a6

Browse files
committed
fix: stop storing the UI's "no priority" sentinels as literal priorities
Taskwarrior priorities are H, M and L. The app was writing two other values into the replica: - the add sheet's "no priority" chip is the string 'X', and all three save handlers sent it as-is — so every task created without a priority carried priority "X", which the desktop CLI renders as a priority that does not exist and urgency scoring ignores - the detail screen's None option is the string 'None', and the save guard was `isNotEmpty` — which "None" passes — so choosing None stored the word "None" Worse, priority could not be cleared at all: sending null just drops the key from the payload (the recur trap again), and TaskChampion's set_priority always stores its argument, so even an empty string would persist as a blank-valued property rather than removing one. - all three add handlers translate 'X' to unset - the detail screen translates 'None' to an empty string, and the FFI treats empty as removal (set_value None) in update_task and as "not set" in add_task - on load, '', 'X' and 'None' all normalise to the None option — so a task polluted by an older build renders correctly, sits on a real radio button instead of leaving the picker with nothing selected, and gets scrubbed from the replica the next time it is saved Tested: three new Rust tests (35 pass) — empty at creation stores nothing, empty on update removes the property, real priorities still round-trip. Verified on device: a task that had stored "X" shows None with the None radio selected; set to M, saved, cleared to None, saved, reopened — still None.
1 parent 5d3d16f commit 5b3f8a6

6 files changed

Lines changed: 118 additions & 7 deletions

File tree

512 Bytes
Binary file not shown.
176 Bytes
Binary file not shown.
128 Bytes
Binary file not shown.

‎lib/app/modules/home/views/add_task_bottom_sheet_new.dart‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,10 @@ class AddTaskBottomSheet extends StatelessWidget {
342342
var task = TaskForC(
343343
description: homeController.namecontroller.text.trim(),
344344
status: 'pending',
345-
priority: homeController.priority.value,
345+
// 'X' is the "no priority" chip, not a priority — leave unset.
346+
priority: homeController.priority.value == 'X'
347+
? null
348+
: homeController.priority.value,
346349
entry: DateTime.now().toIso8601String(),
347350
id: 0,
348351
project: homeController.projectcontroller.text != ""
@@ -392,7 +395,11 @@ class AddTaskBottomSheet extends StatelessWidget {
392395
var task = taskParser(homeController.namecontroller.text.trim())
393396
.rebuild((b) =>
394397
b..due = getDueDate(homeController.selectedDates)?.toUtc())
395-
.rebuild((p) => p..priority = homeController.priority.value)
398+
.rebuild((p) => p
399+
// 'X' is the "no priority" chip, not a priority — leave unset.
400+
..priority = homeController.priority.value == 'X'
401+
? null
402+
: homeController.priority.value)
396403
.rebuild((t) => t..project = homeController.projectcontroller.text)
397404
.rebuild((t) =>
398405
t..wait = getWaitDate(homeController.selectedDates)?.toUtc())
@@ -480,7 +487,12 @@ class AddTaskBottomSheet extends StatelessWidget {
480487
await Replica.addTaskToReplica(HashMap<String, dynamic>.from({
481488
"description": homeController.namecontroller.text.trim(),
482489
"due": getDueDate(homeController.selectedDates)?.toUtc(),
483-
"priority": homeController.priority.value,
490+
// 'X' is the "no priority" chip, a UI sentinel — it used to be sent
491+
// as-is and stored as a literal priority the desktop CLI has no idea
492+
// what to do with (Taskwarrior priorities are H, M and L).
493+
"priority": homeController.priority.value == 'X'
494+
? null
495+
: homeController.priority.value,
484496
"project": homeController.projectcontroller.text != ""
485497
? homeController.projectcontroller.text
486498
: null,

‎lib/app/modules/taskc_details/controllers/taskc_details_controller.dart‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ class TaskcDetailsController extends GetxController {
7272
description = (task.description ?? '').obs;
7373
project = (task.project ?? 'None').obs;
7474
status = (task.status ?? '').obs;
75-
priority = (task.priority ?? 'None').obs;
75+
// Normalise the sentinels older builds stored as literal priorities ('X'
76+
// from the add sheet's "no priority" chip, 'None' from this screen) so
77+
// they render as None, sit on a real radio option, and get cleared from
78+
// the replica on the next save.
79+
priority = _displayPriority(task.priority).obs;
7680
// TaskForReplica stores epoch seconds; convert to ISO string for formatting
7781
debugPrint('Replica task due: ${task.due}');
7882
due = formatDate(task.due).obs;
@@ -497,6 +501,13 @@ class TaskcDetailsController extends GetxController {
497501
previousTags.removeWhere((item) => itemsToMove.contains(item));
498502
}
499503

504+
static String _displayPriority(String? stored) {
505+
if (stored == null || stored.isEmpty || stored == 'X' || stored == 'None') {
506+
return 'None';
507+
}
508+
return stored;
509+
}
510+
500511
Future<void> saveTask() async {
501512
bool is24hrFormat = AppSettings.use24HourFormatRx.value;
502513
final datePattern = is24hrFormat
@@ -587,7 +598,11 @@ class TaskcDetailsController extends GetxController {
587598
description: description.string.isNotEmpty ? description.string : null,
588599
tags: tags.isNotEmpty ? tags.toList() : null,
589600
uuid: initialTask.uuid ?? '',
590-
priority: priority.string.isNotEmpty ? priority.string : null,
601+
// 'None' maps to an empty string, which the FFI treats as removal —
602+
// null would simply drop the key from the payload, so picking None
603+
// used to store the literal string "None" and a clear never
604+
// transmitted (the same trap recur had).
605+
priority: priority.string == 'None' ? '' : priority.string,
591606
project: project.string != 'None' ? project.string : null,
592607
// Sent as part of the same edit rather than as its own write, because
593608
// the FFI validates recurrence against the due date — and the user may

‎rust/src/api.rs‎

Lines changed: 86 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,17 @@ fn update_task_impl(
135135
let _ = t.set_wait(parse_datetime(&value), &mut ops);
136136
}
137137
"priority" => {
138-
let _ = t.set_priority(value, &mut ops);
138+
// Empty clears, mirroring `recur`. set_priority always
139+
// stores its argument, so a clear must remove the property
140+
// outright — an empty-string "priority" is still a value,
141+
// and sending null from Dart never transmits at all (the
142+
// key is simply absent from the map).
143+
let trimmed = value.trim();
144+
if trimmed.is_empty() {
145+
let _ = t.set_value("priority", None, &mut ops);
146+
} else {
147+
let _ = t.set_priority(trimmed.to_string(), &mut ops);
148+
}
139149
}
140150
"tags" => {
141151
let existing_tags: Vec<String> = t
@@ -257,7 +267,12 @@ fn add_task_impl(taskdb_dir_path: &str, map: HashMap<String, String>) -> Result<
257267
let _ = t.set_wait(parse_datetime(&value), &mut ops);
258268
}
259269
"priority" => {
260-
let _ = t.set_priority(value, &mut ops);
270+
// Nothing to clear on a brand-new task, so empty means "not
271+
// set" rather than a removal.
272+
let trimmed = value.trim();
273+
if !trimmed.is_empty() {
274+
let _ = t.set_priority(trimmed.to_string(), &mut ops);
275+
}
261276
}
262277
"tags" => {
263278
for part in value.split_whitespace() {
@@ -1471,3 +1486,72 @@ mod add_task_attribute_tests {
14711486
fs::remove_dir_all(&tmp).ok();
14721487
}
14731488
}
1489+
1490+
#[cfg(test)]
1491+
mod priority_tests {
1492+
//! Priority used to be write-only in practice: set_priority always stores
1493+
//! its argument, so the UI sentinels ('X', 'None') were stored as literal
1494+
//! priorities and there was no way to transmit a clear at all.
1495+
use super::*;
1496+
use serde_json::Value;
1497+
use std::{collections::HashMap, env, fs};
1498+
1499+
fn fixture(priority: Option<&str>) -> (std::path::PathBuf, String, String) {
1500+
let tmp = env::temp_dir().join(format!("taskdb_prio_{}", Uuid::new_v4()));
1501+
fs::create_dir_all(&tmp).expect("create temp taskdb dir");
1502+
let path = tmp.to_string_lossy().into_owned();
1503+
1504+
let uuid = Uuid::new_v4().to_string();
1505+
let mut map: HashMap<String, String> = HashMap::new();
1506+
map.insert("uuid".to_string(), uuid.clone());
1507+
map.insert("description".to_string(), "chore".to_string());
1508+
if let Some(p) = priority {
1509+
map.insert("priority".to_string(), p.to_string());
1510+
}
1511+
add_task(path.clone(), map).expect("add_task");
1512+
(tmp, path, uuid)
1513+
}
1514+
1515+
fn priority_of(path: &str, uuid: &str) -> Option<String> {
1516+
let json = get_all_tasks_json(path.to_string()).expect("get_all_tasks_json");
1517+
let tasks: Vec<Value> = serde_json::from_str(&json).expect("parse json");
1518+
tasks
1519+
.into_iter()
1520+
.find(|t| t.get("uuid").and_then(|u| u.as_str()) == Some(uuid))
1521+
.expect("task exists")
1522+
.get("priority")
1523+
.and_then(|v| v.as_str().map(|s| s.to_string()))
1524+
}
1525+
1526+
#[test]
1527+
fn empty_priority_at_creation_is_not_stored() {
1528+
let (tmp, path, uuid) = fixture(Some(""));
1529+
assert_eq!(priority_of(&path, &uuid), None);
1530+
fs::remove_dir_all(&tmp).ok();
1531+
}
1532+
1533+
#[test]
1534+
fn empty_priority_on_update_removes_the_property() {
1535+
let (tmp, path, uuid) = fixture(Some("M"));
1536+
assert_eq!(priority_of(&path, &uuid).as_deref(), Some("M"));
1537+
1538+
let mut map: HashMap<String, String> = HashMap::new();
1539+
map.insert("priority".to_string(), "".to_string());
1540+
update_task(uuid.clone(), path.clone(), map).expect("update_task");
1541+
1542+
// Removed outright — not left behind as an empty-string property the
1543+
// desktop CLI would still render as a (blank) priority.
1544+
assert_eq!(priority_of(&path, &uuid), None);
1545+
fs::remove_dir_all(&tmp).ok();
1546+
}
1547+
1548+
#[test]
1549+
fn a_real_priority_still_round_trips() {
1550+
let (tmp, path, uuid) = fixture(None);
1551+
let mut map: HashMap<String, String> = HashMap::new();
1552+
map.insert("priority".to_string(), "H".to_string());
1553+
update_task(uuid.clone(), path.clone(), map).expect("update_task");
1554+
assert_eq!(priority_of(&path, &uuid).as_deref(), Some("H"));
1555+
fs::remove_dir_all(&tmp).ok();
1556+
}
1557+
}

0 commit comments

Comments
 (0)