2021-07-02 18:46:19 -04:00
|
|
|
import { useParams, useHistory } from "react-router-dom";
|
2021-07-05 06:23:23 -04:00
|
|
|
import { Channels } from "revolt.js/dist/api/objects";
|
|
|
|
import styled from "styled-components";
|
|
|
|
|
|
|
|
import { useState } from "preact/hooks";
|
|
|
|
|
2021-06-21 16:11:53 -04:00
|
|
|
import { isTouchscreenDevice } from "../../lib/isTouchscreenDevice";
|
2021-07-05 06:23:23 -04:00
|
|
|
|
2021-07-06 17:52:50 -04:00
|
|
|
import { dispatch, getState } from "../../redux";
|
|
|
|
|
2021-06-21 16:11:53 -04:00
|
|
|
import { useChannel, useForceUpdate } from "../../context/revoltjs/hooks";
|
2021-07-05 06:23:23 -04:00
|
|
|
|
|
|
|
import MessageBox from "../../components/common/messaging/MessageBox";
|
2021-06-21 16:11:53 -04:00
|
|
|
import JumpToBottom from "../../components/common/messaging/bars/JumpToBottom";
|
|
|
|
import TypingIndicator from "../../components/common/messaging/bars/TypingIndicator";
|
2021-07-08 15:16:50 -04:00
|
|
|
import AgeGate from "../../components/common/AgeGate";
|
2021-07-05 06:23:23 -04:00
|
|
|
|
|
|
|
import MemberSidebar from "../../components/navigation/right/MemberSidebar";
|
|
|
|
import ChannelHeader from "./ChannelHeader";
|
|
|
|
import { MessageArea } from "./messaging/MessageArea";
|
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`
|
2021-07-05 06:25:20 -04:00
|
|
|
flex-grow: 1;
|
|
|
|
display: flex;
|
|
|
|
min-height: 0;
|
|
|
|
overflow: hidden;
|
|
|
|
flex-direction: row;
|
2021-06-20 12:31:53 -04:00
|
|
|
`;
|
|
|
|
|
|
|
|
const ChannelContent = styled.div`
|
2021-07-05 06:25:20 -04:00
|
|
|
flex-grow: 1;
|
|
|
|
display: flex;
|
|
|
|
overflow: hidden;
|
|
|
|
flex-direction: column;
|
2021-06-20 12:31:53 -04:00
|
|
|
`;
|
|
|
|
|
2021-06-21 16:11:53 -04:00
|
|
|
export function Channel({ id }: { id: string }) {
|
2021-07-05 06:25:20 -04:00
|
|
|
const ctx = useForceUpdate();
|
|
|
|
const channel = useChannel(id, ctx);
|
2021-06-20 12:31:53 -04:00
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
if (!channel) return null;
|
2021-06-23 08:52:16 -04:00
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
if (channel.channel_type === "VoiceChannel") {
|
|
|
|
return <VoiceChannel channel={channel} />;
|
|
|
|
} else {
|
|
|
|
return <TextChannel channel={channel} />;
|
|
|
|
}
|
2021-06-23 08:52:16 -04:00
|
|
|
}
|
|
|
|
|
2021-07-06 17:52:50 -04:00
|
|
|
const MEMBERS_SIDEBAR_KEY = "sidebar_members";
|
2021-07-05 06:23:23 -04:00
|
|
|
function TextChannel({ channel }: { channel: Channels.Channel }) {
|
2021-07-06 17:52:50 -04:00
|
|
|
const [showMembers, setMembers] = useState(
|
|
|
|
getState().sectionToggle[MEMBERS_SIDEBAR_KEY] ?? true,
|
|
|
|
);
|
2021-07-06 17:44:38 -04:00
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
let id = channel._id;
|
|
|
|
return (
|
2021-07-08 15:16:50 -04:00
|
|
|
<AgeGate
|
|
|
|
type="channel"
|
|
|
|
channel={channel}
|
|
|
|
gated={(channel.channel_type === "TextChannel" ||
|
|
|
|
channel.channel_type === "Group") &&
|
|
|
|
channel.name.includes("nsfw")}>
|
2021-07-05 06:25:20 -04:00
|
|
|
<ChannelHeader
|
|
|
|
channel={channel}
|
2021-07-06 17:44:38 -04:00
|
|
|
toggleSidebar={() => {
|
|
|
|
setMembers(!showMembers);
|
|
|
|
|
|
|
|
if (showMembers) {
|
|
|
|
dispatch({
|
2021-07-06 17:52:50 -04:00
|
|
|
type: "SECTION_TOGGLE_SET",
|
2021-07-06 17:44:38 -04:00
|
|
|
id: MEMBERS_SIDEBAR_KEY,
|
2021-07-06 17:52:50 -04:00
|
|
|
state: false,
|
2021-07-06 17:44:38 -04:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
dispatch({
|
2021-07-06 17:52:50 -04:00
|
|
|
type: "SECTION_TOGGLE_UNSET",
|
|
|
|
id: MEMBERS_SIDEBAR_KEY,
|
2021-07-06 17:44:38 -04:00
|
|
|
});
|
|
|
|
}
|
2021-07-06 17:52:50 -04:00
|
|
|
}}
|
|
|
|
/>
|
2021-07-05 06:25:20 -04: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 15:16:50 -04:00
|
|
|
</AgeGate>
|
2021-07-05 06:25:20 -04:00
|
|
|
);
|
2021-06-23 08:52:16 -04:00
|
|
|
}
|
|
|
|
|
2021-07-05 06:23:23 -04:00
|
|
|
function VoiceChannel({ channel }: { channel: Channels.Channel }) {
|
2021-07-05 06:25:20 -04:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<ChannelHeader channel={channel} />
|
|
|
|
<VoiceHeader id={channel._id} />
|
|
|
|
</>
|
|
|
|
);
|
2021-06-20 12:31:53 -04:00
|
|
|
}
|
2021-06-21 16:11:53 -04:00
|
|
|
|
2021-07-05 06:23:23 -04:00
|
|
|
export default function () {
|
2021-07-05 06:25:20 -04:00
|
|
|
const { channel } = useParams<{ channel: string }>();
|
|
|
|
return <Channel id={channel} key={channel} />;
|
2021-06-21 16:11:53 -04:00
|
|
|
}
|