Updated the task view and backend to handle more like a routine

This commit is contained in:
2026-03-08 22:10:46 -04:00
parent 4161ff9513
commit 9d3a277f45
14 changed files with 405 additions and 147 deletions

View File

@@ -1,4 +1,4 @@
// GET /api/tasks/upcoming — Top 3 upcoming tasks per user (for Dashboard)
// GET /api/tasks/upcoming — Today's tasks per user, grouped by period
#include "cJSON.h"
#include "esp_http_server.h"
@@ -20,36 +20,26 @@ internal esp_err_t api_tasks_upcoming_handler(httpd_req_t *req)
continue;
// Collect incomplete tasks for this user
task_t *user_tasks[MAX_TASKS];
int count = 0;
for (int t = 0; t < MAX_TASKS; t++)
{
if (g_Tasks[t].active && g_Tasks[t].user_id == g_Users[u].id &&
!g_Tasks[t].completed)
{
user_tasks[count++] = &g_Tasks[t];
}
}
// Sort by due_date ascending
sort_tasks_by_due_date(user_tasks, count);
// Build user object with top 3
// Include: recurring tasks (any day) and one-off tasks
cJSON *user_obj = cJSON_CreateObject();
cJSON_AddNumberToObject(user_obj, "id", g_Users[u].id);
cJSON_AddStringToObject(user_obj, "name", g_Users[u].name);
cJSON *tasks_arr = cJSON_AddArrayToObject(user_obj, "tasks");
int limit = count < 3 ? count : 3;
for (int i = 0; i < limit; i++)
for (int t = 0; t < MAX_TASKS; t++)
{
if (!g_Tasks[t].active || g_Tasks[t].completed ||
g_Tasks[t].user_id != g_Users[u].id)
continue;
cJSON *t_obj = cJSON_CreateObject();
cJSON_AddNumberToObject(t_obj, "id", user_tasks[i]->id);
cJSON_AddStringToObject(t_obj, "title", user_tasks[i]->title);
cJSON_AddNumberToObject(t_obj, "due_date",
(double)user_tasks[i]->due_date);
cJSON_AddBoolToObject(t_obj, "completed", user_tasks[i]->completed);
cJSON_AddNumberToObject(t_obj, "id", g_Tasks[t].id);
cJSON_AddStringToObject(t_obj, "title", g_Tasks[t].title);
cJSON_AddNumberToObject(t_obj, "due_date", (double)g_Tasks[t].due_date);
cJSON_AddNumberToObject(t_obj, "period", g_Tasks[t].period);
cJSON_AddNumberToObject(t_obj, "recurrence", g_Tasks[t].recurrence);
cJSON_AddBoolToObject(t_obj, "completed", g_Tasks[t].completed);
cJSON_AddItemToArray(tasks_arr, t_obj);
}