commit 168b935203351c2e4f188bcf87dba37190afb7a0
parent a40e45f6cfb391cda0a414c8641b6c26735af514
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date:   Mon, 11 Mar 2024 17:46:58 -0700
Reverse display order of timesheets
The most recent data is the data the user is most likely to want
to see, so since starting at the top of a document is pretty universal
keep the recent data up top.
Diffstat:
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/pages/main.c b/pages/main.c
@@ -225,7 +225,9 @@ printtimes(struct pagedata *pd, struct timesheet *times)
 	    (status = khtml_elem(&pd->html, KELEM_TBODY)) != KCGI_OK)
 		return status;
 
-	for (; times; times = times->next) {
+	for (; times->next; times = times->next)
+		;
+	for (; times; times = times->prev) {
 		if ((status = khtml_elem(&pd->html, KELEM_TR)) != KCGI_OK ||
 		    (status = printtime(pd, times)) != KCGI_OK ||
 		    (status = khtml_closeelem(&pd->html, 1)) != KCGI_OK)
@@ -252,7 +254,7 @@ pagemain(struct pagedata *pd)
 {
 	enum kcgi_err status;
 	enum time_field tf;
-	struct timesheet *times, *end;
+	struct timesheet *times, *end, *new;
 
 	if (!pd->user)
 		return errorpage(pd, KHTTP_401);
@@ -277,10 +279,9 @@ pagemain(struct pagedata *pd)
 
 	for (end = times; end->next; end = end->next)
 		;
-	if (end->set & EndTimeFlag) {
-		end->next = newtimesheet();
-		if (!end->next)
-			freetimesheet(times);
+	if (end->set & EndTimeFlag && !inserttimesheet(newtimesheet(), end)) {
+		freetimesheet(times);
+		return KCGI_SYSTEM;
 	}
 
 	if ((status = htmlwithin(pd, KELEM_H1, "Timekeeper")) != KCGI_OK ||