Refactor question generating to use request.js
This commit is contained in:
parent
90f33dd76c
commit
3b6ade483f
|
@ -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