mirror of
https://github.com/stoatchat/for-legacy-web.git
synced 2026-03-07 09:25:27 +00:00
Remember whether reply was a mention or not.
Fix input modals refreshing page.
This commit is contained in:
@@ -11,6 +11,7 @@ import { StateUpdater, useEffect } from "preact/hooks";
|
|||||||
import { internalSubscribe } from "../../../../lib/eventEmitter";
|
import { internalSubscribe } from "../../../../lib/eventEmitter";
|
||||||
import { getRenderer } from "../../../../lib/renderer/Singleton";
|
import { getRenderer } from "../../../../lib/renderer/Singleton";
|
||||||
|
|
||||||
|
import { dispatch, getState } from "../../../../redux";
|
||||||
import { Reply } from "../../../../redux/reducers/queue";
|
import { Reply } from "../../../../redux/reducers/queue";
|
||||||
|
|
||||||
import IconButton from "../../../ui/IconButton";
|
import IconButton from "../../../ui/IconButton";
|
||||||
@@ -75,7 +76,7 @@ const Base = styled.div`
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
// ! FIXME: Move to global config
|
// ! FIXME: Move to global config
|
||||||
const MAX_REPLIES = 5;
|
const MAX_REPLIES = 4;
|
||||||
export default observer(({ channel, replies, setReplies }: Props) => {
|
export default observer(({ channel, replies, setReplies }: Props) => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
return internalSubscribe(
|
return internalSubscribe(
|
||||||
@@ -84,7 +85,13 @@ export default observer(({ channel, replies, setReplies }: Props) => {
|
|||||||
(id) =>
|
(id) =>
|
||||||
replies.length < MAX_REPLIES &&
|
replies.length < MAX_REPLIES &&
|
||||||
!replies.find((x) => x.id === id) &&
|
!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]);
|
}, [replies, setReplies]);
|
||||||
|
|
||||||
@@ -147,15 +154,28 @@ export default observer(({ channel, replies, setReplies }: Props) => {
|
|||||||
</ReplyBase>
|
</ReplyBase>
|
||||||
<span class="actions">
|
<span class="actions">
|
||||||
<IconButton
|
<IconButton
|
||||||
onClick={() =>
|
onClick={() => {
|
||||||
|
let state = false;
|
||||||
setReplies(
|
setReplies(
|
||||||
replies.map((_, i) =>
|
replies.map((_, i) => {
|
||||||
i === index
|
if (i === index) {
|
||||||
? { ..._, mention: !_.mention }
|
state = !_.mention;
|
||||||
: _,
|
return {
|
||||||
),
|
..._,
|
||||||
)
|
mention: !_.mention,
|
||||||
}>
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return _;
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
dispatch({
|
||||||
|
type: "SECTION_TOGGLE_SET",
|
||||||
|
id: "mention",
|
||||||
|
state,
|
||||||
|
});
|
||||||
|
}}>
|
||||||
<span class="toggle">
|
<span class="toggle">
|
||||||
<At size={16} />{" "}
|
<At size={16} />{" "}
|
||||||
{reply.mention ? "ON" : "OFF"}
|
{reply.mention ? "ON" : "OFF"}
|
||||||
|
|||||||
@@ -57,7 +57,6 @@ export function InputModal({
|
|||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
onClose={onClose}>
|
onClose={onClose}>
|
||||||
<form>
|
|
||||||
{field ? (
|
{field ? (
|
||||||
<Overline error={error} block>
|
<Overline error={error} block>
|
||||||
{field}
|
{field}
|
||||||
@@ -69,7 +68,6 @@ export function InputModal({
|
|||||||
value={value}
|
value={value}
|
||||||
onChange={(e) => setValue(e.currentTarget.value)}
|
onChange={(e) => setValue(e.currentTarget.value)}
|
||||||
/>
|
/>
|
||||||
</form>
|
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user