您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ReactionSelector.js 1.6KB

123456789101112131415161718192021222324252627282930313233343536
  1. import $ from 'jquery';
  2. import {POST} from '../../modules/fetch.js';
  3. export function initCompReactionSelector() {
  4. for (const container of document.querySelectorAll('.issue-content, .diff-file-body')) {
  5. container.addEventListener('click', async (e) => {
  6. // there are 2 places for the "reaction" buttons, one is the top-right reaction menu, one is the bottom of the comment
  7. const target = e.target.closest('.comment-reaction-button');
  8. if (!target) return;
  9. e.preventDefault();
  10. if (target.classList.contains('disabled')) return;
  11. const actionUrl = target.closest('[data-action-url]').getAttribute('data-action-url');
  12. const reactionContent = target.getAttribute('data-reaction-content');
  13. const commentContainer = target.closest('.comment-container');
  14. const bottomReactions = commentContainer.querySelector('.bottom-reactions'); // may not exist if there is no reaction
  15. const bottomReactionBtn = bottomReactions?.querySelector(`a[data-reaction-content="${CSS.escape(reactionContent)}"]`);
  16. const hasReacted = bottomReactionBtn?.getAttribute('data-has-reacted') === 'true';
  17. const res = await POST(`${actionUrl}/${hasReacted ? 'unreact' : 'react'}`, {
  18. data: new URLSearchParams({content: reactionContent}),
  19. });
  20. const data = await res.json();
  21. bottomReactions?.remove();
  22. if (data.html) {
  23. commentContainer.insertAdjacentHTML('beforeend', data.html);
  24. const bottomReactionsDropdowns = commentContainer.querySelectorAll('.bottom-reactions .dropdown.select-reaction');
  25. $(bottomReactionsDropdowns).dropdown(); // re-init the dropdown
  26. }
  27. });
  28. }
  29. }