2021-06-19 17:37:12 -04:00
|
|
|
import { Text } from "preact-i18n";
|
|
|
|
import Category from "../../components/ui/Category";
|
|
|
|
import { GenericSettings } from "./GenericSettings";
|
|
|
|
import { getChannelName } from "../../context/revoltjs/util";
|
|
|
|
import { Route, useHistory, useParams } from "react-router-dom";
|
2021-07-01 12:36:34 -04:00
|
|
|
import { ListCheck, ListUl } from "@styled-icons/boxicons-regular";
|
2021-06-19 17:37:12 -04:00
|
|
|
import { useChannel, useForceUpdate } from "../../context/revoltjs/hooks";
|
|
|
|
|
2021-07-01 12:36:34 -04:00
|
|
|
import Overview from "./channel/Overview";
|
|
|
|
import Permissions from "./channel/Permissions";
|
2021-06-19 17:37:12 -04:00
|
|
|
|
|
|
|
export default function ChannelSettings() {
|
|
|
|
const { channel: cid } = useParams<{ channel: string; }>();
|
|
|
|
const ctx = useForceUpdate();
|
|
|
|
const channel = useChannel(cid, ctx);
|
|
|
|
if (!channel) return null;
|
|
|
|
if (channel.channel_type === 'SavedMessages' || channel.channel_type === 'DirectMessage') return null;
|
|
|
|
|
|
|
|
const history = useHistory();
|
|
|
|
function switchPage(to?: string) {
|
2021-07-01 12:36:34 -04:00
|
|
|
let base_url;
|
|
|
|
switch (channel?.channel_type) {
|
|
|
|
case 'TextChannel':
|
|
|
|
case 'VoiceChannel': base_url = `/server/${channel.server}/channel/${cid}/settings`; break;
|
|
|
|
default: base_url = `/channel/${cid}/settings`;
|
|
|
|
}
|
|
|
|
|
2021-06-19 17:37:12 -04:00
|
|
|
if (to) {
|
2021-07-01 12:36:34 -04:00
|
|
|
history.replace(`${base_url}/${to}`);
|
2021-06-19 17:37:12 -04:00
|
|
|
} else {
|
2021-07-01 12:36:34 -04:00
|
|
|
history.replace(base_url);
|
2021-06-19 17:37:12 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<GenericSettings
|
|
|
|
pages={[
|
|
|
|
{
|
2021-06-20 12:31:53 -04:00
|
|
|
category: <Category variant="uniform" text={getChannelName(ctx.client, channel, true)} />,
|
2021-06-19 17:37:12 -04:00
|
|
|
id: 'overview',
|
2021-06-27 06:17:59 -04:00
|
|
|
icon: <ListUl size={20} />,
|
2021-06-19 17:37:12 -04:00
|
|
|
title: <Text id="app.settings.channel_pages.overview.title" />
|
2021-07-01 12:36:34 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'permissions',
|
|
|
|
icon: <ListCheck size={20} />,
|
|
|
|
title: <Text id="app.settings.channel_pages.permissions.title" />
|
2021-06-19 17:37:12 -04:00
|
|
|
}
|
|
|
|
]}
|
|
|
|
children={[
|
2021-07-01 12:36:34 -04:00
|
|
|
<Route path="/server/:server/channel/:channel/settings/permissions"><Permissions channel={channel} /></Route>,
|
|
|
|
<Route path="/channel/:channel/settings/permissions"><Permissions channel={channel} /></Route>,
|
|
|
|
|
2021-06-19 17:37:12 -04:00
|
|
|
<Route path="/"><Overview channel={channel} /></Route>
|
|
|
|
]}
|
|
|
|
category="channel_pages"
|
|
|
|
switchPage={switchPage}
|
|
|
|
defaultPage="overview"
|
|
|
|
showExitButton
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|