writing rest of fields
authorDaniel Liu <mr.picklepinosaur@gmail.com>
Thu, 18 Feb 2021 04:06:12 +0000 (23:06 -0500)
committerDaniel Liu <mr.picklepinosaur@gmail.com>
Thu, 18 Feb 2021 04:06:12 +0000 (23:06 -0500)
parser.c
render.c

index bad287a..9300bca 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -341,7 +341,21 @@ begin_write(char* board_path, Board* board)
 
             fprintf(file, "### %s\n", cur_todoitem->item_name);
             
-            // write the other fields later!!!
+            /* bug rn, for some reason date is being written as description too */
+            if (strlen(cur_todoitem->description) > 0) {
+                fprintf(file, "> %s\n", cur_todoitem->description);
+            }
+            if (strlen(cur_todoitem->due) > 0) {
+                fprintf(file, "**%s**\n", cur_todoitem->due);
+            }
+
+            for (int k = 0; k < cur_todoitem->subtask_count; k++) {
+                SubTask* cursubtask = cur_todoitem->subtask_list[k];
+
+                char done_char = (cursubtask->done == SubTaskState_done) ? 'X' : ' ';
+                fprintf(file, "- [%c] %s\n", done_char, cursubtask->subtask_name);
+
+            }
 
         }
 
@@ -399,6 +413,13 @@ free_board(Board* board)
             /* free(cur_todoitem->due); */
 
             /* free subtask later too */
+            for (int k = 0; k < cur_todoitem->subtask_count; k++) {
+                SubTask* cur_subtask = cur_todoitem->subtask_list[k];
+
+                /* free(cur_subtask->subtask_name); */
+                free(cur_subtask);
+                
+            }
 
             free(cur_todoitem);
         }
index d6a04ff..6760c9c 100644 (file)
--- a/render.c
+++ b/render.c
@@ -160,14 +160,25 @@ boardmenu_to_board(BoardMenu* boardmenu)
 
         for (int j = 0; j < get_menu_length(curmenu); j++) {
             MenuItem* curmenuitem = get_menu_item(curmenu, j);
+            TodoItem* itemdata = get_menuitem_userdata(curmenuitem);
 
             TodoItem* new_todoitem = malloc(sizeof(TodoItem));
+            SubTask** new_subtask_list = malloc(itemdata->subtask_count*sizeof(SubTask*));
 
             new_todoitem->item_name = strdup(get_menuitem_title(curmenuitem));
-            new_todoitem->description = strdup(get_menuitem_descrip(curmenuitem));
-            new_todoitem->due = strdup(""); //TEMP! 
-            new_todoitem->subtask_list = malloc(0); //TEMP!
-            new_todoitem->subtask_count = 0; //TEMP!
+            new_todoitem->description = strdup(itemdata->description);
+            new_todoitem->due = strdup(itemdata->due);
+            new_todoitem->subtask_count = itemdata->subtask_count;
+            for (int k = 0; k < itemdata->subtask_count; k++) {
+                SubTask* new_subtask = malloc(sizeof(SubTask));
+
+                new_subtask->subtask_name = itemdata->subtask_list[k]->subtask_name;
+                new_subtask->done = itemdata->subtask_list[k]->done;
+
+                new_subtask_list[k] = new_subtask;
+            }
+
+            new_todoitem->subtask_list = new_subtask_list;
 
             new_item_list[j] = new_todoitem;
         }
@@ -245,17 +256,27 @@ update_menuitem_descrip(MenuItem* menuitem)
 
     if (strlen(item_data->description) > 0) {
         /* strcat(new_descrip, "☰ "); */
-        strcat(new_descrip, "~ ");
+        strcat(new_descrip, "# ");
     }
     if (strlen(item_data->due) > 0) {
         strcat(new_descrip, item_data->due);
         strcat(new_descrip, " ");
     }
     if (item_data->subtask_count > 0) {
+
+        int tasks_complete = 0;
+        for (int i = 0; i < item_data->subtask_count; i++) {
+            if (item_data->subtask_list[i]->done == SubTaskState_done) {
+                tasks_complete += 1;
+            }
+        }
+
         /* [, # done, /, # total, ], null */
-        int substask_len = 1+item_data->subtask_count+1+  1+1;
+        char subtask_done[4]; // assume there wont be more than 999 subtasks (possibly danger?)
+        snprintf(subtask_done, 4, "%d", tasks_complete);
+        int substask_len = 1+item_data->subtask_count+1+strlen(subtask_done)+1+1;
         char subtask_text[substask_len];
-        sprintf(subtask_text, "[%d/]", item_data->subtask_count);
+        sprintf(subtask_text, "[%s/%d]", subtask_done, item_data->subtask_count);
         strcat(new_descrip, subtask_text);
     }