WhoReacted: fix scroll jumping when rendering users (#2271)
Co-authored-by: V <vendicated@riseup.net>
This commit is contained in:
parent
3e332a6062
commit
021948c919
2 changed files with 24 additions and 4 deletions
|
@ -29,7 +29,7 @@ import { Message, ReactionEmoji, User } from "discord-types/general";
|
||||||
|
|
||||||
const UserSummaryItem = findComponentByCodeLazy("defaultRenderUser", "showDefaultAvatarsForNullUsers");
|
const UserSummaryItem = findComponentByCodeLazy("defaultRenderUser", "showDefaultAvatarsForNullUsers");
|
||||||
const AvatarStyles = findByPropsLazy("moreUsers", "emptyUser", "avatarContainer", "clickableAvatar");
|
const AvatarStyles = findByPropsLazy("moreUsers", "emptyUser", "avatarContainer", "clickableAvatar");
|
||||||
|
let Scroll: any = null;
|
||||||
const queue = new Queue();
|
const queue = new Queue();
|
||||||
let reactions: Record<string, ReactionCacheEntry>;
|
let reactions: Record<string, ReactionCacheEntry>;
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ function handleClickAvatar(event: React.MouseEvent<HTMLElement, MouseEvent>) {
|
||||||
export default definePlugin({
|
export default definePlugin({
|
||||||
name: "WhoReacted",
|
name: "WhoReacted",
|
||||||
description: "Renders the avatars of users who reacted to a message",
|
description: "Renders the avatars of users who reacted to a message",
|
||||||
authors: [Devs.Ven, Devs.KannaDev],
|
authors: [Devs.Ven, Devs.KannaDev, Devs.newwares],
|
||||||
|
|
||||||
patches: [{
|
patches: [{
|
||||||
find: ",reactionRef:",
|
find: ",reactionRef:",
|
||||||
|
@ -105,7 +105,19 @@ export default definePlugin({
|
||||||
match: /(?<=CONNECTION_OPEN:function\(\){)(\i)={}/,
|
match: /(?<=CONNECTION_OPEN:function\(\){)(\i)={}/,
|
||||||
replace: "$&;$self.reactions=$1"
|
replace: "$&;$self.reactions=$1"
|
||||||
}
|
}
|
||||||
}],
|
},
|
||||||
|
{
|
||||||
|
|
||||||
|
find: "cleanAutomaticAnchor(){",
|
||||||
|
replacement: {
|
||||||
|
match: /this\.automaticAnchor=null,this\.messageFetchAnchor=null,/,
|
||||||
|
replace: "$&$self.setScrollObj(this),"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
setScrollObj(scroll: any) {
|
||||||
|
Scroll = scroll;
|
||||||
|
},
|
||||||
|
|
||||||
renderUsers(props: RootObject) {
|
renderUsers(props: RootObject) {
|
||||||
return props.message.reactions.length > 10 ? null : (
|
return props.message.reactions.length > 10 ? null : (
|
||||||
|
@ -114,9 +126,13 @@ export default definePlugin({
|
||||||
</ErrorBoundary>
|
</ErrorBoundary>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
_renderUsers({ message, emoji, type }: RootObject) {
|
_renderUsers({ message, emoji, type }: RootObject) {
|
||||||
const forceUpdate = useForceUpdater();
|
const forceUpdate = useForceUpdater();
|
||||||
|
React.useLayoutEffect(() => { // bc need to prevent autoscrolling
|
||||||
|
if (Scroll?.scrollCounter > 0) {
|
||||||
|
Scroll.setAutomaticAnchor(null);
|
||||||
|
}
|
||||||
|
});
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
const cb = (e: any) => {
|
const cb = (e: any) => {
|
||||||
if (e.messageId === message.id)
|
if (e.messageId === message.id)
|
||||||
|
|
|
@ -413,6 +413,10 @@ export const Devs = /* #__PURE__*/ Object.freeze({
|
||||||
Elvyra: {
|
Elvyra: {
|
||||||
name: "Elvyra",
|
name: "Elvyra",
|
||||||
id: 708275751816003615n,
|
id: 708275751816003615n,
|
||||||
|
},
|
||||||
|
newwares: {
|
||||||
|
name: "newwares",
|
||||||
|
id: 421405303951851520n
|
||||||
}
|
}
|
||||||
} satisfies Record<string, Dev>);
|
} satisfies Record<string, Dev>);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue