2021-12-11 14:34:12 +00:00
|
|
|
import { Hash } from "@styled-icons/boxicons-regular";
|
|
|
|
import { Ghost } from "@styled-icons/boxicons-solid";
|
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";
|
|
|
|
|
2021-09-08 02:40:57 +02:00
|
|
|
import { Text } from "preact-i18n";
|
2021-12-11 14:34:12 +00:00
|
|
|
import { useEffect, useState } from "preact/hooks";
|
2021-07-05 11:23:23 +01:00
|
|
|
|
2021-06-21 21:11:53 +01:00
|
|
|
import { isTouchscreenDevice } from "../../lib/isTouchscreenDevice";
|
2021-07-05 11:23:23 +01:00
|
|
|
|
2021-12-11 14:34:12 +00:00
|
|
|
import { useApplicationState } from "../../mobx/State";
|
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-09-08 02:40:57 +02:00
|
|
|
import Header from "../../components/ui/Header";
|
2021-07-05 11:23:23 +01:00
|
|
|
|
2021-08-09 15:51:22 +01:00
|
|
|
import RightSidebar from "../../components/navigation/RightSidebar";
|
2021-07-05 11:23:23 +01:00
|
|
|
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-09-08 02:40:57 +02:00
|
|
|
const PlaceholderBase = styled.div`
|
|
|
|
flex-grow: 1;
|
|
|
|
display: flex;
|
|
|
|
overflow: hidden;
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
|
|
.placeholder {
|
|
|
|
justify-content: center;
|
|
|
|
text-align: center;
|
|
|
|
margin: auto;
|
2021-12-11 14:34:12 +00:00
|
|
|
|
2021-09-08 02:40:57 +02:00
|
|
|
.primary {
|
|
|
|
color: var(--secondary-foreground);
|
|
|
|
font-weight: 700;
|
|
|
|
font-size: 22px;
|
|
|
|
margin: 0 0 5px 0;
|
|
|
|
}
|
2021-12-11 14:34:12 +00:00
|
|
|
|
2021-09-08 02:40:57 +02:00
|
|
|
.secondary {
|
|
|
|
color: var(--tertiary-foreground);
|
|
|
|
font-weight: 400;
|
|
|
|
}
|
2021-12-11 14:34:12 +00:00
|
|
|
|
2021-09-08 02:40:57 +02:00
|
|
|
svg {
|
|
|
|
margin: 2em auto;
|
|
|
|
fill-opacity: 0.8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
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-09-08 02:40:57 +02:00
|
|
|
if (!channel) return <ChannelPlaceholder />;
|
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-09-07 10:51:46 -04:00
|
|
|
const CHANNELS_SIDEBAR_KEY = "sidebar_channels";
|
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-09-07 10:51:46 -04:00
|
|
|
const [showChannels, setChannels] = useState(
|
|
|
|
getState().sectionToggle[CHANNELS_SIDEBAR_KEY] ?? true,
|
|
|
|
);
|
2021-07-06 22:44:38 +01:00
|
|
|
|
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={
|
2021-08-05 14:47:00 +01:00
|
|
|
!!(
|
|
|
|
(channel.channel_type === "TextChannel" ||
|
|
|
|
channel.channel_type === "Group") &&
|
2021-10-31 18:57:35 +01:00
|
|
|
channel.nsfw
|
2021-08-05 14:47:00 +01:00
|
|
|
)
|
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-09-07 10:51:46 -04:00
|
|
|
toggleChannelSidebar={() => {
|
2021-09-07 10:57:40 -04:00
|
|
|
if (isTouchscreenDevice) {
|
2021-12-11 14:34:12 +00:00
|
|
|
return;
|
2021-09-07 10:57:40 -04:00
|
|
|
}
|
|
|
|
|
2021-09-07 10:51:46 -04:00
|
|
|
setChannels(!showChannels);
|
|
|
|
|
|
|
|
if (showChannels) {
|
|
|
|
dispatch({
|
|
|
|
type: "SECTION_TOGGLE_SET",
|
|
|
|
id: CHANNELS_SIDEBAR_KEY,
|
|
|
|
state: false,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
dispatch({
|
|
|
|
type: "SECTION_TOGGLE_UNSET",
|
|
|
|
id: CHANNELS_SIDEBAR_KEY,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}}
|
2021-07-06 22:52:50 +01:00
|
|
|
/>
|
2021-07-05 11:25:20 +01:00
|
|
|
<ChannelMain>
|
|
|
|
<ChannelContent>
|
2021-12-11 14:34:12 +00:00
|
|
|
<VoiceHeader id={channel._id} />
|
2021-08-07 20:43:08 +01:00
|
|
|
<MessageArea channel={channel} />
|
2021-07-31 13:48:26 +01:00
|
|
|
<TypingIndicator channel={channel} />
|
2021-08-07 20:43:08 +01:00
|
|
|
<JumpToBottom channel={channel} />
|
2021-07-05 11:25:20 +01:00
|
|
|
<MessageBox channel={channel} />
|
|
|
|
</ChannelContent>
|
2021-08-09 15:51:22 +01:00
|
|
|
{!isTouchscreenDevice && showMembers && <RightSidebar />}
|
2021-07-05 11:25:20 +01:00
|
|
|
</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-09-08 02:40:57 +02:00
|
|
|
function ChannelPlaceholder() {
|
|
|
|
return (
|
|
|
|
<PlaceholderBase>
|
|
|
|
<Header placement="primary">
|
|
|
|
<Hash size={24} />
|
2021-12-11 14:34:12 +00:00
|
|
|
<span className="name">
|
|
|
|
<Text id="app.main.channel.errors.nochannel" />
|
|
|
|
</span>
|
2021-09-08 02:40:57 +02:00
|
|
|
</Header>
|
|
|
|
|
|
|
|
<div className="placeholder">
|
|
|
|
<Ghost width={80} />
|
2021-12-11 14:34:12 +00:00
|
|
|
<div className="primary">
|
|
|
|
<Text id="app.main.channel.errors.title" />
|
|
|
|
</div>
|
|
|
|
<div className="secondary">
|
|
|
|
<Text id="app.main.channel.errors.nochannels" />
|
|
|
|
</div>
|
2021-09-08 02:40:57 +02:00
|
|
|
</div>
|
|
|
|
</PlaceholderBase>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-08-05 14:47:00 +01:00
|
|
|
export default function ChannelComponent() {
|
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
|
|
|
}
|