mirror of
https://codeberg.org/vyn/mirai.git
synced 2025-07-01 17:03:19 +00:00
Fix tasks being unscheduled if the day for the task already exists
This commit is contained in:
parent
dee7a6fa42
commit
3e7c9b150a
6 changed files with 26 additions and 6 deletions
|
@ -25,6 +25,7 @@ class Task
|
|||
mirai::TaskState state() const;
|
||||
bool checked() const;
|
||||
bool hasEvent() const;
|
||||
bool hasDate() const;
|
||||
|
||||
void setTitle(const std::string &newTitle);
|
||||
void setDay(const Day &day);
|
||||
|
|
|
@ -128,9 +128,14 @@ std::string MarkdownDataProvider::toMarkdown()
|
|||
|
||||
for (const auto &day : days) {
|
||||
auto &date = day.date;
|
||||
auto tasks = getTasksByDayId(day.id);
|
||||
auto events = getEventsByDate(date);
|
||||
if (tasks.size() == 0 && events.size() == 0) {
|
||||
continue;
|
||||
}
|
||||
result +=
|
||||
"## " + std::format("{:02d}-{:02d}-{:02d}", date.year, date.month, date.day) + "\n\n";
|
||||
for (auto event : getEventsByDate(date)) {
|
||||
for (auto event : events) {
|
||||
auto &start = event.startsAt;
|
||||
auto &end = event.endsAt;
|
||||
result += "> " +
|
||||
|
@ -144,7 +149,7 @@ std::string MarkdownDataProvider::toMarkdown()
|
|||
}
|
||||
result += '\n';
|
||||
}
|
||||
for (const auto &task : getTasksByDayId(day.id)) {
|
||||
for (const auto &task : tasks) {
|
||||
result += taskToString(task) + '\n';
|
||||
}
|
||||
result += '\n';
|
||||
|
|
2
external/mirai-core/src/Source.cpp
vendored
2
external/mirai-core/src/Source.cpp
vendored
|
@ -29,8 +29,8 @@ void Source::createTask(const createTaskParams &task)
|
|||
auto day = data->getDayByDate(task.date.value());
|
||||
if (!day.has_value() && task.date.has_value()) {
|
||||
day = data->insertDay({.id = generateUniqueId(), .date = task.date.value()});
|
||||
dayId = day->id;
|
||||
}
|
||||
dayId = day->id;
|
||||
}
|
||||
|
||||
if (task.event.has_value() && task.event->id()) {
|
||||
|
|
5
external/mirai-core/src/Task.cpp
vendored
5
external/mirai-core/src/Task.cpp
vendored
|
@ -44,6 +44,11 @@ bool Task::hasEvent() const
|
|||
return task_.eventId.has_value();
|
||||
}
|
||||
|
||||
bool Task::hasDate() const
|
||||
{
|
||||
return task_.dayId.has_value();
|
||||
}
|
||||
|
||||
void Task::setTitle(const std::string &newTitle)
|
||||
{
|
||||
data_->updateTask(id(), {.title = newTitle});
|
||||
|
|
7
external/mirai-core/src/View.cpp
vendored
7
external/mirai-core/src/View.cpp
vendored
|
@ -63,12 +63,15 @@ void View::update()
|
|||
for (auto day : source->getDays()) {
|
||||
// day's tasks
|
||||
auto sourceTasks = day.tasks() | std::ranges::views::filter([&](const Task &task) {
|
||||
if (day.date() >= todayDate) {
|
||||
return true;
|
||||
}
|
||||
if (shouldHideCompletedTasks()) {
|
||||
return task.checked() == false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
if (std::ranges::distance(sourceTasks) > 0) {
|
||||
if (day.date() >= todayDate || std::ranges::distance(sourceTasks) > 0) {
|
||||
|
||||
if (!dates.contains(day.date())) {
|
||||
dates.insert_or_assign(day.date(), DateView{});
|
||||
|
@ -85,7 +88,7 @@ void View::update()
|
|||
}).has_value();
|
||||
});
|
||||
|
||||
if (std::ranges::distance(sourceEvents) > 0) {
|
||||
if (day.date() >= todayDate || std::ranges::distance(sourceEvents) > 0) {
|
||||
if (!dates.contains(day.date())) {
|
||||
dates.insert_or_assign(day.date(), DateView{});
|
||||
}
|
||||
|
|
|
@ -96,9 +96,13 @@ void UiState::setupCallbacks()
|
|||
assert(source);
|
||||
auto task = source->getTaskById(taskId);
|
||||
assert(task);
|
||||
if (!task->checked() && !task->hasDate() && !task->hasEvent()) {
|
||||
task->setDate(mirai::Date(mirai::Date(std::chrono::system_clock::now())));
|
||||
}
|
||||
task->setChecked(!task->checked());
|
||||
// task->getState() == mirai::DONE ? task->markAsUndone() : task->markAsDone();
|
||||
miraiInstance_->save();
|
||||
view_.update();
|
||||
reloadTasks();
|
||||
});
|
||||
|
||||
mainWindow_->global<ui::Backend>().on_source_clicked([&](int index) {
|
||||
|
@ -156,6 +160,8 @@ void UiState::setupCallbacks()
|
|||
});
|
||||
|
||||
mainWindow_->global<ui::Backend>().on_create_task([&](ui::NewTaskData newTaskData) {
|
||||
std::cout << "Task date: " << newTaskData.date.year << " " << newTaskData.date.day
|
||||
<< std::endl;
|
||||
std::optional<mirai::Date> date = std::nullopt;
|
||||
if (newTaskData.date.year != 0) {
|
||||
date = SlintDateToMiraiDate(newTaskData.date);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue