mirror of
https://github.com/revoltchat/revite.git
synced 2024-12-25 23:22:06 -05:00
Remember whether reply was a mention or not.
Fix input modals refreshing page.
This commit is contained in:
parent
8609a1f016
commit
f59d0efbcb
2 changed files with 41 additions and 23 deletions
|
@ -11,6 +11,7 @@ import { StateUpdater, useEffect } from "preact/hooks";
|
|||
import { internalSubscribe } from "../../../../lib/eventEmitter";
|
||||
import { getRenderer } from "../../../../lib/renderer/Singleton";
|
||||
|
||||
import { dispatch, getState } from "../../../../redux";
|
||||
import { Reply } from "../../../../redux/reducers/queue";
|
||||
|
||||
import IconButton from "../../../ui/IconButton";
|
||||
|
@ -75,7 +76,7 @@ const Base = styled.div`
|
|||
`;
|
||||
|
||||
// ! FIXME: Move to global config
|
||||
const MAX_REPLIES = 5;
|
||||
const MAX_REPLIES = 4;
|
||||
export default observer(({ channel, replies, setReplies }: Props) => {
|
||||
useEffect(() => {
|
||||
return internalSubscribe(
|
||||
|
@ -84,7 +85,13 @@ export default observer(({ channel, replies, setReplies }: Props) => {
|
|||
(id) =>
|
||||
replies.length < MAX_REPLIES &&
|
||||
!replies.find((x) => x.id === id) &&
|
||||
setReplies([...replies, { id: id as string, mention: false }]),
|
||||
setReplies([
|
||||
...replies,
|
||||
{
|
||||
id: id as string,
|
||||
mention: getState().sectionToggle.mention ?? false,
|
||||
},
|
||||
]),
|
||||
);
|
||||
}, [replies, setReplies]);
|
||||
|
||||
|
@ -147,15 +154,28 @@ export default observer(({ channel, replies, setReplies }: Props) => {
|
|||
</ReplyBase>
|
||||
<span class="actions">
|
||||
<IconButton
|
||||
onClick={() =>
|
||||
onClick={() => {
|
||||
let state = false;
|
||||
setReplies(
|
||||
replies.map((_, i) =>
|
||||
i === index
|
||||
? { ..._, mention: !_.mention }
|
||||
: _,
|
||||
),
|
||||
)
|
||||
}>
|
||||
replies.map((_, i) => {
|
||||
if (i === index) {
|
||||
state = !_.mention;
|
||||
return {
|
||||
..._,
|
||||
mention: !_.mention,
|
||||
};
|
||||
}
|
||||
|
||||
return _;
|
||||
}),
|
||||
);
|
||||
|
||||
dispatch({
|
||||
type: "SECTION_TOGGLE_SET",
|
||||
id: "mention",
|
||||
state,
|
||||
});
|
||||
}}>
|
||||
<span class="toggle">
|
||||
<At size={16} />{" "}
|
||||
{reply.mention ? "ON" : "OFF"}
|
||||
|
|
|
@ -57,7 +57,6 @@ export function InputModal({
|
|||
},
|
||||
]}
|
||||
onClose={onClose}>
|
||||
<form>
|
||||
{field ? (
|
||||
<Overline error={error} block>
|
||||
{field}
|
||||
|
@ -69,7 +68,6 @@ export function InputModal({
|
|||
value={value}
|
||||
onChange={(e) => setValue(e.currentTarget.value)}
|
||||
/>
|
||||
</form>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue