mirror of
https://codeberg.org/vyn/mirai.git
synced 2025-07-05 19:13:20 +00:00
Fix due date not updating correctly when removing it
This commit is contained in:
parent
048d835bd6
commit
6acb97df79
3 changed files with 33 additions and 26 deletions
|
@ -110,18 +110,20 @@ std::string markdown_data_provider::to_markdown()
|
||||||
int next_task_index = 0;
|
int next_task_index = 0;
|
||||||
int next_event_index = 0;
|
int next_event_index = 0;
|
||||||
|
|
||||||
std::sort(_data.tasks.begin(), _data.tasks.end(), [](const task_data &t1, const task_data &t2) {
|
std::stable_sort(
|
||||||
if (!t1.due_date.has_value() && !t2.due_date.has_value()) {
|
_data.tasks.begin(), _data.tasks.end(), [](const task_data &t1, const task_data &t2) {
|
||||||
return false;
|
if (!t1.due_date.has_value() && !t2.due_date.has_value()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (t1.due_date.has_value() && !t2.due_date.has_value()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!t1.due_date.has_value() && t2.due_date.has_value()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return t1.due_date < t2.due_date;
|
||||||
}
|
}
|
||||||
if (t1.due_date.has_value() && !t2.due_date.has_value()) {
|
);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!t1.due_date.has_value() && t2.due_date.has_value()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return t1.due_date < t2.due_date;
|
|
||||||
});
|
|
||||||
|
|
||||||
while (next_event_index < _data.events.size() || next_task_index < _data.tasks.size()) {
|
while (next_event_index < _data.events.size() || next_task_index < _data.tasks.size()) {
|
||||||
std::optional<class date> current_date = std::nullopt;
|
std::optional<class date> current_date = std::nullopt;
|
||||||
|
|
5
external/mirai-core/src/task.cpp
vendored
5
external/mirai-core/src/task.cpp
vendored
|
@ -58,14 +58,13 @@ void task::set_title(const std::string &newTitle)
|
||||||
|
|
||||||
void task::set_date(const date &date)
|
void task::set_date(const date &date)
|
||||||
{
|
{
|
||||||
auto emptyEventId = std::optional<std::optional<int>>(std::optional<int>(std::nullopt));
|
|
||||||
data_->update_task(id(), {.due_date = date});
|
data_->update_task(id(), {.due_date = date});
|
||||||
}
|
}
|
||||||
|
|
||||||
void task::unschedule()
|
void task::unschedule()
|
||||||
{
|
{
|
||||||
auto emptyId = std::optional<std::optional<int>>(std::optional<int>(std::nullopt));
|
const std::optional<date> new_date = std::nullopt;
|
||||||
data_->update_task(id(), {.due_date = std::nullopt});
|
data_->update_task(id(), {.due_date = new_date});
|
||||||
}
|
}
|
||||||
|
|
||||||
void task::set_checked(bool checked)
|
void task::set_checked(bool checked)
|
||||||
|
|
|
@ -190,7 +190,11 @@ void app_logic::setup_callbacks()
|
||||||
const mirai::date &date = slint_date_to_mirai_date(newTaskData.date);
|
const mirai::date &date = slint_date_to_mirai_date(newTaskData.date);
|
||||||
// const auto dayOpt = source->get_day_by_date(date);
|
// const auto dayOpt = source->get_day_by_date(date);
|
||||||
task->set_title(std::string(newTaskData.title));
|
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();
|
_mirai_core->save();
|
||||||
update_views();
|
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();
|
const auto &tasks = source->get_tasks();
|
||||||
all_tasks.insert(all_tasks.end(), tasks.begin(), tasks.end());
|
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) {
|
std::stable_sort(
|
||||||
if (!t1.has_due_date() && !t2.has_due_date()) {
|
all_tasks.begin(), all_tasks.end(), [](const mirai::task &t1, const mirai::task &t2) {
|
||||||
return false;
|
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;
|
return all_tasks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue