commit f3ad5f0

default  ·  2023-11-21 10:11:05 +0000 UTC
parent 009a1da
More refactoring of html_people_list().
1 files changed,  +56, -30
M html.c
M html.c
+56, -30
  1@@ -766,7 +766,7 @@ xs_str *html_top_controls(snac *snac, xs_str *s)
  2 }
  3 
  4 
  5-xs_str *html_button(xs_str *s, const char *clss, const char *label, const char *hint)
  6+static xs_str *html_button(xs_str *s, const char *clss, const char *label, const char *hint)
  7 {
  8     xs *s1 = xs_fmt(
  9                "<input type=\"submit\" name=\"action\" "
 10@@ -777,6 +777,19 @@ xs_str *html_button(xs_str *s, const char *clss, const char *label, const char *
 11 }
 12 
 13 
 14+static xs_html *html_button_2(char *clss, char *label, char *hint)
 15+{
 16+    xs *c = xs_fmt("snac-btn-%s", clss);
 17+
 18+    return xs_html_sctag("input",
 19+        xs_html_attr("type",    "submit"),
 20+        xs_html_attr("name",    "action"),
 21+        xs_html_attr("class",   c),
 22+        xs_html_attr("value",   label),
 23+        xs_html_attr("title",   hint));
 24+}
 25+
 26+
 27 xs_str *build_mentions(snac *snac, const xs_dict *msg)
 28 /* returns a string with the mentions in msg */
 29 {
 30@@ -1739,46 +1752,59 @@ xs_str *html_people_list(snac *snac, xs_str *os, xs_list *list, const char *head
 31                 }
 32             }
 33 
 34-
 35             /* buttons */
 36-            s = xs_str_cat(s, "<div class=\"snac-controls\">\n");
 37-
 38-            xs *s1 = xs_fmt(
 39-                "<p><form autocomplete=\"off\" method=\"post\" action=\"%s/admin/action\">\n"
 40-                "<input type=\"hidden\" name=\"actor\" value=\"%s\">\n"
 41-                "<input type=\"hidden\" name=\"actor-form\" value=\"yes\">\n",
 42-
 43-                snac->actor, actor_id
 44-            );
 45-            s = xs_str_cat(s, s1);
 46+            xs *btn_form_action = xs_fmt("%s/admin/action", snac->actor);
 47+
 48+            xs_html *snac_controls = xs_html_tag("DIV",
 49+                xs_html_attr("class",   "snac-controls"));
 50+
 51+            xs_html *form = xs_html_tag("form",
 52+                xs_html_attr("autocomplete",    "off"),
 53+                xs_html_attr("method",          "post"),
 54+                xs_html_attr("action",          btn_form_action),
 55+                xs_html_sctag("input",
 56+                    xs_html_attr("type",    "hidden"),
 57+                    xs_html_attr("name",    "actor"),
 58+                    xs_html_attr("value",   actor_id)),
 59+                xs_html_sctag("input",
 60+                    xs_html_attr("type",    "hidden"),
 61+                    xs_html_attr("name",    "actor-form"),
 62+                    xs_html_attr("value",   "yes")));
 63+
 64+            xs_html_add(snac_controls, form);
 65 
 66             if (following_check(snac, actor_id)) {
 67-                s = html_button(s, "unfollow", L("Unfollow"),
 68-                                L("Stop following this user's activity"));
 69+                xs_html_add(form,
 70+                    html_button_2("unfollow", L("Unfollow"),
 71+                                L("Stop following this user's activity")));
 72 
 73                 if (is_limited(snac, actor_id))
 74-                    s = html_button(s, "unlimit", L("Unlimit"),
 75-                                L("Allow announces (boosts) from this user"));
 76+                    xs_html_add(form,
 77+                        html_button_2("unlimit", L("Unlimit"),
 78+                                L("Allow announces (boosts) from this user")));
 79                 else
 80-                    s = html_button(s, "limit", L("Limit"),
 81-                                L("Block announces (boosts) from this user"));
 82+                    xs_html_add(form,
 83+                        html_button_2("limit", L("Limit"),
 84+                                L("Block announces (boosts) from this user")));
 85             }
 86             else {
 87-                s = html_button(s, "follow", L("Follow"),
 88-                                L("Start following this user's activity"));
 89+                xs_html_add(form,
 90+                    html_button_2("follow", L("Follow"),
 91+                                L("Start following this user's activity")));
 92 
 93                 if (follower_check(snac, actor_id))
 94-                    s = html_button(s, "delete", L("Delete"), L("Delete this user"));
 95+                    xs_html_add(form,
 96+                        html_button_2("delete", L("Delete"), L("Delete this user")));
 97             }
 98 
 99             if (is_muted(snac, actor_id))
100-                s = html_button(s, "unmute", L("Unmute"),
101-                                L("Stop blocking activities from this user"));
102+                xs_html_add(form,
103+                    html_button_2("unmute", L("Unmute"),
104+                                L("Stop blocking activities from this user")));
105             else
106-                s = html_button(s, "mute", L("MUTE"),
107-                                L("Block any activity from this user"));
108-
109-            s = xs_str_cat(s, "</form>\n");
110+                xs_html_add(form,
111+                    html_button_2("mute", L("MUTE"),
112+                                L("Block any activity from this user")));
113 
114             /* the post textarea */
115             xs *dm_form_id  = xs_fmt("%s_%s_dm", md5, t);
116@@ -1821,14 +1847,14 @@ xs_str *html_people_list(snac *snac, xs_str *os, xs_list *list, const char *head
117                         xs_html_sctag("p", NULL))),
118                 xs_html_sctag("p", NULL));
119 
120+            xs_html_add(snac_controls, dm_textarea);
121+
122             {
123-                xs *s1 = xs_html_render(dm_textarea);
124+                xs *s1 = xs_html_render(snac_controls);
125                 s = xs_str_cat(s, s1);
126             }
127 
128             s = xs_str_cat(s, "</div>\n");
129-
130-            s = xs_str_cat(s, "</div>\n");
131         }
132     }
133