From 97b7100b0617d05a13c8bb7972361becf07c8e2d Mon Sep 17 00:00:00 2001 From: default Date: Tue, 28 Nov 2023 19:57:59 +0100 Subject: [PATCH] Children in html_entry() is (almost) xs_html. --- html.c | 54 ++++++++++++++++++++++++++---------------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/html.c b/html.c index de3659f..d00ba66 100644 --- a/html.c +++ b/html.c @@ -1988,25 +1988,27 @@ xs_str *html_entry(snac *user, xs_str *os, const xs_dict *msg, int local, int left = xs_list_len(children); if (left) { - char *p, *cmd5; - int older_open = 0; - xs *ss = xs_str_new(NULL); - int n_children = 0; + xs_html *ch_details = xs_html_tag("details", + xs_html_attr("open", NULL), + xs_html_tag("summary", + xs_html_text("..."))); - ss = xs_str_cat(ss, "
...

\n"); + xs_html *ch_container = xs_html_tag("div", + xs_html_attr("class", level < 4 ? "snac-children" : "snac-children-too-deep")); - if (level < 4) - ss = xs_str_cat(ss, "

\n"); - else - ss = xs_str_cat(ss, "
\n"); + xs_html_add(ch_details, + ch_container); + xs_html *ch_older = NULL; if (left > 3) { - xs *s1 = xs_fmt("
%s\n", L("Older...")); - ss = xs_str_cat(ss, s1); - older_open = 1; + xs_html_add(ch_container, + ch_older = xs_html_tag("details", + xs_html_tag("summary", + xs_html_text(L("Older..."))))); } - p = children; + xs_list *p = children; + char *cmd5; while (xs_list_iter(&p, &cmd5)) { xs *chd = NULL; @@ -2015,14 +2017,16 @@ xs_str *html_entry(snac *user, xs_str *os, const xs_dict *msg, int local, else object_get_by_md5(cmd5, &chd); - if (older_open && left <= 3) { - ss = xs_str_cat(ss, "
\n"); - older_open = 0; - } - if (chd != NULL && xs_is_null(xs_dict_get(chd, "name"))) { - ss = html_entry(user, ss, chd, local, level + 1, cmd5, hide_children); - n_children++; + xs *s1 = xs_str_new(NULL); + s1 = html_entry(user, s1, chd, local, level + 1, cmd5, hide_children); + + if (left > 3) + xs_html_add(ch_older, + xs_html_raw(s1)); + else + xs_html_add(ch_container, + xs_html_raw(s1)); } else srv_debug(2, xs_fmt("cannot read child %s", cmd5)); @@ -2030,14 +2034,8 @@ xs_str *html_entry(snac *user, xs_str *os, const xs_dict *msg, int local, left--; } - if (older_open) - ss = xs_str_cat(ss, "
\n"); - - ss = xs_str_cat(ss, "\n"); - ss = xs_str_cat(ss, "\n"); - - if (n_children) - s = xs_str_cat(s, ss); + xs *s1 = xs_html_render(ch_details); + s = xs_str_cat(s, s1); } }