Fix avatars not loading correctly

This commit is contained in:
jude 2023-08-08 17:44:40 +01:00
parent 77f17c8dc2
commit e135a74a9b
2 changed files with 17 additions and 19 deletions

View File

@ -66,30 +66,26 @@ function update_select(sel) {
return; return;
} }
let isCreating = sel.closest("div.reminderContent").classList.contains("creator"); const avatarInput = sel.closest("div.reminderContent").querySelector("img.avatar");
if (!isCreating) { if (!avatarInput.dataset["set"]) {
return; if (sel.selectedOptions[0].dataset["webhookAvatar"]) {
} avatarInput.src = sel.selectedOptions[0].dataset["webhookAvatar"];
} else {
const avatarInput = sel avatarInput.src = "/static/img/icon.png";
.closest("div.reminderContent") }
.querySelector("img.discord-avatar");
if (sel.selectedOptions[0].dataset["webhookAvatar"]) {
avatarInput.src = sel.selectedOptions[0].dataset["webhookAvatar"];
} else {
avatarInput.src = "/static/img/icon.png";
} }
const usernameInput = sel const usernameInput = sel
.closest("div.reminderContent") .closest("div.reminderContent")
.querySelector("input.discord-username"); .querySelector("input.discord-username");
if (sel.selectedOptions[0].dataset["webhookName"]) { if (usernameInput.value.length === 0) {
usernameInput.value = sel.selectedOptions[0].dataset["webhookName"]; if (sel.selectedOptions[0].dataset["webhookName"]) {
} else { usernameInput.value = sel.selectedOptions[0].dataset["webhookName"];
usernameInput.value = "Reminder"; } else {
usernameInput.value = "Reminder";
}
} }
} }
@ -342,7 +338,7 @@ async function serialize_reminder(node, mode) {
restartable: false, restartable: false,
attachment: attachment, attachment: attachment,
attachment_name: attachment_name, attachment_name: attachment_name,
avatar: has_source(node.querySelector("img.discord-avatar").src), avatar: has_source(node.querySelector("img.avatar").src),
channel: node.querySelector("select.channel-selector").value, channel: node.querySelector("select.channel-selector").value,
content: content, content: content,
embed_author_url: embed_author_url, embed_author_url: embed_author_url,
@ -387,7 +383,9 @@ function deserialize_reminder(reminder, frame, mode) {
if ($input !== null) { if ($input !== null) {
$input.value = reminder[prop]; $input.value = reminder[prop];
} else if ($image !== null) { } else if ($image !== null) {
console.log(`loading img ${prop}`);
$image.src = reminder[prop]; $image.src = reminder[prop];
$image.dataset["set"] = "1";
} }
} }
} }

View File

@ -25,7 +25,7 @@
<figure class="media-left"> <figure class="media-left">
<p class="image is-32x32 customizable"> <p class="image is-32x32 customizable">
<a> <a>
<img class="is-rounded discord-avatar" src="/static/img/bg.webp" alt="Image for discord avatar"> <img class="is-rounded avatar" src="/static/img/bg.webp" alt="Image for discord avatar">
</a> </a>
</p> </p>
</figure> </figure>