mirror of
https://github.com/revoltchat/revite.git
synced 2024-12-25 23:22:06 -05:00
Merge pull request #98 from fatalerrorcoded/master
This commit is contained in:
commit
468350b36c
2 changed files with 56 additions and 44 deletions
|
@ -3,6 +3,7 @@ import { File, XCircle } from "@styled-icons/boxicons-solid";
|
||||||
import { observer } from "mobx-react-lite";
|
import { observer } from "mobx-react-lite";
|
||||||
import { SYSTEM_USER_ID } from "revolt.js";
|
import { SYSTEM_USER_ID } from "revolt.js";
|
||||||
import { Channel } from "revolt.js/dist/maps/Channels";
|
import { Channel } from "revolt.js/dist/maps/Channels";
|
||||||
|
import { Message } from "revolt.js/dist/maps/Messages";
|
||||||
import styled from "styled-components";
|
import styled from "styled-components";
|
||||||
|
|
||||||
import { Text } from "preact-i18n";
|
import { Text } from "preact-i18n";
|
||||||
|
@ -14,6 +15,8 @@ import { getRenderer } from "../../../../lib/renderer/Singleton";
|
||||||
import { dispatch, getState } from "../../../../redux";
|
import { dispatch, getState } from "../../../../redux";
|
||||||
import { Reply } from "../../../../redux/reducers/queue";
|
import { Reply } from "../../../../redux/reducers/queue";
|
||||||
|
|
||||||
|
import { useClient } from "../../../../context/revoltjs/RevoltClient";
|
||||||
|
|
||||||
import IconButton from "../../../ui/IconButton";
|
import IconButton from "../../../ui/IconButton";
|
||||||
|
|
||||||
import Markdown from "../../../markdown/Markdown";
|
import Markdown from "../../../markdown/Markdown";
|
||||||
|
@ -78,22 +81,29 @@ const Base = styled.div`
|
||||||
// ! FIXME: Move to global config
|
// ! FIXME: Move to global config
|
||||||
const MAX_REPLIES = 4;
|
const MAX_REPLIES = 4;
|
||||||
export default observer(({ channel, replies, setReplies }: Props) => {
|
export default observer(({ channel, replies, setReplies }: Props) => {
|
||||||
|
const client = useClient();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
return internalSubscribe(
|
return internalSubscribe("ReplyBar", "add", (_message) => {
|
||||||
"ReplyBar",
|
const message = _message as Message;
|
||||||
"add",
|
if (
|
||||||
(id) =>
|
replies.length >= MAX_REPLIES ||
|
||||||
replies.length < MAX_REPLIES &&
|
replies.find((x) => x.id === message._id)
|
||||||
!replies.find((x) => x.id === id) &&
|
)
|
||||||
setReplies([
|
return;
|
||||||
...replies,
|
|
||||||
{
|
setReplies([
|
||||||
id: id as string,
|
...replies,
|
||||||
mention: getState().sectionToggle.mention ?? false,
|
{
|
||||||
},
|
id: message._id,
|
||||||
]),
|
mention:
|
||||||
);
|
message.author_id === client.user!._id
|
||||||
}, [replies, setReplies]);
|
? false
|
||||||
|
: getState().sectionToggle.mention ?? false,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
}, [replies, setReplies, client.user]);
|
||||||
|
|
||||||
const renderer = getRenderer(channel);
|
const renderer = getRenderer(channel);
|
||||||
if (renderer.state !== "RENDER") return null;
|
if (renderer.state !== "RENDER") return null;
|
||||||
|
@ -153,34 +163,36 @@ export default observer(({ channel, replies, setReplies }: Props) => {
|
||||||
</div>
|
</div>
|
||||||
</ReplyBase>
|
</ReplyBase>
|
||||||
<span class="actions">
|
<span class="actions">
|
||||||
<IconButton
|
{message.author_id !== client.user!._id && (
|
||||||
onClick={() => {
|
<IconButton
|
||||||
let state = false;
|
onClick={() => {
|
||||||
setReplies(
|
let state = false;
|
||||||
replies.map((_, i) => {
|
setReplies(
|
||||||
if (i === index) {
|
replies.map((_, i) => {
|
||||||
state = !_.mention;
|
if (i === index) {
|
||||||
return {
|
state = !_.mention;
|
||||||
..._,
|
return {
|
||||||
mention: !_.mention,
|
..._,
|
||||||
};
|
mention: !_.mention,
|
||||||
}
|
};
|
||||||
|
}
|
||||||
|
|
||||||
return _;
|
return _;
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: "SECTION_TOGGLE_SET",
|
type: "SECTION_TOGGLE_SET",
|
||||||
id: "mention",
|
id: "mention",
|
||||||
state,
|
state,
|
||||||
});
|
});
|
||||||
}}>
|
}}>
|
||||||
<span class="toggle">
|
<span class="toggle">
|
||||||
<At size={16} />{" "}
|
<At size={16} />{" "}
|
||||||
{reply.mention ? "ON" : "OFF"}
|
{reply.mention ? "ON" : "OFF"}
|
||||||
</span>
|
</span>
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
)}
|
||||||
<IconButton
|
<IconButton
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
setReplies(
|
setReplies(
|
||||||
|
|
|
@ -79,7 +79,7 @@ type Action =
|
||||||
| { action: "retry_message"; message: QueuedMessage }
|
| { action: "retry_message"; message: QueuedMessage }
|
||||||
| { action: "cancel_message"; message: QueuedMessage }
|
| { action: "cancel_message"; message: QueuedMessage }
|
||||||
| { action: "mention"; user: string }
|
| { action: "mention"; user: string }
|
||||||
| { action: "reply_message"; id: string }
|
| { action: "reply_message"; target: Message }
|
||||||
| { action: "quote_message"; content: string }
|
| { action: "quote_message"; content: string }
|
||||||
| { action: "edit_message"; id: string }
|
| { action: "edit_message"; id: string }
|
||||||
| { action: "delete_message"; target: Message }
|
| { action: "delete_message"; target: Message }
|
||||||
|
@ -247,7 +247,7 @@ function ContextMenus(props: Props) {
|
||||||
|
|
||||||
case "reply_message":
|
case "reply_message":
|
||||||
{
|
{
|
||||||
internalEmit("ReplyBar", "add", data.id);
|
internalEmit("ReplyBar", "add", data.target);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -702,7 +702,7 @@ function ContextMenus(props: Props) {
|
||||||
if (message && !queued) {
|
if (message && !queued) {
|
||||||
generateAction({
|
generateAction({
|
||||||
action: "reply_message",
|
action: "reply_message",
|
||||||
id: message._id,
|
target: message,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
|
Loading…
Reference in a new issue