You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ReactionSelector.js 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import $ from 'jquery';
  2. import {POST} from '../../modules/fetch.js';
  3. export function initCompReactionSelector($parent) {
  4. $parent.find(`.select-reaction .item.reaction, .comment-reaction-button`).on('click', async function (e) {
  5. e.preventDefault();
  6. if (this.classList.contains('disabled')) return;
  7. const actionUrl = this.closest('[data-action-url]')?.getAttribute('data-action-url');
  8. const reactionContent = this.getAttribute('data-reaction-content');
  9. const hasReacted = this.closest('.ui.segment.reactions')?.querySelector(`a[data-reaction-content="${reactionContent}"]`)?.getAttribute('data-has-reacted') === 'true';
  10. const res = await POST(`${actionUrl}/${hasReacted ? 'unreact' : 'react'}`, {
  11. data: new URLSearchParams({content: reactionContent}),
  12. });
  13. const data = await res.json();
  14. if (data && (data.html || data.empty)) {
  15. const $content = $(this).closest('.content');
  16. let $react = $content.find('.segment.reactions');
  17. if ((!data.empty || data.html === '') && $react.length > 0) {
  18. $react.remove();
  19. }
  20. if (!data.empty) {
  21. const $attachments = $content.find('.segment.bottom:first');
  22. $react = $(data.html);
  23. if ($attachments.length > 0) {
  24. $react.insertBefore($attachments);
  25. } else {
  26. $react.appendTo($content);
  27. }
  28. $react.find('.dropdown').dropdown();
  29. initCompReactionSelector($react);
  30. }
  31. }
  32. });
  33. }