Fix due date not updating correctly when removing it

This commit is contained in:
Vyn 2025-07-04 10:29:26 +02:00
parent 048d835bd6
commit 6acb97df79
Signed by: vyn
GPG key ID: E1B2BE34E7A971E7
3 changed files with 33 additions and 26 deletions

View file

@ -190,7 +190,11 @@ void app_logic::setup_callbacks()
const mirai::date &date = slint_date_to_mirai_date(newTaskData.date);
// const auto dayOpt = source->get_day_by_date(date);
task->set_title(std::string(newTaskData.title));
task->set_date(slint_date_to_mirai_date(newTaskData.date));
if (newTaskData.date.day == 0) {
task->unschedule();
} else {
task->set_date(slint_date_to_mirai_date(newTaskData.date));
}
_mirai_core->save();
update_views();
@ -391,18 +395,20 @@ get_all_tasks_from_sources(std::vector<std::unique_ptr<mirai::source>> &sources)
const auto &tasks = source->get_tasks();
all_tasks.insert(all_tasks.end(), tasks.begin(), tasks.end());
}
std::sort(all_tasks.begin(), all_tasks.end(), [](const mirai::task &t1, const mirai::task &t2) {
if (!t1.has_due_date() && !t2.has_due_date()) {
return false;
std::stable_sort(
all_tasks.begin(), all_tasks.end(), [](const mirai::task &t1, const mirai::task &t2) {
if (!t1.has_due_date() && !t2.has_due_date()) {
return false;
}
if (t1.has_due_date() && !t2.has_due_date()) {
return true;
}
if (!t1.has_due_date() && t2.has_due_date()) {
return false;
}
return t1.due_date() < t2.due_date();
}
if (t1.has_due_date() && !t2.has_due_date()) {
return true;
}
if (!t1.has_due_date() && t2.has_due_date()) {
return false;
}
return t1.due_date() < t2.due_date();
});
);
return all_tasks;
}