Skip to content

Commit

Permalink
Test closures and update
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtOfCode- committed Oct 16, 2024
1 parent 1bf6150 commit 0924c01
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ document.addEventListener('DOMContentLoaded', async () => {
});

if (document.cookie.indexOf('dismiss_fvn') === -1) {
document.querySelector('#fvn-dismiss').addEventListener('click', _ev => {
QPixel.DOM.addSelectorListener('click', '#fvn-dismiss', _ev => {
document.cookie = 'dismiss_fvn=true; path=/; expires=Fri, 31 Dec 9999 23:59:59 GMT';
});
}
Expand Down
19 changes: 11 additions & 8 deletions app/assets/javascripts/closure.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,25 @@ document.addEventListener('DOMContentLoaded', async () => {

const self = ev.target;
const activeRadio = self.closest('.js-close-box').querySelector("input[type='radio'][name='close-reason']:checked");

if (!activeRadio) {
QPixel.createNotification('danger', 'You must select a close reason.');
return;
}

const otherPostInput = activeRadio.closest('.widget--body').querySelector('.js-close-other-post');
const otherPostRequired = !!activeRadio.dataset.rop;
const otherPostRequired = activeRadio.dataset.rop === 'true';
const data = {
'reason_id': activeRadio.value,
'other_post': otherPostInput.value
'reason_id': parseInt(activeRadio.value, 10),
'other_post': otherPostInput?.value
// option will be silently discarded if no input element
};

if (data['other_post'] && data['other_post'].match(/\/[0-9]+$/)) {
data['other_post'] = data['other_post'].replace(/.*\/([0-9]+)$/, "$1");
}

if (!activeRadio.value) {
QPixel.createNotification('danger', 'You must select a close reason.');
return;
}
if (!otherPostInput.value && otherPostRequired) {
if (!otherPostInput?.value && otherPostRequired) {
QPixel.createNotification('danger', 'You must enter an ID or URL to another post.');
return;
}
Expand All @@ -30,6 +32,7 @@ document.addEventListener('DOMContentLoaded', async () => {
body: JSON.stringify(data),
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'X-CSRF-Token': QPixel.csrfToken()
}
});
Expand Down

0 comments on commit 0924c01

Please sign in to comment.