From 4a9500d0c0a79eec2c22d1034a62b979af452f2d Mon Sep 17 00:00:00 2001 From: nekobit Date: Mon, 6 Jun 2022 19:18:12 +0000 Subject: [PATCH] AJAX interaction fixes FossilOrigin-Name: cfc54659730b258dcd127953cfca216735cf0023df3363c6ea35afa46295603c --- dist/js/main.js | 30 +++++++++++++----- dist/treebird20.css | 16 ++++++++-- src/notifications.c | 56 ++++++++++++++++++++------------- src/status.c | 2 -- static/interaction_buttons.tmpl | 2 +- static/status.tmpl | 2 +- 6 files changed, 71 insertions(+), 37 deletions(-) diff --git a/dist/js/main.js b/dist/js/main.js index f7aaeae..811d0f7 100644 --- a/dist/js/main.js +++ b/dist/js/main.js @@ -110,17 +110,17 @@ function change_count_text(val, sum) return val > 0 ? val.toString() : ""; } -function interact_action(xhr, arg) +function interact_action(status, type) { - let like = arg.status.querySelector(".like"); - let repeat = arg.status.querySelector(".repeat"); + let like = status.querySelector(".like"); + let repeat = status.querySelector(".repeat"); let svg; - if (arg.type === "like" || arg.type === "unlike") + if (type.value === "like" || type.value === "unlike") svg = [ like ]; - else if (arg.type === "repeat" || arg.type === "unrepeat") + else if (type.value === "repeat" || type.value === "unrepeat") svg = [ repeat ]; - else if (arg.type === "likeboost") + else if (type.value === "likeboost") svg = [ like, repeat ]; svg.forEach(that => { @@ -130,6 +130,13 @@ function interact_action(xhr, arg) let is_active = that.classList.contains("active"); that.classList.toggle("active"); + + // Flip itype value + if (type.value.substr(0, 2) === "un") + type.value = type.value.replace("un", ""); + else + type.value = "un" + type.value; + counter.innerHTML = change_count_text(counter.innerHTML, is_active ? -1 : 1); }); } @@ -148,8 +155,15 @@ function status_interact_props(e) itype: type.value }, 1, - interact_action, - { status: status, type: type.value }); + (xhr, args) => { + if (xhr.status !== 200) + { + // Undo action if failure + interact_action(status, type); + } + }, null); + + interact_action(status, type); e.preventDefault(); return false; diff --git a/dist/treebird20.css b/dist/treebird20.css index 3ca20fd..f353aa7 100644 --- a/dist/treebird20.css +++ b/dist/treebird20.css @@ -632,10 +632,12 @@ svg.in-reply-to-icon border-spacing: 0px; } -.status.focused +.status.focused, +.status:target { background-color: #ffdddd; border-left: 3px solid #aa0000; + padding-left: 7px; } .notification-info + .status, @@ -698,8 +700,9 @@ svg.in-reply-to-icon { color: #606060; vertical-align: middle; - font-size: 15px; + font-size: 14px; padding-left: 5px; + text-decoration: none; } .status .status-info, @@ -1190,9 +1193,16 @@ p} .status-interact .statbtn { display: block; - padding: 3px 8px; + padding: 3px 2px 5px; + min-width: 43px; } +.view-btn +{ + min-width: 25px !important; +} + + .status-interact svg.repeat.active { stroke: #08d345; diff --git a/src/notifications.c b/src/notifications.c index f04f8b2..4cb65fb 100644 --- a/src/notifications.c +++ b/src/notifications.c @@ -201,16 +201,21 @@ void content_notifications(struct session* ssn, mastodont_t* api, char** data) if (mastodont_get_notifications(api, &args, &storage, ¬ifs, ¬ifs_len) == 0) { - notif_html = construct_notifications(ssn, api, notifs, notifs_len, NULL); - start_id = keystr(ssn->post.start_id) ? keystr(ssn->post.start_id) : notifs[0].id; - navigation_box = construct_navigation_box(start_id, - notifs[0].id, - notifs[notifs_len-1].id, - NULL); - mstdnt_cleanup_notifications(notifs, notifs_len);} - + if (notifs && notifs_len) + { + notif_html = construct_notifications(ssn, api, notifs, notifs_len, NULL); + start_id = keystr(ssn->post.start_id) ? keystr(ssn->post.start_id) : notifs[0].id; + navigation_box = construct_navigation_box(start_id, + notifs[0].id, + notifs[notifs_len-1].id, + NULL); + mstdnt_cleanup_notifications(notifs, notifs_len); + } + else + notif_html = construct_error("No notifications", E_NOTICE, 1, NULL); + } else - notif_html = construct_error(storage.error, E_NOTICE, 1, NULL); + notif_html = construct_error(storage.error, E_ERROR, 1, NULL); } @@ -229,6 +234,7 @@ void content_notifications(struct session* ssn, mastodont_t* api, char** data) // Output render_base_page(&b, ssn, api); + mastodont_storage_cleanup(&storage); if (notif_html) free(notif_html); if (navigation_box) free(navigation_box); if (page) free(page); @@ -237,10 +243,10 @@ void content_notifications(struct session* ssn, mastodont_t* api, char** data) void content_notifications_compact(struct session* ssn, mastodont_t* api, char** data) { char* page, *notif_html = NULL; - struct mstdnt_storage storage; - struct mstdnt_notification* notifs; - size_t notifs_len; - char* start_id; + struct mstdnt_storage storage = { 0 }; + struct mstdnt_notification* notifs = NULL; + size_t notifs_len = 0; + char* start_id = NULL; char* navigation_box = NULL; if (keystr(ssn->cookies.logged_in)) @@ -260,16 +266,21 @@ void content_notifications_compact(struct session* ssn, mastodont_t* api, char** if (mastodont_get_notifications(api, &args, &storage, ¬ifs, ¬ifs_len) == 0) { - notif_html = construct_notifications_compact(ssn, api, notifs, notifs_len, NULL); - start_id = keystr(ssn->post.start_id) ? keystr(ssn->post.start_id) : notifs[0].id; - navigation_box = construct_navigation_box(start_id, - notifs[0].id, - notifs[notifs_len-1].id, - NULL); - mstdnt_cleanup_notifications(notifs, notifs_len);} - + if (notifs && notifs_len) + { + notif_html = construct_notifications_compact(ssn, api, notifs, notifs_len, NULL); + start_id = keystr(ssn->post.start_id) ? keystr(ssn->post.start_id) : notifs[0].id; + navigation_box = construct_navigation_box(start_id, + notifs[0].id, + notifs[notifs_len-1].id, + NULL); + mstdnt_cleanup_notifications(notifs, notifs_len); + } + else + notif_html = construct_error("No notifications", E_NOTICE, 1, NULL); + } else - notif_html = construct_error(storage.error, E_NOTICE, 1, NULL); + notif_html = construct_error(storage.error, E_ERROR, 1, NULL); } @@ -285,6 +296,7 @@ void content_notifications_compact(struct session* ssn, mastodont_t* api, char** send_result(NULL, NULL, page, len); + mastodont_storage_cleanup(&storage); if (notif_html) free(notif_html); if (navigation_box) free(navigation_box); if (page) free(page); diff --git a/src/status.c b/src/status.c index 1690b39..177c8be 100644 --- a/src/status.c +++ b/src/status.c @@ -596,8 +596,6 @@ char* construct_status(struct session* ssn, struct status_template tmpl = { .status_id = status->id, - .focused = ((flags & STATUS_FOCUSED) == STATUS_FOCUSED ? - "focused" : ""), .notif_info = notif_info, // TODO doesn't even need to be a hashtag, this is a temporary hack .is_cat = status->account.note && strstr(status->account.note, "isCat") ? "is-cat" : NULL, diff --git a/static/interaction_buttons.tmpl b/static/interaction_buttons.tmpl index 6e388af..8524276 100644 --- a/static/interaction_buttons.tmpl +++ b/static/interaction_buttons.tmpl @@ -36,7 +36,7 @@ - {{%s:rel_time}} + {{%s:rel_time}} diff --git a/static/status.tmpl b/static/status.tmpl index 1161eda..2285cff 100644 --- a/static/status.tmpl +++ b/static/status.tmpl @@ -1,4 +1,4 @@ - +
{{ %s : notif_info }}