Style hide link with Crayons (#8820)

This commit is contained in:
Michael Kohl 2020-06-22 19:27:38 +07:00 committed by GitHub
parent e56bb3ade5
commit 359f2cb2c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 19 deletions

View file

@ -8,16 +8,16 @@ All child comments in this thread will also be hidden.
For further actions, you may consider blocking this person and/or reporting abuse.
`;
const confirmHide = window.confirm(confirmMsg)
if(confirmHide) {
const confirmHide = window.confirm(confirmMsg);
if (confirmHide) {
fetch(`/comments/${commentId}/hide`, {
method: 'PATCH',
headers: {
'X-CSRF-Token': window.csrfToken,
},
})
.then(response => response.json())
.then(response => {
.then((response) => response.json())
.then((response) => {
if (response.hidden === 'true') {
/* eslint-disable-next-line no-restricted-globals */
location.reload();
@ -33,8 +33,8 @@ For further actions, you may consider blocking this person and/or reporting abus
'X-CSRF-Token': window.csrfToken,
},
})
.then(response => response.json())
.then(response => {
.then((response) => response.json())
.then((response) => {
if (response.hidden === 'false') {
/* eslint-disable-next-line no-restricted-globals */
location.reload();
@ -42,21 +42,20 @@ For further actions, you may consider blocking this person and/or reporting abus
});
}
const hideButtons = Array.from(
document.getElementsByClassName('hide-comment')
)
hideButtons.forEach(butt => {
const { hideType, commentId } = butt.dataset
const hideLinks = Array.from(document.getElementsByClassName('hide-comment'));
hideLinks.forEach((link) => {
const { hideType, commentId } = link.dataset;
if (hideType === 'hide') {
butt.addEventListener('click', () => {
hide(commentId)
})
link.addEventListener('click', () => {
hide(commentId);
});
} else if (hideType === 'unhide') {
butt.addEventListener('click', () => {
link.addEventListener('click', () => {
unhide(commentId);
});
}
})
});
}
/* eslint-enable no-alert */
/* eslint-enable no-alert */

View file

@ -63,7 +63,7 @@
</span>
<% action = comment.hidden_by_commentable_user ? "Unhide" : "Hide" %>
<span class="comment-actions hidden" data-action="hide-button" data-commentable-user-id="<%= commentable.user_id %>" data-user-id="<%= comment.user_id %>" style="display: none; width: 100%;">
<button class="hide-comment" type="button" data-hide-type="<%= action.downcase %>" data-comment-id="<%= comment.id %>">
<a class="crayons-link crayons-link--block hide-comment" data-hide-type="<%= action.downcase %>" data-comment-id="<%= comment.id %>">
<%= action %>
</button>
</span>