2021-07-29 18:41:01 +01:00
|
|
|
import { observer } from "mobx-react-lite";
|
2021-07-30 21:20:42 +01:00
|
|
|
import { useParams } from "react-router-dom";
|
|
|
|
import { Channel as ChannelI } from "revolt.js/dist/maps/Channels";
|
2021-07-05 11:23:23 +01:00
|
|
|
import styled from "styled-components";
|
|
|
|
|
|
|
|
import { useState } from "preact/hooks";
|
|
|
|
|
2021-06-21 21:11:53 +01:00
|
|
|
import { isTouchscreenDevice } from "../../lib/isTouchscreenDevice";
|
2021-07-05 11:23:23 +01:00
|
|
|
|
2021-07-06 22:52:50 +01:00
|
|
|
import { dispatch, getState } from "../../redux";
|
|
|
|
|
2021-07-30 21:20:42 +01:00
|
|
|
import { useClient } from "../../context/revoltjs/RevoltClient";
|
|
|
|
|
2021-07-10 15:57:29 +01:00
|
|
|
import AgeGate from "../../components/common/AgeGate";
|
2021-07-05 11:23:23 +01:00
|
|
|
import MessageBox from "../../components/common/messaging/MessageBox";
|
2021-06-21 21:11:53 +01:00
|
|
|
import JumpToBottom from "../../components/common/messaging/bars/JumpToBottom";
|
|
|
|
import TypingIndicator from "../../components/common/messaging/bars/TypingIndicator";
|
2021-07-05 11:23:23 +01:00
|
|
|
|
|
|
|
import MemberSidebar from "../../components/navigation/right/MemberSidebar";
|
|
|
|
import ChannelHeader from "./ChannelHeader";
|
|
|
|
import { MessageArea } from "./messaging/MessageArea";
|
2021-06-24 10:54:32 +01:00
|
|
|
import VoiceHeader from "./voice/VoiceHeader";
|
2021-06-20 17:31:53 +01:00
|
|
|
|
|
|
|
const ChannelMain = styled.div`
|
2021-07-05 11:25:20 +01:00
|
|
|
flex-grow: 1;
|
|
|
|
display: flex;
|
|
|
|
min-height: 0;
|
|
|
|
overflow: hidden;
|
|
|
|
flex-direction: row;
|
2021-06-20 17:31:53 +01:00
|
|
|
`;
|
|
|
|
|
|
|
|
const ChannelContent = styled.div`
|
2021-07-05 11:25:20 +01:00
|
|
|
flex-grow: 1;
|
|
|
|
display: flex;
|
|
|
|
overflow: hidden;
|
|
|
|
flex-direction: column;
|
2021-06-20 17:31:53 +01:00
|
|
|
`;
|
|
|
|
|
2021-06-21 21:11:53 +01:00
|
|
|
export function Channel({ id }: { id: string }) {
|
2021-07-30 21:20:42 +01:00
|
|
|
const client = useClient();
|
|
|
|
const channel = client.channels.get(id);
|
2021-07-05 11:25:20 +01:00
|
|
|
if (!channel) return null;
|
2021-06-23 13:52:16 +01:00
|
|
|
|
2021-07-05 11:25:20 +01:00
|
|
|
if (channel.channel_type === "VoiceChannel") {
|
|
|
|
return <VoiceChannel channel={channel} />;
|
|
|
|
}
|
2021-07-29 18:41:01 +01:00
|
|
|
|
2021-07-10 15:57:29 +01:00
|
|
|
return <TextChannel channel={channel} />;
|
2021-06-23 13:52:16 +01:00
|
|
|
}
|
|
|
|
|
2021-07-06 22:52:50 +01:00
|
|
|
const MEMBERS_SIDEBAR_KEY = "sidebar_members";
|
2021-07-30 21:20:42 +01:00
|
|
|
const TextChannel = observer(({ channel }: { channel: ChannelI }) => {
|
2021-07-06 22:52:50 +01:00
|
|
|
const [showMembers, setMembers] = useState(
|
|
|
|
getState().sectionToggle[MEMBERS_SIDEBAR_KEY] ?? true,
|
|
|
|
);
|
2021-07-06 22:44:38 +01:00
|
|
|
|
2021-07-10 15:57:29 +01:00
|
|
|
const id = channel._id;
|
2021-07-05 11:25:20 +01:00
|
|
|
return (
|
2021-07-08 20:16:50 +01:00
|
|
|
<AgeGate
|
|
|
|
type="channel"
|
|
|
|
channel={channel}
|
2021-07-10 15:57:29 +01:00
|
|
|
gated={
|
|
|
|
(channel.channel_type === "TextChannel" ||
|
|
|
|
channel.channel_type === "Group") &&
|
2021-07-29 18:41:01 +01:00
|
|
|
channel.name?.includes("nsfw")
|
|
|
|
? true
|
|
|
|
: false
|
2021-07-10 15:57:29 +01:00
|
|
|
}>
|
2021-07-05 11:25:20 +01:00
|
|
|
<ChannelHeader
|
|
|
|
channel={channel}
|
2021-07-06 22:44:38 +01:00
|
|
|
toggleSidebar={() => {
|
|
|
|
setMembers(!showMembers);
|
|
|
|
|
|
|
|
if (showMembers) {
|
|
|
|
dispatch({
|
2021-07-06 22:52:50 +01:00
|
|
|
type: "SECTION_TOGGLE_SET",
|
2021-07-06 22:44:38 +01:00
|
|
|
id: MEMBERS_SIDEBAR_KEY,
|
2021-07-06 22:52:50 +01:00
|
|
|
state: false,
|
2021-07-06 22:44:38 +01:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
dispatch({
|
2021-07-06 22:52:50 +01:00
|
|
|
type: "SECTION_TOGGLE_UNSET",
|
|
|
|
id: MEMBERS_SIDEBAR_KEY,
|
2021-07-06 22:44:38 +01:00
|
|
|
});
|
|
|
|
}
|
2021-07-06 22:52:50 +01:00
|
|
|
}}
|
|
|
|
/>
|
2021-07-05 11:25:20 +01:00
|
|
|
<ChannelMain>
|
|
|
|
<ChannelContent>
|
|
|
|
<VoiceHeader id={id} />
|
|
|
|
<MessageArea id={id} />
|
|
|
|
<TypingIndicator id={id} />
|
|
|
|
<JumpToBottom id={id} />
|
|
|
|
<MessageBox channel={channel} />
|
|
|
|
</ChannelContent>
|
|
|
|
{!isTouchscreenDevice && showMembers && (
|
|
|
|
<MemberSidebar channel={channel} />
|
|
|
|
)}
|
|
|
|
</ChannelMain>
|
2021-07-08 20:16:50 +01:00
|
|
|
</AgeGate>
|
2021-07-05 11:25:20 +01:00
|
|
|
);
|
2021-07-29 18:41:01 +01:00
|
|
|
});
|
2021-06-23 13:52:16 +01:00
|
|
|
|
2021-07-30 21:20:42 +01:00
|
|
|
function VoiceChannel({ channel }: { channel: ChannelI }) {
|
2021-07-05 11:25:20 +01:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<ChannelHeader channel={channel} />
|
|
|
|
<VoiceHeader id={channel._id} />
|
|
|
|
</>
|
|
|
|
);
|
2021-06-20 17:31:53 +01:00
|
|
|
}
|
2021-06-21 21:11:53 +01:00
|
|
|
|
2021-07-05 11:23:23 +01:00
|
|
|
export default function () {
|
2021-07-05 11:25:20 +01:00
|
|
|
const { channel } = useParams<{ channel: string }>();
|
|
|
|
return <Channel id={channel} key={channel} />;
|
2021-06-21 21:11:53 +01:00
|
|
|
}
|