Children in html_entry() is (almost) xs_html.

This commit is contained in:
default 2023-11-28 19:57:59 +01:00
parent a0ae0885d2
commit 97b7100b06

54
html.c
View file

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