From f65c9bdd5ebd65d849ed36176cdcdd98c5509a67 Mon Sep 17 00:00:00 2001 From: Paul Makles Date: Sun, 6 Mar 2022 19:13:12 +0000 Subject: [PATCH] fix: context menus are now bound by spread --- package.json | 2 +- src/components/common/messaging/Message.tsx | 29 ++++++++----------- .../common/messaging/SystemMessage.tsx | 17 +++++------ .../messaging/attachments/Attachment.tsx | 4 +-- .../navigation/items/ButtonItem.tsx | 26 +++++++---------- .../navigation/left/ServerListSidebar.tsx | 26 +++++++---------- .../navigation/left/ServerSidebar.tsx | 14 +++------ src/pages/friends/Friend.tsx | 11 +++---- yarn.lock | 8 ++--- 9 files changed, 55 insertions(+), 82 deletions(-) diff --git a/package.json b/package.json index 122d5dde..50331fb7 100644 --- a/package.json +++ b/package.json @@ -135,7 +135,7 @@ "mobx": "^6.3.2", "mobx-react-lite": "^3.2.0", "preact": "^10.5.14", - "preact-context-menu": "0.3.0-patch.1", + "preact-context-menu": "0.4.0-patch.0", "preact-i18n": "^2.4.0-preactx", "prettier": "^2.3.1", "prismjs": "^1.23.0", diff --git a/src/components/common/messaging/Message.tsx b/src/components/common/messaging/Message.tsx index 6cd1525c..895b5ecf 100644 --- a/src/components/common/messaging/Message.tsx +++ b/src/components/common/messaging/Message.tsx @@ -1,8 +1,7 @@ import { observer } from "mobx-react-lite"; import { Message as MessageObject } from "revolt.js/dist/maps/Messages"; -import { Ref } from "preact"; -import { refContextMenu } from "preact-context-menu"; +import { useTriggerEvents } from "preact-context-menu"; import { memo } from "preact/compat"; import { useEffect, useState } from "preact/hooks"; @@ -62,14 +61,12 @@ const Message = observer( const head = preferHead || (message.reply_ids && message.reply_ids.length > 0); - // ! TODO: tell fatal to make this type generic - // bree: Fatal please... const userContext = attachContext - ? (refContextMenu("Menu", { + ? useTriggerEvents("Menu", { user: message.author_id, contextualChannel: message.channel_id, // eslint-disable-next-line - }) as any) + }) : undefined; const openProfile = () => @@ -120,15 +117,13 @@ const Message = observer( sending={typeof queued !== "undefined"} mention={message.mention_ids?.includes(client.user!._id)} failed={typeof queued?.error !== "undefined"} - ref={ - attachContext - ? (refContextMenu("Menu", { - message, - contextualChannel: message.channel_id, - queued, - }) as Ref) - : undefined - } + {...(attachContext + ? useTriggerEvents("Menu", { + message, + contextualChannel: message.channel_id, + queued, + }) + : undefined)} onMouseEnter={() => setAnimate(true)} onMouseLeave={() => setAnimate(false)}> @@ -138,9 +133,9 @@ const Message = observer( url={message.generateMasqAvatarURL()} target={user} size={36} - innerRef={userContext} onClick={handleUserClick} animate={mouseHovering} + {...(userContext as any)} showServerIdentity /> ) : ( @@ -155,8 +150,8 @@ const Message = observer( className="author" showServerIdentity onClick={handleUserClick} - innerRef={userContext} masquerade={message.masquerade!} + {...userContext} /> ) - : undefined - }> + {...(attachContext + ? useTriggerEvents("Menu", { + message, + contextualChannel: message.channel, + }) + : undefined)}> {!hideInfo && ( diff --git a/src/components/common/messaging/attachments/Attachment.tsx b/src/components/common/messaging/attachments/Attachment.tsx index 3000b2b3..a9234bf1 100644 --- a/src/components/common/messaging/attachments/Attachment.tsx +++ b/src/components/common/messaging/attachments/Attachment.tsx @@ -2,7 +2,7 @@ import { Attachment as AttachmentI } from "revolt-api/types/Autumn"; import styles from "./Attachment.module.scss"; import classNames from "classnames"; -import { refContextMenu } from "preact-context-menu"; +import { useTriggerEvents } from "preact-context-menu"; import { useContext, useState } from "preact/hooks"; import { AppContext } from "../../../../context/revoltjs/RevoltClient"; @@ -37,7 +37,7 @@ export default function Attachment({ attachment, hasContent }: Props) { { typeof channel !== "undefined" || (user.online && user.status?.presence !== Presence.Invisible) } - ref={ - refContextMenu("Menu", { - user: user._id, - channel: channel?._id, - unread: alert, - contextualChannel: context?._id, - }) as Ref - }> + {...useTriggerEvents("Menu", { + user: user._id, + channel: channel?._id, + unread: alert, + contextualChannel: context?._id, + })}> { data-muted={muted} aria-label={channel.name} className={classNames(styles.item, { [styles.compact]: compact })} - ref={ - refContextMenu("Menu", { - channel: channel._id, - unread: !!alert, - }) as Ref - }> + {...useTriggerEvents("Menu", { + channel: channel._id, + unread: !!alert, + })}> {
- } + {...useTriggerEvents("Status")} onClick={() => homeActive && history.push("/settings") }> @@ -303,12 +301,10 @@ export default observer(() => { - }> + {...useTriggerEvents("Menu", { + channel: x._id, + unread: true, + })}>
{ to={state.layout.getServerPath(server._id)}> - }> + {...useTriggerEvents("Menu", { + server: server._id, + unread: isUnread, + })}> { const client = useClient(); const state = useApplicationState(); @@ -146,11 +142,9 @@ export default observer(() => { - }> + {...useTriggerEvents("Menu", { + server_list: server._id, + })}> {elements} diff --git a/src/pages/friends/Friend.tsx b/src/pages/friends/Friend.tsx index e1782e7d..4715352b 100644 --- a/src/pages/friends/Friend.tsx +++ b/src/pages/friends/Friend.tsx @@ -8,9 +8,8 @@ import { User } from "revolt.js/dist/maps/Users"; import styles from "./Friend.module.scss"; import classNames from "classnames"; import { Ref } from "preact"; -import { refContextMenu } from "preact-context-menu"; +import { useTriggerEvents } from "preact-context-menu"; import { Text } from "preact-i18n"; -import { useContext } from "preact/hooks"; import { stopPropagation } from "../../lib/stopPropagation"; import { voiceState } from "../../lib/vortex/VoiceState"; @@ -133,11 +132,9 @@ export const Friend = observer(({ user }: Props) => {
openScreen({ id: "profile", user_id: user._id })} - ref={ - refContextMenu("Menu", { - user: user._id, - }) as Ref - }> + {...useTriggerEvents("Menu", { + user: user._id, + })}>
{user.username} diff --git a/yarn.lock b/yarn.lock index 332a94b0..56a07147 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3999,10 +3999,10 @@ postcss@^8.3.8: picocolors "^1.0.0" source-map-js "^0.6.2" -preact-context-menu@0.3.0-patch.1: - version "0.3.0-patch.1" - resolved "https://registry.yarnpkg.com/preact-context-menu/-/preact-context-menu-0.3.0-patch.1.tgz#0dcaa794f30f83bf1e1a94e93403dc1cf80fe2ec" - integrity sha512-K/Fe7/F2fZmuPw9farSyd/IDu0+ScM2fvopRHk681mMlVKBRVHRwJQWyDL1hEY3E7uTe7TwyyU09knsfu48ycw== +preact-context-menu@0.4.0-patch.0: + version "0.4.0-patch.0" + resolved "https://registry.yarnpkg.com/preact-context-menu/-/preact-context-menu-0.4.0-patch.0.tgz#6a4da06b2e304e7a1cb6e940bad7e15a428ff18c" + integrity sha512-eYR4xjvZVlw2HZmPFZHi+PehCldUupsIZXYHkpc96Se9Y4QwkBkHs7YFy2PqTbWXAJwaDFdX+OA0VzXUtVXlyg== dependencies: preact "^10.5.14"