fix: hide new messages bar on click

This commit is contained in:
Paul 2021-12-24 14:49:21 +00:00
parent f1a9c889b8
commit c64906051d

View file

@ -4,6 +4,8 @@ import { useHistory } from "react-router-dom";
import { Channel } from "revolt.js/dist/maps/Channels"; import { Channel } from "revolt.js/dist/maps/Channels";
import { decodeTime } from "ulid"; import { decodeTime } from "ulid";
import { useEffect, useState } from "preact/hooks";
import { getRenderer } from "../../../../lib/renderer/Singleton"; import { getRenderer } from "../../../../lib/renderer/Singleton";
import { dayjs } from "../../../../context/Locale"; import { dayjs } from "../../../../context/Locale";
@ -12,24 +14,26 @@ import { Bar } from "./JumpToBottom";
export default observer( export default observer(
({ channel, last_id }: { channel: Channel; last_id?: string }) => { ({ channel, last_id }: { channel: Channel; last_id?: string }) => {
const [hidden, setHidden] = useState(false);
useEffect(() => setHidden(false), [last_id]);
const renderer = getRenderer(channel); const renderer = getRenderer(channel);
const history = useHistory(); const history = useHistory();
if (renderer.state !== "RENDER") return null; if (renderer.state !== "RENDER") return null;
if (!last_id) return null; if (!last_id) return null;
if (hidden) return null;
return ( return (
<>
<Bar position="top" accent> <Bar position="top" accent>
<div <div
onClick={() => { onClick={() => {
setHidden(true);
if (channel.channel_type === "TextChannel") { if (channel.channel_type === "TextChannel") {
history.push( history.push(
`/server/${channel.server_id}/channel/${channel._id}/${last_id}`, `/server/${channel.server_id}/channel/${channel._id}/${last_id}`,
); );
} else { } else {
history.push( history.push(`/channel/${channel._id}/${last_id}`);
`/channel/${channel._id}/${last_id}`,
);
} }
}}> }}>
<div> <div>
@ -41,7 +45,6 @@ export default observer(
</div> </div>
</div> </div>
</Bar> </Bar>
</>
); );
}, },
); );