From 7982489ab63bbeb9def63dd2eee33f8f4eee3824 Mon Sep 17 00:00:00 2001 From: Paul Date: Fri, 2 Jul 2021 13:35:50 +0100 Subject: [PATCH] Link to profiles from message / member sidebar. --- src/components/common/messaging/Message.tsx | 8 +++++-- .../navigation/items/ButtonItem.tsx | 23 ++++++++++++------- .../navigation/right/MemberSidebar.tsx | 16 ++++++------- src/context/intermediate/Intermediate.tsx | 2 +- 4 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/components/common/messaging/Message.tsx b/src/components/common/messaging/Message.tsx index 0c536949..8c27c513 100644 --- a/src/components/common/messaging/Message.tsx +++ b/src/components/common/messaging/Message.tsx @@ -14,6 +14,7 @@ import { useContext } from "preact/hooks"; import { AppContext } from "../../../context/revoltjs/RevoltClient"; import { memo } from "preact/compat"; import { MessageReply } from "./attachments/MessageReply"; +import { useIntermediate } from "../../../context/intermediate/Intermediate"; interface Props { attachContext?: boolean @@ -29,10 +30,13 @@ function Message({ attachContext, message, contrast, content: replacement, head: // TODO: of dependencies. We only need to update on u/avatar. const user = useUser(message.author); const client = useContext(AppContext); + const { openScreen } = useIntermediate(); const content = message.content as string; const head = preferHead || (message.replies && message.replies.length > 0); + const userContext = attachContext ? attachContextMenu('Menu', { user: message.author, contextualChannel: message.channel }) : undefined as any; // ! FIXME: tell fatal to make this type generic + const openProfile = () => openScreen({ id: 'profile', user_id: message.author }); return (
@@ -46,13 +50,13 @@ function Message({ attachContext, message, contrast, content: replacement, head: onContextMenu={attachContext ? attachContextMenu('Menu', { message, contextualChannel: message.channel, queued }) : undefined}> { head ? - : + : } { head && - + } diff --git a/src/components/navigation/items/ButtonItem.tsx b/src/components/navigation/items/ButtonItem.tsx index 139ec677..176f5f80 100644 --- a/src/components/navigation/items/ButtonItem.tsx +++ b/src/components/navigation/items/ButtonItem.tsx @@ -14,7 +14,7 @@ import { isTouchscreenDevice } from "../../../lib/isTouchscreenDevice"; import { useIntermediate } from '../../../context/intermediate/Intermediate'; import { stopPropagation } from '../../../lib/stopPropagation'; -interface CommonProps { +type CommonProps = Omit, 'children' | 'as'> & { active?: boolean alert?: 'unread' | 'mention' alertCount?: number @@ -26,11 +26,12 @@ type UserProps = CommonProps & { channel?: Channels.DirectMessageChannel } -export function UserButton({ active, alert, alertCount, user, context, channel }: UserProps) { +export function UserButton(props: UserProps) { + const { active, alert, alertCount, user, context, channel, ...divProps } = props; const { openScreen } = useIntermediate(); return ( -
@@ -138,9 +142,12 @@ type ButtonProps = CommonProps & { compact?: boolean } -export default function ButtonItem({ active, alert, alertCount, onClick, className, children, compact }: ButtonProps) { +export default function ButtonItem(props: ButtonProps) { + const { active, alert, alertCount, onClick, className, children, compact, ...divProps } = props; + return ( -
diff --git a/src/components/navigation/right/MemberSidebar.tsx b/src/components/navigation/right/MemberSidebar.tsx index 97383549..96b3728f 100644 --- a/src/components/navigation/right/MemberSidebar.tsx +++ b/src/components/navigation/right/MemberSidebar.tsx @@ -8,11 +8,12 @@ import { UserButton } from "../items/ButtonItem"; import { ChannelDebugInfo } from "./ChannelDebugInfo"; import { Channels, Servers, Users } from "revolt.js/dist/api/objects"; import { GenericSidebarBase, GenericSidebarList } from "../SidebarBase"; +import { useIntermediate } from "../../../context/intermediate/Intermediate"; import { ClientboundNotification } from "revolt.js/dist/websocket/notifications"; +import { AppContext, ClientStatus, StatusContext } from "../../../context/revoltjs/RevoltClient"; import { HookContext, useChannel, useForceUpdate, useUsers } from "../../../context/revoltjs/hooks"; import placeholderSVG from "../items/placeholder.svg"; -import { AppContext, ClientStatus, StatusContext } from "../../../context/revoltjs/RevoltClient"; interface Props { ctx: HookContext @@ -31,6 +32,7 @@ export default function MemberSidebar(props: { channel?: Channels.Channel }) { } export function GroupMemberSidebar({ channel, ctx }: Props & { channel: Channels.GroupChannel }) { + const { openScreen } = useIntermediate(); const users = useUsers(undefined, ctx); let members = channel.recipients .map(x => users.find(y => y?._id === x)) @@ -112,13 +114,11 @@ export function GroupMemberSidebar({ channel, ctx }: Props & { channel: Channels {members.map( user => user && ( - // - - // + openScreen({ id: 'profile', user_id: user._id })} /> ) )} diff --git a/src/context/intermediate/Intermediate.tsx b/src/context/intermediate/Intermediate.tsx index ff723c0b..3fb81674 100644 --- a/src/context/intermediate/Intermediate.tsx +++ b/src/context/intermediate/Intermediate.tsx @@ -98,7 +98,7 @@ export default function Intermediate(props: Props) { const navigate = (path: string) => history.push(path); const subs = [ - internalSubscribe("Intermediate", "open_profile", openProfile), + internalSubscribe("Intermediate", "openProfile", openProfile), internalSubscribe("Intermediate", "navigate", navigate) ]