2021-06-20 12:31:53 -04:00
|
|
|
import styled from "styled-components";
|
2021-06-21 16:11:53 -04:00
|
|
|
import { useState } from "preact/hooks";
|
|
|
|
import ChannelHeader from "./ChannelHeader";
|
2021-06-20 12:31:53 -04:00
|
|
|
import { useParams } from "react-router-dom";
|
|
|
|
import { MessageArea } from "./messaging/MessageArea";
|
2021-06-21 16:11:53 -04:00
|
|
|
// import { useRenderState } from "../../lib/renderer/Singleton";
|
|
|
|
import { isTouchscreenDevice } from "../../lib/isTouchscreenDevice";
|
2021-06-20 15:30:42 -04:00
|
|
|
import MessageBox from "../../components/common/messaging/MessageBox";
|
2021-06-21 16:11:53 -04:00
|
|
|
import { useChannel, useForceUpdate } from "../../context/revoltjs/hooks";
|
|
|
|
import MemberSidebar from "../../components/navigation/right/MemberSidebar";
|
|
|
|
import JumpToBottom from "../../components/common/messaging/bars/JumpToBottom";
|
|
|
|
import TypingIndicator from "../../components/common/messaging/bars/TypingIndicator";
|
2021-06-23 08:52:16 -04:00
|
|
|
import { Channel } from "revolt.js";
|
2021-06-24 05:54:32 -04:00
|
|
|
import VoiceHeader from "./voice/VoiceHeader";
|
2021-06-20 12:31:53 -04:00
|
|
|
|
|
|
|
const ChannelMain = styled.div`
|
|
|
|
flex-grow: 1;
|
|
|
|
display: flex;
|
|
|
|
min-height: 0;
|
|
|
|
overflow: hidden;
|
|
|
|
flex-direction: row;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const ChannelContent = styled.div`
|
|
|
|
flex-grow: 1;
|
|
|
|
display: flex;
|
|
|
|
overflow: hidden;
|
|
|
|
flex-direction: column;
|
|
|
|
`;
|
|
|
|
|
2021-06-21 16:11:53 -04:00
|
|
|
export function Channel({ id }: { id: string }) {
|
2021-06-20 12:31:53 -04:00
|
|
|
const ctx = useForceUpdate();
|
|
|
|
const channel = useChannel(id, ctx);
|
|
|
|
|
|
|
|
if (!channel) return null;
|
2021-06-23 08:52:16 -04:00
|
|
|
|
|
|
|
if (channel.channel_type === 'VoiceChannel') {
|
|
|
|
return <VoiceChannel channel={channel} />;
|
|
|
|
} else {
|
|
|
|
return <TextChannel channel={channel} />;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function TextChannel({ channel }: { channel: Channel }) {
|
2021-06-21 16:11:53 -04:00
|
|
|
const [ showMembers, setMembers ] = useState(true);
|
2021-06-20 12:31:53 -04:00
|
|
|
|
2021-06-23 08:52:16 -04:00
|
|
|
let id = channel._id;
|
|
|
|
return <>
|
|
|
|
<ChannelHeader channel={channel} toggleSidebar={() => setMembers(!showMembers)} />
|
|
|
|
<ChannelMain>
|
|
|
|
<ChannelContent>
|
2021-06-24 05:54:32 -04:00
|
|
|
<VoiceHeader id={id} />
|
2021-06-23 08:52:16 -04:00
|
|
|
<MessageArea id={id} />
|
|
|
|
<TypingIndicator id={id} />
|
|
|
|
<JumpToBottom id={id} />
|
|
|
|
<MessageBox channel={channel} />
|
|
|
|
</ChannelContent>
|
|
|
|
{ !isTouchscreenDevice && showMembers && <MemberSidebar channel={channel} /> }
|
|
|
|
</ChannelMain>
|
|
|
|
</>;
|
|
|
|
}
|
|
|
|
|
|
|
|
function VoiceChannel({ channel }: { channel: Channel }) {
|
|
|
|
return <>
|
|
|
|
<ChannelHeader channel={channel} />
|
2021-06-24 05:54:32 -04:00
|
|
|
<VoiceHeader id={channel._id} />
|
2021-06-23 08:52:16 -04:00
|
|
|
</>;
|
2021-06-20 12:31:53 -04:00
|
|
|
}
|
2021-06-21 16:11:53 -04:00
|
|
|
|
|
|
|
export default function() {
|
|
|
|
const { channel } = useParams<{ channel: string }>();
|
|
|
|
return <Channel id={channel} key={channel} />;
|
|
|
|
}
|