mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-26 06:16:56 +09:00
feat: add release reactions and a GitHub-like reaction bar (#38415)
Adds emoji reactions to releases and moves the reaction picker of issues, comments and releases into a GitHub-like reaction bar. - Releases omit 👎 or 😕 - Drafts and tags can't be reacted to - Moved menu to tippy - Added keyboard navigation Fixes: https://github.com/go-gitea/gitea/issues/34268 Fixes: https://github.com/go-gitea/gitea/issues/16676 Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
42 files changed
+508
-313
No files matched your search
@@ -1,31 +1,44 @@
|
||||
import {POST} from '../../modules/fetch.ts';
|
||||
import {performFetchActionRequest} from '../../modules/fetch-action.ts';
|
||||
import {registerGlobalEventFunc} from '../../modules/observer.ts';
|
||||
import {createTippy} from '../../modules/tippy.ts';
|
||||
import {createElementFromHTML} from '../../utils/dom.ts';
|
||||
|
||||
export function initCompReactionSelector() {
|
||||
registerGlobalEventFunc('click', 'onReactionPickerClick', (btn: HTMLElement) => {
|
||||
if (btn._tippy) return;
|
||||
createTippy(btn, {
|
||||
content: btn.nextElementSibling!,
|
||||
theme: 'menu',
|
||||
arrow: false,
|
||||
maxWidth: 'none',
|
||||
placement: 'bottom-start',
|
||||
trigger: 'click',
|
||||
interactive: true,
|
||||
hideOnClick: true,
|
||||
}).show();
|
||||
});
|
||||
|
||||
registerGlobalEventFunc('click', 'onCommentReactionButtonClick', async (target: HTMLElement, e: Event) => {
|
||||
// there are 2 places for the "reaction" buttons, one is the top-right reaction menu, one is the bottom of the comment
|
||||
e.preventDefault();
|
||||
|
||||
if (target.classList.contains('disabled')) return;
|
||||
|
||||
const actionUrl = target.closest('[data-action-url]')!.getAttribute('data-action-url');
|
||||
const reactionContent = target.getAttribute('data-reaction-content')!;
|
||||
|
||||
const commentContainer = target.closest('.comment-container')!;
|
||||
|
||||
const bottomReactions = commentContainer.querySelector('.bottom-reactions'); // may not exist if there is no reaction
|
||||
const bottomReactionBtn = bottomReactions?.querySelector(`a[data-reaction-content="${CSS.escape(reactionContent)}"]`);
|
||||
const hasReacted = bottomReactionBtn?.getAttribute('data-has-reacted') === 'true';
|
||||
|
||||
const res = await POST(`${actionUrl}/${hasReacted ? 'unreact' : 'react'}`, {
|
||||
data: new URLSearchParams({content: reactionContent}),
|
||||
const picker = target.closest('[data-tippy-root]')?._tippy;
|
||||
picker?.hide();
|
||||
const bottomReactions = (picker?.reference ?? target).closest<HTMLElement>('.bottom-reactions')!;
|
||||
const hasReacted = target.getAttribute('data-has-reacted') === 'true';
|
||||
const res = await performFetchActionRequest(bottomReactions, {
|
||||
method: 'POST',
|
||||
url: `${bottomReactions.getAttribute('data-action-url')}/${hasReacted ? 'unreact' : 'react'}`,
|
||||
data: new URLSearchParams({content: target.getAttribute('data-reaction-content')!}),
|
||||
});
|
||||
if (!res.ok) return;
|
||||
if (!res) return;
|
||||
|
||||
const data = await res.json();
|
||||
bottomReactions?.remove();
|
||||
if (data.html) {
|
||||
commentContainer.insertAdjacentHTML('beforeend', data.html);
|
||||
}
|
||||
const hadFocus = bottomReactions.contains(document.activeElement);
|
||||
bottomReactions.querySelector('.select-reaction')?._tippy?.destroy();
|
||||
const newBottomReactions = createElementFromHTML(data.html);
|
||||
bottomReactions.replaceWith(newBottomReactions);
|
||||
if (hadFocus) newBottomReactions.querySelector<HTMLElement>('.select-reaction')?.focus();
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user