mirror of
https://github.com/revoltchat/revite.git
synced 2024-12-26 07:22:10 -05:00
Add shift+click
to mention a user in the textarea
This commit is contained in:
parent
4787a2166f
commit
2966e77917
3 changed files with 68 additions and 28 deletions
|
@ -25,6 +25,7 @@ import Attachment from "./attachments/Attachment";
|
||||||
import { MessageReply } from "./attachments/MessageReply";
|
import { MessageReply } from "./attachments/MessageReply";
|
||||||
import Embed from "./embed/Embed";
|
import Embed from "./embed/Embed";
|
||||||
import InviteList from "./embed/EmbedInvite";
|
import InviteList from "./embed/EmbedInvite";
|
||||||
|
import { internalEmit } from "../../../lib/eventEmitter";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
attachContext?: boolean;
|
attachContext?: boolean;
|
||||||
|
@ -61,15 +62,28 @@ const Message = observer(
|
||||||
// bree: Fatal please...
|
// bree: Fatal please...
|
||||||
const userContext = attachContext
|
const userContext = attachContext
|
||||||
? (attachContextMenu("Menu", {
|
? (attachContextMenu("Menu", {
|
||||||
user: message.author_id,
|
user: message.author_id,
|
||||||
contextualChannel: message.channel_id,
|
contextualChannel: message.channel_id,
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
}) as any)
|
}) as any)
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
const openProfile = () =>
|
const openProfile = () =>
|
||||||
openScreen({ id: "profile", user_id: message.author_id });
|
openScreen({ id: "profile", user_id: message.author_id });
|
||||||
|
|
||||||
|
const handleUserClick = (e: MouseEvent) => {
|
||||||
|
if (e.shiftKey && user?._id) {
|
||||||
|
internalEmit(
|
||||||
|
"MessageBox",
|
||||||
|
"append",
|
||||||
|
`<@${user._id}>`,
|
||||||
|
"mention",
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
openProfile()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ! FIXME(?): animate on hover
|
// ! FIXME(?): animate on hover
|
||||||
const [animate, setAnimate] = useState(false);
|
const [animate, setAnimate] = useState(false);
|
||||||
|
|
||||||
|
@ -91,11 +105,11 @@ const Message = observer(
|
||||||
hideReply
|
hideReply
|
||||||
? false
|
? false
|
||||||
: (head &&
|
: (head &&
|
||||||
!(
|
!(
|
||||||
message.reply_ids &&
|
message.reply_ids &&
|
||||||
message.reply_ids.length > 0
|
message.reply_ids.length > 0
|
||||||
)) ??
|
)) ??
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
contrast={contrast}
|
contrast={contrast}
|
||||||
sending={typeof queued !== "undefined"}
|
sending={typeof queued !== "undefined"}
|
||||||
|
@ -104,10 +118,10 @@ const Message = observer(
|
||||||
onContextMenu={
|
onContextMenu={
|
||||||
attachContext
|
attachContext
|
||||||
? attachContextMenu("Menu", {
|
? attachContextMenu("Menu", {
|
||||||
message,
|
message,
|
||||||
contextualChannel: message.channel_id,
|
contextualChannel: message.channel_id,
|
||||||
queued,
|
queued,
|
||||||
})
|
})
|
||||||
: undefined
|
: undefined
|
||||||
}
|
}
|
||||||
onMouseEnter={() => setAnimate(true)}
|
onMouseEnter={() => setAnimate(true)}
|
||||||
|
@ -118,7 +132,7 @@ const Message = observer(
|
||||||
target={user}
|
target={user}
|
||||||
size={36}
|
size={36}
|
||||||
onContextMenu={userContext}
|
onContextMenu={userContext}
|
||||||
onClick={openProfile}
|
onClick={handleUserClick}
|
||||||
animate={animate}
|
animate={animate}
|
||||||
showServerIdentity
|
showServerIdentity
|
||||||
/>
|
/>
|
||||||
|
@ -133,7 +147,7 @@ const Message = observer(
|
||||||
className="author"
|
className="author"
|
||||||
user={user}
|
user={user}
|
||||||
onContextMenu={userContext}
|
onContextMenu={userContext}
|
||||||
onClick={openProfile}
|
onClick={handleUserClick}
|
||||||
showServerIdentity
|
showServerIdentity
|
||||||
/>
|
/>
|
||||||
<MessageDetail
|
<MessageDetail
|
||||||
|
|
|
@ -9,6 +9,7 @@ import { useIntermediate } from "../../../context/intermediate/Intermediate";
|
||||||
import { useClient } from "../../../context/revoltjs/RevoltClient";
|
import { useClient } from "../../../context/revoltjs/RevoltClient";
|
||||||
|
|
||||||
import UserIcon from "./UserIcon";
|
import UserIcon from "./UserIcon";
|
||||||
|
import { internalEmit } from "../../../lib/eventEmitter";
|
||||||
|
|
||||||
const BotBadge = styled.div`
|
const BotBadge = styled.div`
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
@ -25,17 +26,18 @@ const BotBadge = styled.div`
|
||||||
border-radius: calc(var(--border-radius) / 2);
|
border-radius: calc(var(--border-radius) / 2);
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
type UsernameProps = JSX.HTMLAttributes<HTMLElement> & {
|
||||||
|
user?: User;
|
||||||
|
prefixAt?: boolean;
|
||||||
|
showServerIdentity?: boolean;
|
||||||
|
}
|
||||||
export const Username = observer(
|
export const Username = observer(
|
||||||
({
|
({
|
||||||
user,
|
user,
|
||||||
prefixAt,
|
prefixAt,
|
||||||
showServerIdentity,
|
showServerIdentity,
|
||||||
...otherProps
|
...otherProps
|
||||||
}: {
|
}: UsernameProps) => {
|
||||||
user?: User;
|
|
||||||
prefixAt?: boolean;
|
|
||||||
showServerIdentity?: boolean;
|
|
||||||
} & JSX.HTMLAttributes<HTMLElement>) => {
|
|
||||||
let username = user?.username;
|
let username = user?.username;
|
||||||
let color;
|
let color;
|
||||||
|
|
||||||
|
@ -108,18 +110,32 @@ export default function UserShort({
|
||||||
const openProfile = () =>
|
const openProfile = () =>
|
||||||
user && openScreen({ id: "profile", user_id: user._id });
|
user && openScreen({ id: "profile", user_id: user._id });
|
||||||
|
|
||||||
|
const handleUserClick = (e: MouseEvent) => {
|
||||||
|
if (e.shiftKey && user?._id) {
|
||||||
|
e.preventDefault()
|
||||||
|
internalEmit(
|
||||||
|
"MessageBox",
|
||||||
|
"append",
|
||||||
|
`<@${user?._id}>`,
|
||||||
|
"mention",
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
openProfile()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<UserIcon
|
<UserIcon
|
||||||
size={size ?? 24}
|
size={size ?? 24}
|
||||||
target={user}
|
target={user}
|
||||||
onClick={openProfile}
|
onClick={handleUserClick}
|
||||||
showServerIdentity={showServerIdentity}
|
showServerIdentity={showServerIdentity}
|
||||||
/>
|
/>
|
||||||
<Username
|
<Username
|
||||||
user={user}
|
user={user}
|
||||||
showServerIdentity={showServerIdentity}
|
showServerIdentity={showServerIdentity}
|
||||||
onClick={openProfile}
|
onClick={handleUserClick}
|
||||||
prefixAt={prefixAt}
|
prefixAt={prefixAt}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
|
|
|
@ -12,6 +12,7 @@ import {
|
||||||
} from "../../../context/intermediate/Intermediate";
|
} from "../../../context/intermediate/Intermediate";
|
||||||
|
|
||||||
import { UserButton } from "../items/ButtonItem";
|
import { UserButton } from "../items/ButtonItem";
|
||||||
|
import { internalEmit } from "../../../lib/eventEmitter";
|
||||||
|
|
||||||
export type MemberListGroup = {
|
export type MemberListGroup = {
|
||||||
type: "online" | "offline" | "role";
|
type: "online" | "offline" | "role";
|
||||||
|
@ -53,12 +54,21 @@ const ItemContent = memo(
|
||||||
user={item}
|
user={item}
|
||||||
margin
|
margin
|
||||||
context={context}
|
context={context}
|
||||||
onClick={() =>
|
onClick={e => {
|
||||||
openScreen({
|
if (e.shiftKey) {
|
||||||
id: "profile",
|
internalEmit(
|
||||||
user_id: item._id,
|
"MessageBox",
|
||||||
})
|
"append",
|
||||||
}
|
`<@${item._id}>`,
|
||||||
|
"mention",
|
||||||
|
);
|
||||||
|
} else[
|
||||||
|
openScreen({
|
||||||
|
id: "profile",
|
||||||
|
user_id: item._id,
|
||||||
|
})
|
||||||
|
]
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue