AJAX interaction fixes

FossilOrigin-Name: cfc54659730b258dcd127953cfca216735cf0023df3363c6ea35afa46295603c
This commit is contained in:
nekobit 2022-06-06 19:18:12 +00:00
parent 3dba7538f7
commit 4a9500d0c0
6 changed files with 71 additions and 37 deletions

30
dist/js/main.js vendored
View file

@ -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;

16
dist/treebird20.css vendored
View file

@ -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;

View file

@ -201,16 +201,21 @@ void content_notifications(struct session* ssn, mastodont_t* api, char** data)
if (mastodont_get_notifications(api, &args, &storage, &notifs, &notifs_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, &notifs, &notifs_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);

View file

@ -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,

View file

@ -36,7 +36,7 @@
</a>
</td>
<td>
<span class="time">{{%s:rel_time}}</span>
<a href="#{{%s:status_id}}" class="time">{{%s:rel_time}}</a>
</td>
</tr>
</table>

View file

@ -1,4 +1,4 @@
<table id="{{%s:status_id}}" class="status {{%s:focused}} ui-table">
<table id="{{%s:status_id}}" class="status ui-table">
{{ %s : notif_info }}
<tr>
<td class="pfp-td {{%s:is_cat}} {{%s:is_bun}}">