mirror of
https://github.com/revoltchat/revite.git
synced 2024-12-25 15:12:08 -05:00
fix: hide new messages bar on click
This commit is contained in:
parent
f1a9c889b8
commit
c64906051d
1 changed files with 26 additions and 23 deletions
|
@ -4,6 +4,8 @@ import { useHistory } from "react-router-dom";
|
|||
import { Channel } from "revolt.js/dist/maps/Channels";
|
||||
import { decodeTime } from "ulid";
|
||||
|
||||
import { useEffect, useState } from "preact/hooks";
|
||||
|
||||
import { getRenderer } from "../../../../lib/renderer/Singleton";
|
||||
|
||||
import { dayjs } from "../../../../context/Locale";
|
||||
|
@ -12,36 +14,37 @@ import { Bar } from "./JumpToBottom";
|
|||
|
||||
export default observer(
|
||||
({ channel, last_id }: { channel: Channel; last_id?: string }) => {
|
||||
const [hidden, setHidden] = useState(false);
|
||||
useEffect(() => setHidden(false), [last_id]);
|
||||
|
||||
const renderer = getRenderer(channel);
|
||||
const history = useHistory();
|
||||
if (renderer.state !== "RENDER") return null;
|
||||
if (!last_id) return null;
|
||||
if (hidden) return null;
|
||||
|
||||
return (
|
||||
<>
|
||||
<Bar position="top" accent>
|
||||
<div
|
||||
onClick={() => {
|
||||
if (channel.channel_type === "TextChannel") {
|
||||
history.push(
|
||||
`/server/${channel.server_id}/channel/${channel._id}/${last_id}`,
|
||||
);
|
||||
} else {
|
||||
history.push(
|
||||
`/channel/${channel._id}/${last_id}`,
|
||||
);
|
||||
}
|
||||
}}>
|
||||
<div>
|
||||
New messages since{" "}
|
||||
{dayjs(decodeTime(last_id)).fromNow()}
|
||||
</div>
|
||||
<div>
|
||||
Click to jump to start. <UpArrowAlt size={20} />
|
||||
</div>
|
||||
<Bar position="top" accent>
|
||||
<div
|
||||
onClick={() => {
|
||||
setHidden(true);
|
||||
if (channel.channel_type === "TextChannel") {
|
||||
history.push(
|
||||
`/server/${channel.server_id}/channel/${channel._id}/${last_id}`,
|
||||
);
|
||||
} else {
|
||||
history.push(`/channel/${channel._id}/${last_id}`);
|
||||
}
|
||||
}}>
|
||||
<div>
|
||||
New messages since{" "}
|
||||
{dayjs(decodeTime(last_id)).fromNow()}
|
||||
</div>
|
||||
</Bar>
|
||||
</>
|
||||
<div>
|
||||
Click to jump to start. <UpArrowAlt size={20} />
|
||||
</div>
|
||||
</div>
|
||||
</Bar>
|
||||
);
|
||||
},
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue