diff postdog/main.c @ 117:b91f2dd6f84d

[PostDog] Fixed delete logic.
author June Park <parkjune1995@gmail.com>
date Wed, 07 Jan 2026 05:02:45 -0800
parents 7bd795bac997
children 249881ceff7b
line wrap: on
line diff
--- a/postdog/main.c	Wed Jan 07 04:52:17 2026 -0800
+++ b/postdog/main.c	Wed Jan 07 05:02:45 2026 -0800
@@ -48,6 +48,7 @@
   char *filename;
   Rectangle rect;
   long time_modified;
+  boolean deleted;
 } HistoryItem;
 
 typedef struct {
@@ -90,8 +91,8 @@
     do {
       HistoryItem item = {0};
       item.filename = strdup(fileinfo.name);
-      item.rect = (Rectangle){0};
       item.time_modified = fileinfo.time_write; 
+      item.deleted = FALSE;
       Dowa_Array_Push(file_arr, item);
     } while (_findnext(handle, &fileinfo) == 0);
     _findclose(handle);
@@ -113,6 +114,7 @@
       HistoryItem item = {0};
       item.filename = strdup(entry->d_name);
       item.time_modified = file_stat.st_mtime;
+      item.deleted = FALSE;
       Dowa_Array_Push(file_arr, item);
     }
   }
@@ -232,7 +234,9 @@
   snprintf(filename, 1024, "%s.txt", uuid4);
   PostDog_History_CreateFile(filename, new_file);
 
-  HistoryItem item = (HistoryItem){ .filename = malloc(sizeof(char) * strlen(filename) + 1), .rect = (Rectangle){0} };
+  HistoryItem item = {0};
+  item.filename = strdup(filename);
+  item.deleted = FALSE;
   memcpy(item.filename, filename, strlen(filename) + 1);
   Dowa_Array_Push(new_history_items, item);
   
@@ -685,22 +689,15 @@
     int32 number_of_skipped_items = 0;
     for (int i = 0; i < total; i++)
     {
-      boolean skip = FALSE;
-      for (int32 j = 0; j < Dowa_Array_Length(history_deleted_items); j++)
-      {
-        if (i == j)
-        {
-          skip = TRUE;
-          number_of_skipped_items++;
-          break;
-        }
-      }
-      if (skip)
-        continue;
-
       HistoryItem *curr_history_items = i < new_history_items_length ?
         &new_history_items[i] : &history_items[i - new_history_items_length];
 
+      if (curr_history_items->deleted)
+      {
+        number_of_skipped_items++;
+        continue;
+      }
+
       curr_history_items->rect = (Rectangle){
         .x = history_list_area.x,
         .y = history_list_area.y + (padding + item_height) * (i - number_of_skipped_items) + history_scroll_offset,
@@ -821,18 +818,11 @@
       BeginScissorMode(history_list_area.x, history_list_area.y, history_list_area.width, history_list_area.height);
         for (int i = 0; i < total; i++)
         {
-          boolean skip = FALSE;
-          for (int32 j = 0; j < Dowa_Array_Length(history_deleted_items); j++)
-          {
-            if (i == j)
-            {
-              skip = TRUE;
-              break;
-            }
-          }
-          if (skip)
+          HistoryItem *curr_history_items = i < new_history_items_length ? 
+            &new_history_items[i] : &history_items[i - new_history_items_length];
+
+          if (curr_history_items->deleted)
             continue;
-          HistoryItem *curr_history_items = i < new_history_items_length ? &new_history_items[i] : &history_items[i - new_history_items_length];
 
           float diff = curr_history_items->rect.height*0.3;
           // DrawRectangleRec(curr_history_items->rect, Fade(RED, 0.1f));
@@ -860,11 +850,9 @@
           if (GuiButton(AddPaddingHorizontal(icon_area_right_column,padding), "delete"))
           {
             if (!remove(PostDog_Construct_URL(curr_history_items->filename)))
-               Dowa_Array_Push(history_deleted_items, i);
+               curr_history_items->deleted = TRUE;
             else
-            {
               fprintf(stderr, "Wasn't able to delete file: %s \n", curr_history_items->filename);
-            }
           }
         }
       EndScissorMode();