-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Rewrite and restyle reaction selector and enable no-sizzle eslint rule #30453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
3d08728
Rewrite reaction selector and enable no-sizzle eslint rule
silverwind d7f7aaf
remove .ui
silverwind be8f933
Merge branch 'main' into nosizzle
silverwind 56cf6b5
avoid necessary init by using higher-up parent
silverwind 8b090f1
whitespace
silverwind fbd25fa
remove unneeded .matches
silverwind adf6d1c
remove optional chaining
silverwind 456ea0f
simplify for loop
silverwind 6e00683
fix all bugs
silverwind 9c95a11
refactor
wxiaoguang 472e6bd
fix conversation-holder comment style
wxiaoguang 921fada
fix emoji size
wxiaoguang 23535a2
re-style
silverwind cb755a4
fix lint
silverwind 37b004c
fix selector to only target timeline item
silverwind 84b62cc
simplify styles
wxiaoguang 602c1b9
remove pb-4
wxiaoguang fc753e7
fix padding and tweak gap between comments
silverwind 4e591c7
Merge branch 'main' into nosizzle
GiteaBot c3e968e
Merge branch 'main' into nosizzle
GiteaBot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,45 @@ | ||
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(); | ||
export function initCompReactionSelector() { | ||
const containers = document.querySelectorAll('.comment-container, .code-comment'); | ||
if (!containers.length) return; | ||
|
||
if (this.classList.contains('disabled')) return; | ||
for (const container of containers) { | ||
container.addEventListener('click', async (e) => { | ||
const item = e.target.matches('.item.reaction') ? e.target : e.target.closest('.item.reaction'); | ||
const button = e.target.matches('.comment-reaction-button') ? e.target : e.target.closest('.comment-reaction-button'); | ||
if (!item && !button) return; | ||
e.preventDefault(); | ||
|
||
const actionUrl = this.closest('[data-action-url]')?.getAttribute('data-action-url'); | ||
const reactionContent = this.getAttribute('data-reaction-content'); | ||
const hasReacted = this.closest('.ui.segment.reactions')?.querySelector(`a[data-reaction-content="${reactionContent}"]`)?.getAttribute('data-has-reacted') === 'true'; | ||
const target = item || button; | ||
if (target.classList.contains('disabled')) return; | ||
|
||
const res = await POST(`${actionUrl}/${hasReacted ? 'unreact' : 'react'}`, { | ||
data: new URLSearchParams({content: reactionContent}), | ||
}); | ||
const actionUrl = target.closest('[data-action-url]')?.getAttribute('data-action-url'); | ||
silverwind marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const reactionContent = target.getAttribute('data-reaction-content'); | ||
const hasReacted = target.closest('.segment.reactions')?.querySelector(`a[data-reaction-content="${CSS.escape(reactionContent)}"]`)?.getAttribute('data-has-reacted') === 'true'; | ||
const content = target.closest('.content'); | ||
|
||
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); | ||
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 reactions = content.querySelector('.segment.reactions'); | ||
if ((!data.empty || data.html === '') && reactions) { | ||
reactions.remove(); | ||
} | ||
if (!data.empty) { | ||
const attachments = content.querySelector('.segment.bottom'); | ||
if (attachments) { | ||
attachments.insertAdjacentHTML('beforebegin', data.html); | ||
} else { | ||
content.insertAdjacentHTML('beforeend', data.html); | ||
} | ||
$(content.querySelectorAll('.segment.reactions .dropdown')).dropdown(); | ||
} | ||
$react.find('.dropdown').dropdown(); | ||
initCompReactionSelector($react); | ||
} | ||
} | ||
}); | ||
}); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.