feat(WhoReacted): add toggle to disable click (#46)

* squash (#8)

squash

* lil fix

---------

Co-authored-by: thororen1234 <78185467+thororen1234@users.noreply.github.com>
This commit is contained in:
panbread 2024-10-03 18:55:53 +04:00 committed by GitHub
parent 026d39aef2
commit 11ad3bceb6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -16,12 +16,13 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import { definePluginSettings } from "@api/Settings";
import ErrorBoundary from "@components/ErrorBoundary"; import ErrorBoundary from "@components/ErrorBoundary";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import { sleep } from "@utils/misc"; import { sleep } from "@utils/misc";
import { Queue } from "@utils/Queue"; import { Queue } from "@utils/Queue";
import { useForceUpdater } from "@utils/react"; import { useForceUpdater } from "@utils/react";
import definePlugin from "@utils/types"; import definePlugin, { OptionType } from "@utils/types";
import { findByPropsLazy, findComponentByCodeLazy } from "@webpack"; import { findByPropsLazy, findComponentByCodeLazy } from "@webpack";
import { ChannelStore, Constants, FluxDispatcher, React, RestAPI, Tooltip } from "@webpack/common"; import { ChannelStore, Constants, FluxDispatcher, React, RestAPI, Tooltip } from "@webpack/common";
import { CustomEmoji } from "@webpack/types"; import { CustomEmoji } from "@webpack/types";
@ -97,11 +98,20 @@ function handleClickAvatar(event: React.MouseEvent<HTMLElement, MouseEvent>) {
event.stopPropagation(); event.stopPropagation();
} }
const settings = definePluginSettings({
avatarClick: {
description: "Toggle clicking avatars in reactions",
type: OptionType.BOOLEAN,
default: false,
restartNeeded: true
}
});
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, Devs.newwares], authors: [Devs.Ven, Devs.KannaDev, Devs.newwares],
settings,
patches: [ patches: [
{ {
find: ",reactionRef:", find: ",reactionRef:",
@ -159,21 +169,37 @@ export default definePlugin({
const reactions = getReactionsWithQueue(message, emoji, type); const reactions = getReactionsWithQueue(message, emoji, type);
const users = Object.values(reactions).filter(Boolean) as User[]; const users = Object.values(reactions).filter(Boolean) as User[];
console.log(settings.store.avatarClick);
return ( return (
<div <div
style={{ marginLeft: "0.5em", transform: "scale(0.9)" }} style={{ marginLeft: "0.5em", transform: "scale(0.9)" }}
> >
<div onClick={handleClickAvatar}> {settings.store.avatarClick ? (
<UserSummaryItem <div onClick={handleClickAvatar}>
users={users} <UserSummaryItem
guildId={ChannelStore.getChannel(message.channel_id)?.guild_id} users={users}
renderIcon={false} guildId={ChannelStore.getChannel(message.channel_id)?.guild_id}
max={5} renderIcon={false}
showDefaultAvatarsForNullUsers max={5}
showUserPopout showDefaultAvatarsForNullUsers
renderMoreUsers={makeRenderMoreUsers(users)} showUserPopout
/> renderMoreUsers={makeRenderMoreUsers(users)}
</div> />
</div>
) : (
<div>
<UserSummaryItem
users={users}
guildId={ChannelStore.getChannel(message.channel_id)?.guild_id}
renderIcon={false}
max={5}
showDefaultAvatarsForNullUsers
showUserPopout={false}
renderMoreUsers={makeRenderMoreUsers(users)}
/>
</div>
)}
</div> </div>
); );
}, },