summaryrefslogtreecommitdiffstats
path: root/web_src/js/features/comp/ReactionSelector.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel@debian.org>2024-10-18 20:33:49 +0200
committerDaniel Baumann <daniel@debian.org>2024-12-12 23:57:56 +0100
commite68b9d00a6e05b3a941f63ffb696f91e554ac5ec (patch)
tree97775d6c13b0f416af55314eb6a89ef792474615 /web_src/js/features/comp/ReactionSelector.js
parentInitial commit. (diff)
downloadforgejo-e68b9d00a6e05b3a941f63ffb696f91e554ac5ec.tar.xz
forgejo-e68b9d00a6e05b3a941f63ffb696f91e554ac5ec.zip
Adding upstream version 9.0.3.
Signed-off-by: Daniel Baumann <daniel@debian.org>
Diffstat (limited to 'web_src/js/features/comp/ReactionSelector.js')
-rw-r--r--web_src/js/features/comp/ReactionSelector.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/web_src/js/features/comp/ReactionSelector.js b/web_src/js/features/comp/ReactionSelector.js
new file mode 100644
index 0000000..fd4601f
--- /dev/null
+++ b/web_src/js/features/comp/ReactionSelector.js
@@ -0,0 +1,38 @@
+import $ from 'jquery';
+import {POST} from '../../modules/fetch.js';
+
+export function initCompReactionSelector($parent) {
+ $parent.find(`.select-reaction .item.reaction, .comment-reaction-button`).on('click', async function (e) {
+ e.preventDefault();
+
+ if (this.classList.contains('disabled')) return;
+
+ const actionUrl = this.closest('[data-action-url]')?.getAttribute('data-action-url');
+ const reactionContent = this.getAttribute('data-reaction-content');
+ const hasReacted = this.closest('.comment')?.querySelector(`.ui.segment.reactions a[data-reaction-content="${reactionContent}"]`)?.getAttribute('data-has-reacted') === 'true';
+
+ const res = await POST(`${actionUrl}/${hasReacted ? 'unreact' : 'react'}`, {
+ data: new URLSearchParams({content: reactionContent}),
+ });
+
+ const data = await res.json();
+ if (data && (data.html || data.empty)) {
+ const $content = $(this).closest('.content');
+ let $react = $content.find('.segment.reactions');
+ if ((!data.empty || data.html === '') && $react.length > 0) {
+ $react.remove();
+ }
+ if (!data.empty) {
+ const $attachments = $content.find('.segment.bottom:first');
+ $react = $(data.html);
+ if ($attachments.length > 0) {
+ $react.insertBefore($attachments);
+ } else {
+ $react.appendTo($content);
+ }
+ $react.find('.dropdown').dropdown();
+ initCompReactionSelector($react);
+ }
+ }
+ });
+}