Merge pull request #658 from Retrospring/feature/request-js-inbox
Refactor inbox TS functionality to use `@rails/request.js`
This commit is contained in:
commit
e4155bf21f
|
@ -1,4 +1,4 @@
|
||||||
import Rails from '@rails/ujs';
|
import { post } from '@rails/request.js';
|
||||||
import swal from 'sweetalert';
|
import swal from 'sweetalert';
|
||||||
|
|
||||||
import I18n from 'retrospring/i18n';
|
import I18n from 'retrospring/i18n';
|
||||||
|
@ -43,20 +43,18 @@ export function deleteAllQuestionsHandler(event: Event): void {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Rails.ajax({
|
post('/ajax/delete_all_inbox')
|
||||||
url: '/ajax/delete_all_inbox',
|
.then(async response => {
|
||||||
type: 'POST',
|
const data = await response.json;
|
||||||
dataType: 'json',
|
|
||||||
success: (data) => {
|
|
||||||
if (!data.success) return false;
|
if (!data.success) return false;
|
||||||
|
|
||||||
updateDeleteButton(false);
|
updateDeleteButton(false);
|
||||||
document.querySelector('#entries').innerHTML = 'Nothing to see here!';
|
document.querySelector('#entries').innerHTML = 'Nothing to see here!';
|
||||||
},
|
})
|
||||||
error: (data, status, xhr) => {
|
.catch(err => {
|
||||||
console.log(data, status, xhr);
|
console.log(err);
|
||||||
showErrorNotification(I18n.translate('frontend.error.message'));
|
showErrorNotification(I18n.translate('frontend.error.message'));
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -77,20 +75,18 @@ export function deleteAllAuthorQuestionsHandler(event: Event): void {
|
||||||
}, (returnValue) => {
|
}, (returnValue) => {
|
||||||
if (returnValue === null) return false;
|
if (returnValue === null) return false;
|
||||||
|
|
||||||
Rails.ajax({
|
post(`/ajax/delete_all_inbox/${location.pathname.split('/')[2]}`)
|
||||||
url: `/ajax/delete_all_inbox/${location.pathname.split('/')[2]}`,
|
.then(async response => {
|
||||||
type: 'POST',
|
const data = await response.json;
|
||||||
dataType: 'json',
|
|
||||||
success: (data) => {
|
|
||||||
if (!data.success) return false;
|
if (!data.success) return false;
|
||||||
|
|
||||||
updateDeleteButton(false);
|
updateDeleteButton(false);
|
||||||
document.querySelector('#entries').innerHTML = 'Nothing to see here!';
|
document.querySelector('#entries').innerHTML = 'Nothing to see here!';
|
||||||
},
|
})
|
||||||
error: (data, status, xhr) => {
|
.catch(err => {
|
||||||
console.log(data, status, xhr);
|
console.log(err);
|
||||||
showErrorNotification(I18n.translate('frontend.error.message'));
|
showErrorNotification(I18n.translate('frontend.error.message'));
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
import Rails from '@rails/ujs';
|
import { post } from '@rails/request.js';
|
||||||
|
|
||||||
import { updateDeleteButton } from '../delete';
|
import { updateDeleteButton } from '../delete';
|
||||||
import { showNotification, showErrorNotification } from 'utilities/notifications';
|
import { showNotification, showErrorNotification } from 'utilities/notifications';
|
||||||
|
@ -22,11 +22,13 @@ export function answerEntryHandler(event: Event): void {
|
||||||
inbox: 'true'
|
inbox: 'true'
|
||||||
};
|
};
|
||||||
|
|
||||||
Rails.ajax({
|
post('/ajax/answer', {
|
||||||
url: '/ajax/answer',
|
body: data,
|
||||||
type: 'POST',
|
contentType: 'application/json'
|
||||||
data: new URLSearchParams(data).toString(),
|
})
|
||||||
success: (data) => {
|
.then(async response => {
|
||||||
|
const data = await response.json;
|
||||||
|
|
||||||
if (!data.success) {
|
if (!data.success) {
|
||||||
showErrorNotification(data.message);
|
showErrorNotification(data.message);
|
||||||
element.disabled = false;
|
element.disabled = false;
|
||||||
|
@ -35,11 +37,10 @@ export function answerEntryHandler(event: Event): void {
|
||||||
updateDeleteButton(false);
|
updateDeleteButton(false);
|
||||||
showNotification(data.message);
|
showNotification(data.message);
|
||||||
(inboxEntry as HTMLElement).remove();
|
(inboxEntry as HTMLElement).remove();
|
||||||
},
|
})
|
||||||
error: (data, status, xhr) => {
|
.catch(err => {
|
||||||
console.log(data, status, xhr);
|
console.log(err);
|
||||||
element.disabled = false;
|
element.disabled = false;
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import Rails from '@rails/ujs';
|
import { post } from '@rails/request.js';
|
||||||
|
|
||||||
import { showErrorNotification, showNotification } from "utilities/notifications";
|
import { showErrorNotification, showNotification } from "utilities/notifications";
|
||||||
import I18n from "retrospring/i18n";
|
import I18n from "retrospring/i18n";
|
||||||
|
@ -10,21 +10,22 @@ export function blockAnonEventHandler(event: Event): void {
|
||||||
question: element.getAttribute('data-q-id'),
|
question: element.getAttribute('data-q-id'),
|
||||||
};
|
};
|
||||||
|
|
||||||
Rails.ajax({
|
post('/ajax/block_anon', {
|
||||||
url: '/ajax/block_anon',
|
body: data,
|
||||||
type: 'POST',
|
contentType: 'application/json'
|
||||||
data: new URLSearchParams(data).toString(),
|
})
|
||||||
success: (data) => {
|
.then(async response => {
|
||||||
|
const data = await response.json;
|
||||||
|
|
||||||
if (!data.success) return false;
|
if (!data.success) return false;
|
||||||
const inboxEntry: Node = element.closest('.inbox-entry');
|
const inboxEntry: Node = element.closest('.inbox-entry');
|
||||||
|
|
||||||
showNotification(data.message);
|
showNotification(data.message);
|
||||||
|
|
||||||
(inboxEntry as HTMLElement).remove();
|
(inboxEntry as HTMLElement).remove();
|
||||||
},
|
})
|
||||||
error: (data, status, xhr) => {
|
.catch(err => {
|
||||||
console.log(data, status, xhr);
|
console.log(err);
|
||||||
showErrorNotification(I18n.translate('frontend.error.message'));
|
showErrorNotification(I18n.translate('frontend.error.message'));
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
import Rails from '@rails/ujs';
|
import { post } from '@rails/request.js';
|
||||||
import swal from 'sweetalert';
|
import swal from 'sweetalert';
|
||||||
|
|
||||||
import I18n from 'retrospring/i18n';
|
import I18n from 'retrospring/i18n';
|
||||||
|
@ -28,11 +28,13 @@ export function deleteEntryHandler(event: Event): void {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Rails.ajax({
|
post('/ajax/delete_inbox', {
|
||||||
url: '/ajax/delete_inbox',
|
body: data,
|
||||||
type: 'POST',
|
contentType: 'application/json'
|
||||||
data: new URLSearchParams(data).toString(),
|
})
|
||||||
success: (data) => {
|
.then(async response => {
|
||||||
|
const data = await response.json;
|
||||||
|
|
||||||
if (!data.success) return false;
|
if (!data.success) return false;
|
||||||
const inboxEntry: Node = element.closest('.inbox-entry');
|
const inboxEntry: Node = element.closest('.inbox-entry');
|
||||||
|
|
||||||
|
@ -40,11 +42,10 @@ export function deleteEntryHandler(event: Event): void {
|
||||||
showNotification(data.message);
|
showNotification(data.message);
|
||||||
|
|
||||||
(inboxEntry as HTMLElement).remove();
|
(inboxEntry as HTMLElement).remove();
|
||||||
},
|
})
|
||||||
error: (data, status, xhr) => {
|
.catch(err => {
|
||||||
console.log(data, status, xhr);
|
console.log(err);
|
||||||
showErrorNotification(I18n.translate('frontend.error.message'));
|
showErrorNotification(I18n.translate('frontend.error.message'));
|
||||||
}
|
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
}
|
}
|
|
@ -1,23 +1,21 @@
|
||||||
import Rails from '@rails/ujs';
|
import { post } from '@rails/request.js';
|
||||||
|
|
||||||
import I18n from 'retrospring/i18n';
|
import I18n from 'retrospring/i18n';
|
||||||
import { updateDeleteButton } from './delete';
|
import { updateDeleteButton } from './delete';
|
||||||
import { showErrorNotification } from 'utilities/notifications';
|
import { showErrorNotification } from 'utilities/notifications';
|
||||||
|
|
||||||
export function generateQuestionHandler(): void {
|
export function generateQuestionHandler(): void {
|
||||||
Rails.ajax({
|
post('/ajax/generate_question')
|
||||||
url: '/ajax/generate_question',
|
.then(async response => {
|
||||||
type: 'POST',
|
const data = await response.json;
|
||||||
dataType: 'json',
|
|
||||||
success: (data) => {
|
|
||||||
if (!data.success) return false;
|
if (!data.success) return false;
|
||||||
|
|
||||||
document.querySelector('#entries').insertAdjacentHTML('afterbegin', data.render);
|
document.querySelector('#entries').insertAdjacentHTML('afterbegin', data.render);
|
||||||
updateDeleteButton();
|
updateDeleteButton();
|
||||||
},
|
})
|
||||||
error: (data, status, xhr) => {
|
.catch(err => {
|
||||||
console.log(data, status, xhr);
|
console.log(err);
|
||||||
showErrorNotification(I18n.translate('frontend.error.message'));
|
showErrorNotification(I18n.translate('frontend.error.message'));
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
Loading…
Reference in New Issue