Made $x use significantly less ugly.
This commit is contained in:
parent
bc2d7a08d0
commit
6c723f2ecc
6 changed files with 21 additions and 30 deletions
|
@ -74,7 +74,7 @@ const MszEmbed = (function() {
|
||||||
console.error(ex);
|
console.error(ex);
|
||||||
})
|
})
|
||||||
.then(result => {
|
.then(result => {
|
||||||
const metadata = result.body();
|
const metadata = result.body;
|
||||||
|
|
||||||
if(metadata.error) {
|
if(metadata.error) {
|
||||||
replaceWithUrl(targets, url);
|
replaceWithUrl(targets, url);
|
||||||
|
|
|
@ -195,9 +195,7 @@ const MszForumEditor = function(form) {
|
||||||
formData.append('post[text]', text);
|
formData.append('post[text]', text);
|
||||||
formData.append('post[parser]', parseInt(parser));
|
formData.append('post[parser]', parseInt(parser));
|
||||||
|
|
||||||
const result = await $x.post('/forum/posting.php', { authed: true }, formData);
|
return (await $x.post('/forum/posting.php', { authed: true }, formData)).body;
|
||||||
|
|
||||||
return result.body();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const previewBtn = <button class="input__button" type="button" value="preview">Preview</button>;
|
const previewBtn = <button class="input__button" type="button" value="preview">Preview</button>;
|
||||||
|
|
|
@ -17,11 +17,11 @@
|
||||||
if(!(avatar instanceof Element) || !(userName instanceof Element))
|
if(!(avatar instanceof Element) || !(userName instanceof Element))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const result = (await $x.get(`/auth/login.php?resolve=1&name=${encodeURIComponent(userName.value)}`, { type: 'json' })).body();
|
const { body } = await $x.get(`/auth/login.php?resolve=1&name=${encodeURIComponent(userName.value)}`, { type: 'json' });
|
||||||
|
|
||||||
avatar.src = result.avatar;
|
avatar.src = body.avatar;
|
||||||
if(result.name.length > 0)
|
if(body.name.length > 0)
|
||||||
userName.value = result.name;
|
userName.value = body.name;
|
||||||
};
|
};
|
||||||
|
|
||||||
for(const form of forms) {
|
for(const form of forms) {
|
||||||
|
|
|
@ -40,8 +40,7 @@ const MszMessages = () => {
|
||||||
formData.append('recipient', recipient);
|
formData.append('recipient', recipient);
|
||||||
formData.append('reply', replyTo);
|
formData.append('reply', replyTo);
|
||||||
|
|
||||||
const result = await $x.post('/messages/create', { type: 'json', csrf: true }, formData);
|
const { body } = await $x.post('/messages/create', { type: 'json', csrf: true }, formData);
|
||||||
const body = result.body();
|
|
||||||
if(body.error !== undefined)
|
if(body.error !== undefined)
|
||||||
throw body.error;
|
throw body.error;
|
||||||
|
|
||||||
|
@ -55,8 +54,7 @@ const MszMessages = () => {
|
||||||
formData.append('parser', parser);
|
formData.append('parser', parser);
|
||||||
formData.append('draft', draft);
|
formData.append('draft', draft);
|
||||||
|
|
||||||
const result = await $x.post(`/messages/${encodeURIComponent(messageId)}`, { type: 'json', csrf: true }, formData);
|
const { body } = await $x.post(`/messages/${encodeURIComponent(messageId)}`, { type: 'json', csrf: true }, formData);
|
||||||
const body = result.body();
|
|
||||||
if(body.error !== undefined)
|
if(body.error !== undefined)
|
||||||
throw body.error;
|
throw body.error;
|
||||||
|
|
||||||
|
@ -64,11 +62,10 @@ const MszMessages = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const msgsMark = async (msgs, state) => {
|
const msgsMark = async (msgs, state) => {
|
||||||
const result = await $x.post('/messages/mark', { type: 'json', csrf: true }, {
|
const { body } = await $x.post('/messages/mark', { type: 'json', csrf: true }, {
|
||||||
type: state,
|
type: state,
|
||||||
messages: msgs.map(extractMsgIds).join(','),
|
messages: msgs.map(extractMsgIds).join(','),
|
||||||
});
|
});
|
||||||
const body = result.body();
|
|
||||||
if(body.error !== undefined)
|
if(body.error !== undefined)
|
||||||
throw body.error;
|
throw body.error;
|
||||||
|
|
||||||
|
@ -76,10 +73,9 @@ const MszMessages = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const msgsDelete = async msgs => {
|
const msgsDelete = async msgs => {
|
||||||
const result = await $x.post('/messages/delete', { type: 'json', csrf: true }, {
|
const { body } = await $x.post('/messages/delete', { type: 'json', csrf: true }, {
|
||||||
messages: msgs.map(extractMsgIds).join(','),
|
messages: msgs.map(extractMsgIds).join(','),
|
||||||
});
|
});
|
||||||
const body = result.body();
|
|
||||||
if(body.error !== undefined)
|
if(body.error !== undefined)
|
||||||
throw body.error;
|
throw body.error;
|
||||||
|
|
||||||
|
@ -87,10 +83,9 @@ const MszMessages = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const msgsRestore = async msgs => {
|
const msgsRestore = async msgs => {
|
||||||
const result = await $x.post('/messages/restore', { type: 'json', csrf: true }, {
|
const { body } = await $x.post('/messages/restore', { type: 'json', csrf: true }, {
|
||||||
messages: msgs.map(extractMsgIds).join(','),
|
messages: msgs.map(extractMsgIds).join(','),
|
||||||
});
|
});
|
||||||
const body = result.body();
|
|
||||||
if(body.error !== undefined)
|
if(body.error !== undefined)
|
||||||
throw body.error;
|
throw body.error;
|
||||||
|
|
||||||
|
@ -98,11 +93,9 @@ const MszMessages = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const msgsNuke = async msgs => {
|
const msgsNuke = async msgs => {
|
||||||
const result = await $x.post('/messages/nuke', { type: 'json', csrf: true }, {
|
const { body } = await $x.post('/messages/nuke', { type: 'json', csrf: true }, {
|
||||||
messages: msgs.map(extractMsgIds).join(','),
|
messages: msgs.map(extractMsgIds).join(','),
|
||||||
});
|
});
|
||||||
|
|
||||||
const body = result.body();
|
|
||||||
if(body.error !== undefined)
|
if(body.error !== undefined)
|
||||||
throw body.error;
|
throw body.error;
|
||||||
|
|
||||||
|
@ -112,7 +105,7 @@ const MszMessages = () => {
|
||||||
const msgsUserBtns = Array.from($qa('.js-header-pms-button'));
|
const msgsUserBtns = Array.from($qa('.js-header-pms-button'));
|
||||||
if(msgsUserBtns.length > 0)
|
if(msgsUserBtns.length > 0)
|
||||||
$x.get('/messages/stats', { type: 'json' }).then(result => {
|
$x.get('/messages/stats', { type: 'json' }).then(result => {
|
||||||
const body = result.body();
|
const body = result.body;
|
||||||
if(typeof body === 'object' && typeof body.unread === 'number')
|
if(typeof body === 'object' && typeof body.unread === 'number')
|
||||||
if(body.unread > 0)
|
if(body.unread > 0)
|
||||||
for(const msgsUserBtn of msgsUserBtns)
|
for(const msgsUserBtn of msgsUserBtns)
|
||||||
|
|
|
@ -9,10 +9,9 @@ const MszMessagesRecipient = function(element) {
|
||||||
|
|
||||||
let updateHandler = undefined;
|
let updateHandler = undefined;
|
||||||
const update = async () => {
|
const update = async () => {
|
||||||
const result = await $x.post(element.dataset.msgLookup, { type: 'json', csrf: true }, {
|
const { body } = await $x.post(element.dataset.msgLookup, { type: 'json', csrf: true }, {
|
||||||
name: nameInput.value,
|
name: nameInput.value,
|
||||||
});
|
});
|
||||||
const body = result.body();
|
|
||||||
|
|
||||||
if(updateHandler !== undefined)
|
if(updateHandler !== undefined)
|
||||||
await updateHandler(body);
|
await updateHandler(body);
|
||||||
|
|
|
@ -84,12 +84,13 @@ const $x = (function() {
|
||||||
MszCSRF.token = headers.get('x-csrf-token');
|
MszCSRF.token = headers.get('x-csrf-token');
|
||||||
|
|
||||||
resolve({
|
resolve({
|
||||||
status: xhr.status,
|
get ev() { return ev; },
|
||||||
body: () => xhr.response,
|
get xhr() { return xhr; },
|
||||||
text: () => xhr.responseText,
|
|
||||||
headers: () => headers,
|
get status() { return xhr.status; },
|
||||||
xhr: xhr,
|
get headers() { return headers; },
|
||||||
ev: ev,
|
get body() { return xhr.response; },
|
||||||
|
get text() { return xhr.responseText; },
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue