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-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-05 06:23:23 -04:00
|
|
|
import Button from "../../components/ui/Button";
|
|
|
|
import Checkbox from "../../components/ui/Checkbox";
|
|
|
|
|
|
|
|
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-07-02 18:46:19 -04:00
|
|
|
const AgeGate = styled.div`
|
2021-07-05 06:25:20 -04:00
|
|
|
display: flex;
|
|
|
|
flex-grow: 1;
|
|
|
|
flex-direction: column;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
user-select: none;
|
|
|
|
padding: 12px;
|
|
|
|
|
|
|
|
img {
|
|
|
|
height: 150px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.subtext {
|
|
|
|
color: var(--secondary-foreground);
|
|
|
|
margin-bottom: 12px;
|
|
|
|
font-size: 14px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.actions {
|
|
|
|
margin-top: 20px;
|
|
|
|
display: flex;
|
|
|
|
gap: 12px;
|
|
|
|
}
|
2021-07-02 18:46:19 -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-05 06:23:23 -04:00
|
|
|
function TextChannel({ channel }: { channel: Channels.Channel }) {
|
2021-07-05 06:25:20 -04:00
|
|
|
const [showMembers, setMembers] = useState(true);
|
|
|
|
|
|
|
|
if (
|
|
|
|
(channel.channel_type === "TextChannel" ||
|
|
|
|
channel.channel_type === "Group") &&
|
|
|
|
channel.name.includes("nsfw")
|
|
|
|
) {
|
|
|
|
const goBack = useHistory();
|
|
|
|
const [consent, setConsent] = useState(false);
|
|
|
|
const [ageGate, setAgeGate] = useState(false);
|
|
|
|
if (!ageGate) {
|
|
|
|
return (
|
|
|
|
<AgeGate>
|
|
|
|
<img
|
|
|
|
src={"https://static.revolt.chat/emoji/mutant/26a0.svg"}
|
|
|
|
draggable={false}
|
|
|
|
/>
|
|
|
|
<h2>{channel.name}</h2>
|
|
|
|
<span className="subtext">
|
|
|
|
This channel is marked as NSFW.{" "}
|
|
|
|
<a href="#">Learn more</a>
|
|
|
|
</span>
|
|
|
|
|
|
|
|
<Checkbox checked={consent} onChange={(v) => setConsent(v)}>
|
|
|
|
I confirm that I am at least 18 years old.
|
|
|
|
</Checkbox>
|
|
|
|
<div className="actions">
|
|
|
|
<Button contrast onClick={() => goBack}>
|
|
|
|
Go back
|
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
contrast
|
|
|
|
onClick={() => consent && setAgeGate(true)}>
|
|
|
|
Enter Channel
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</AgeGate>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let id = channel._id;
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<ChannelHeader
|
|
|
|
channel={channel}
|
|
|
|
toggleSidebar={() => setMembers(!showMembers)}
|
|
|
|
/>
|
|
|
|
<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-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
|
|
|
}
|