1
0
mirror of https://github.com/axllent/mailpit.git synced 2025-08-13 20:04:49 +02:00

Chore: Refactor JS functions and remove unused parameters

This commit is contained in:
Ralph Slooten
2025-07-24 17:27:11 +12:00
parent 33fe814c34
commit cce21854b9
13 changed files with 28 additions and 23 deletions

View File

@@ -17,7 +17,7 @@ export default {
mixins: [CommonMixins], mixins: [CommonMixins],
watch: { watch: {
$route(to, from) { $route() {
// hide mobile menu on URL change // hide mobile menu on URL change
this.hideNav(); this.hideNav();
}, },

View File

@@ -52,7 +52,7 @@ export default {
let response; let response;
try { try {
response = JSON.parse(e.data); response = JSON.parse(e.data);
} catch (e) { } catch {
return; return;
} }
@@ -128,7 +128,7 @@ export default {
} }
}; };
ws.onclose = (e) => { ws.onclose = () => {
if (this.socketLastConnection === 0) { if (this.socketLastConnection === 0) {
// connection failed immediately after connecting to Mailpit implies proxy websockets aren't configured // connection failed immediately after connecting to Mailpit implies proxy websockets aren't configured
console.log("Unable to connect to websocket, disabling websocket support"); console.log("Unable to connect to websocket, disabling websocket support");

View File

@@ -47,14 +47,14 @@ export default {
}, },
markAllRead() { markAllRead() {
this.put(this.resolve(`/api/v1/messages`), { read: true }, (response) => { this.put(this.resolve(`/api/v1/messages`), { read: true }, () => {
window.scrollInPlace = true; window.scrollInPlace = true;
this.loadMessages(); this.loadMessages();
}); });
}, },
deleteAllMessages() { deleteAllMessages() {
this.delete(this.resolve(`/api/v1/messages`), false, (response) => { this.delete(this.resolve(`/api/v1/messages`), false, () => {
pagination.start = 0; pagination.start = 0;
this.loadMessages(); this.loadMessages();
}); });

View File

@@ -28,7 +28,7 @@ export default {
if (!mailbox.selected.length) { if (!mailbox.selected.length) {
return false; return false;
} }
this.put(this.resolve(`/api/v1/messages`), { Read: true, IDs: mailbox.selected }, (response) => { this.put(this.resolve(`/api/v1/messages`), { Read: true, IDs: mailbox.selected }, () => {
window.scrollInPlace = true; window.scrollInPlace = true;
this.loadMessages(); this.loadMessages();
}); });
@@ -43,7 +43,7 @@ export default {
if (!mailbox.selected.length) { if (!mailbox.selected.length) {
return false; return false;
} }
this.put(this.resolve(`/api/v1/messages`), { Read: false, IDs: mailbox.selected }, (response) => { this.put(this.resolve(`/api/v1/messages`), { Read: false, IDs: mailbox.selected }, () => {
window.scrollInPlace = true; window.scrollInPlace = true;
this.loadMessages(); this.loadMessages();
}); });
@@ -57,7 +57,7 @@ export default {
return false; return false;
} }
this.delete(this.resolve(`/api/v1/messages`), { IDs: ids }, (response) => { this.delete(this.resolve(`/api/v1/messages`), { IDs: ids }, () => {
window.scrollInPlace = true; window.scrollInPlace = true;
this.loadMessages(); this.loadMessages();
}); });

View File

@@ -257,7 +257,10 @@ export default {
if (platforms) { if (platforms) {
try { try {
this.platforms = JSON.parse(platforms); this.platforms = JSON.parse(platforms);
} catch (e) {} } catch {
// if parsing fails, reset to default
this.platforms = [];
}
} }
// set all options // set all options

View File

@@ -153,7 +153,7 @@ export default {
this.error = error.message; this.error = error.message;
} }
}) })
.then((result) => { .then(() => {
// always run // always run
this.loading = false; this.loading = false;
}); });

View File

@@ -143,12 +143,12 @@ export default {
window.addEventListener("resize", this.resizeIFrames); window.addEventListener("resize", this.resizeIFrames);
const headersTab = document.getElementById("nav-headers-tab"); const headersTab = document.getElementById("nav-headers-tab");
headersTab.addEventListener("shown.bs.tab", (event) => { headersTab.addEventListener("shown.bs.tab", () => {
this.loadHeaders = true; this.loadHeaders = true;
}); });
const rawTab = document.getElementById("nav-raw-tab"); const rawTab = document.getElementById("nav-raw-tab");
rawTab.addEventListener("shown.bs.tab", (event) => { rawTab.addEventListener("shown.bs.tab", () => {
this.srcURI = this.resolve("/api/v1/message/" + this.message.ID + "/raw"); this.srcURI = this.resolve("/api/v1/message/" + this.message.ID + "/raw");
this.resizeIFrames(); this.resizeIFrames();
}); });
@@ -180,7 +180,7 @@ export default {
this.isHTMLTabSelected(); this.isHTMLTabSelected();
document.querySelectorAll('button[data-bs-toggle="tab"]').forEach((listObj) => { document.querySelectorAll('button[data-bs-toggle="tab"]').forEach((listObj) => {
listObj.addEventListener("shown.bs.tab", (event) => { listObj.addEventListener("shown.bs.tab", () => {
this.isHTMLTabSelected(); this.isHTMLTabSelected();
}); });
}); });
@@ -203,7 +203,9 @@ export default {
anchorEl.setAttribute("target", "_blank"); anchorEl.setAttribute("target", "_blank");
} }
} }
} catch (error) {} } catch {
// ignore errors when accessing the iframe content
}
this.resizeIFrames(); this.resizeIFrames();
} }
}, 500); }, 500);
@@ -280,7 +282,7 @@ export default {
Tags: this.messageTags, Tags: this.messageTags,
}; };
this.put(this.resolve("/api/v1/tags"), data, (response) => { this.put(this.resolve("/api/v1/tags"), data, () => {
window.scrollInPlace = true; window.scrollInPlace = true;
this.$emit("loadMessages"); this.$emit("loadMessages");
}); });

View File

@@ -64,7 +64,7 @@ export default {
To: this.addresses, To: this.addresses,
}; };
this.post(this.resolve("/api/v1/message/" + this.message.ID + "/release"), data, (response) => { this.post(this.resolve("/api/v1/message/" + this.message.ID + "/release"), data, () => {
this.modal("ReleaseModal").hide(); this.modal("ReleaseModal").hide();
if (this.deleteAfterRelease) { if (this.deleteAfterRelease) {
this.$emit("delete"); this.$emit("delete");

View File

@@ -14,7 +14,7 @@ export default {
}, },
watch: { watch: {
"mailbox.refresh": function (v) { "mailbox.refresh"(v) {
if (v) { if (v) {
// trigger a refresh // trigger a refresh
this.loadMessages(); this.loadMessages();
@@ -45,9 +45,9 @@ export default {
const params = {}; const params = {};
mailbox.selected = []; mailbox.selected = [];
params["limit"] = pagination.limit; params.limit = pagination.limit;
if (pagination.start > 0) { if (pagination.start > 0) {
params["start"] = pagination.start; params.start = pagination.start;
} }
this.get(this.apiURI, params, (response) => { this.get(this.apiURI, params, (response) => {

View File

@@ -33,7 +33,7 @@ export const mailbox = reactive({
watch( watch(
() => mailbox.count, () => mailbox.count,
(v) => { () => {
mailbox.selected = []; mailbox.selected = [];
}, },
); );

View File

@@ -36,7 +36,7 @@ export default {
}, },
watch: { watch: {
$route(to, from) { $route() {
this.loadMailbox(); this.loadMailbox();
}, },
}, },

View File

@@ -94,7 +94,7 @@ export default {
}, },
watch: { watch: {
$route(to, from) { $route() {
this.loadMessage(); this.loadMessage();
}, },
}, },

View File

@@ -36,7 +36,7 @@ export default {
}, },
watch: { watch: {
$route(to, from) { $route() {
this.doSearch(); this.doSearch();
}, },
}, },