diff options
author | Michael McVady <femtonaut@gmail.com> | 2024-01-13 15:56:36 -0600 |
---|---|---|
committer | Michael McVady <femtonaut@gmail.com> | 2024-01-13 15:56:36 -0600 |
commit | ef7cd622768b9dfe99ad18b7af5bd0e328b4d503 (patch) | |
tree | d46505f75b2d5831e16074470c42135b8ae05d22 /src/clog.c | |
parent | 53e31bbbd4e77ff08d697d1a848bccf044172432 (diff) |
Add message for no search results
Diffstat (limited to 'src/clog.c')
-rw-r--r-- | src/clog.c | 60 |
1 files changed, 29 insertions, 31 deletions
@@ -167,12 +167,13 @@ int validate_text(struct http_request *req, char *data) { } int http_ok_resp( - struct http_request *req, - enum http_status_code status, - struct kore_buf *content + struct http_request *req, enum http_status_code status, struct kore_buf *content ) { - struct kore_buf *resp_buf = kore_buf_alloc(0); - const char *body = kore_buf_stringify(content, NULL); + struct kore_buf *resp_buf = NULL; + const char *body = NULL; + + resp_buf = kore_buf_alloc(0); + body = kore_buf_stringify(content, NULL); http_response_header(req, "content-type", "text/html; charset=utf-8"); kore_buf_append(resp_buf, asset_html_header_html, asset_len_html_header_html); @@ -186,11 +187,10 @@ int http_ok_resp( return KORE_RESULT_OK; } -int http_err_resp( - struct http_request *req, - enum http_status_code status -) { - struct kore_buf *resp_buf = kore_buf_alloc(0); +int http_err_resp(struct http_request *req, enum http_status_code status) { + struct kore_buf *resp_buf = NULL; + + resp_buf = kore_buf_alloc(0); http_response_header(req, "content-type", "text/html; charset=utf-8"); kore_buf_append(resp_buf, asset_html_header_html, asset_len_html_header_html); @@ -241,31 +241,30 @@ int get_index(struct http_request *req) { kore_buf_append(content, asset_header_html, asset_len_header_html); // Write search form. - kore_buf_append(content, asset_search_html, asset_len_search_html); + kore_buf_appendf(content, (const char *) asset_search_html, query ? query : ""); - // Write table header. - kore_buf_append(content, asset_table_header_html, asset_len_table_header_html); - - // Iterate over entries and render them. - for (i = 0; i < eq.num_entries; i++) { - // Append rendered MD entry. - kore_buf_appendf( - content, - (const char *) asset_table_row_html, - eq.entries[i]->id, eq.entries[i]->title, eq.entries[i]->created_at, eq.entries[i]->updated_at - ); + if (eq.num_entries == 0 && query) { + kore_buf_appendf(content, (const char *) asset_error_html, "No results found."); } - - // Write table footer. - kore_buf_append(content, asset_table_footer_html, asset_len_table_footer_html); - - + else { + kore_buf_append(content, asset_table_header_html, asset_len_table_header_html); + // Iterate over entries and render them. + for (i = 0; i < eq.num_entries; i++) { + // Append rendered MD entry. + kore_buf_appendf( + content, + (const char *) asset_table_row_html, + eq.entries[i]->id, eq.entries[i]->title, eq.entries[i]->created_at, eq.entries[i]->updated_at + ); + } + kore_buf_append(content, asset_table_footer_html, asset_len_table_footer_html); + } + http_ok_resp(req, HTTP_STATUS_OK, content); out: ; kore_free(content); - entry_query_cleanup(&eq); return KORE_RESULT_OK; @@ -331,12 +330,11 @@ out: ; int edit_entry(struct http_request *req) { int err = 0; + char *id = NULL; struct entry_query eq; struct kore_buf *content = NULL; struct kore_buf *rendered_body = NULL; - - char *id = NULL; - + content = kore_buf_alloc(0); rendered_body = kore_buf_alloc(0); |