From 5d3b22bfcef0fe4ff7e9ba1bbfce2a421c10528c Mon Sep 17 00:00:00 2001
From: default
Date: Tue, 28 Nov 2023 09:29:54 +0100
Subject: Refactored to xs_html the poll part of html_entry().
---
html.c | 83 ++++++++++++++++++++++++++++++++++++++++++------------------------
1 file changed, 53 insertions(+), 30 deletions(-)
(limited to 'html.c')
diff --git a/html.c b/html.c
index 544cbad..d49cfd6 100644
--- a/html.c
+++ b/html.c
@@ -1512,54 +1512,77 @@ xs_str *html_entry(snac *user, xs_str *os, const xs_dict *msg, int local,
if (closed || user == NULL) {
/* closed poll */
- c = xs_str_cat(c, "
\n");
+ xs_html *poll_result = xs_html_tag("table",
+ xs_html_attr("class", "snac-poll-result"));
while (xs_list_iter(&p, &v)) {
- const char *name = xs_dict_get(v, "name");
- const xs_dict *replies = xs_dict_get(v, "replies");
+ char *name = xs_dict_get(v, "name");
+ xs_dict *replies = xs_dict_get(v, "replies");
if (name && replies) {
- int nr = xs_number_get(xs_dict_get(replies, "totalItems"));
- xs *es1 = encode_html(name);
- xs *l = xs_fmt("| %s: | %d |
\n", es1, nr);
-
- c = xs_str_cat(c, l);
+ char *ti = (char *)xs_number_str(xs_dict_get(replies, "totalItems"));
+
+ xs_html_add(poll_result,
+ xs_html_tag("tr",
+ xs_html_tag("td",
+ xs_html_text(name),
+ xs_html_text(":")),
+ xs_html_tag("td",
+ xs_html_text(ti))));
}
}
- c = xs_str_cat(c, "
\n");
+ xs *s1 = xs_html_render(poll_result);
+ c = xs_str_cat(c, s1);
}
else {
/* poll still active */
- xs *s1 = xs_fmt("\n\n", L("Vote"));
-
- s1 = xs_str_cat(s1, s2);
+ xs_html_add(form,
+ xs_html_tag("p", NULL),
+ xs_html_sctag("input",
+ xs_html_attr("type", "submit"),
+ xs_html_attr("class", "button"),
+ xs_html_attr("value", L("Vote"))));
+ xs *s1 = xs_html_render(poll);
c = xs_str_cat(c, s1);
}
--
cgit v1.2.3