revite/src/pages/settings/ChannelSettings.tsx

92 lines
2.8 KiB
TypeScript
Raw Normal View History

2021-07-01 12:36:34 -04:00
import { ListCheck, ListUl } from "@styled-icons/boxicons-regular";
2021-08-05 09:47:00 -04:00
import { Route, Switch, useHistory, useParams } from "react-router-dom";
2021-07-05 06:23:23 -04:00
import { Text } from "preact-i18n";
2021-07-29 13:41:01 -04:00
import { useClient } from "../../context/revoltjs/RevoltClient";
2021-07-05 06:23:23 -04:00
import { getChannelName } from "../../context/revoltjs/util";
import Category from "../../components/ui/Category";
2021-06-19 17:37:12 -04:00
2021-07-05 06:23:23 -04:00
import { GenericSettings } from "./GenericSettings";
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() {
2021-07-05 06:25:20 -04:00
const { channel: cid } = useParams<{ channel: string }>();
2021-07-29 13:41:01 -04:00
const client = useClient();
2021-08-05 09:47:00 -04:00
const history = useHistory();
const channel = client.channels.get(cid);
2021-08-05 09:47:00 -04:00
2021-07-05 06:25:20 -04:00
if (!channel) return null;
if (
channel.channel_type === "SavedMessages" ||
channel.channel_type === "DirectMessage"
)
return null;
2021-07-05 06:23:23 -04:00
2021-07-05 06:25:20 -04:00
function switchPage(to?: string) {
let base_url;
switch (channel?.channel_type) {
case "TextChannel":
case "VoiceChannel":
base_url = `/server/${channel.server_id}/channel/${cid}/settings`;
2021-07-05 06:25:20 -04:00
break;
default:
base_url = `/channel/${cid}/settings`;
}
2021-07-05 06:23:23 -04:00
2021-07-05 06:25:20 -04:00
if (to) {
history.replace(`${base_url}/${to}`);
} else {
history.replace(base_url);
}
}
2021-07-05 06:23:23 -04:00
2021-07-05 06:25:20 -04:00
return (
<GenericSettings
pages={[
{
category: (
<Category
variant="uniform"
text={getChannelName(channel, true)}
2021-07-05 06:25:20 -04:00
/>
),
id: "overview",
icon: <ListUl size={20} />,
title: (
<Text id="app.settings.channel_pages.overview.title" />
),
},
{
id: "permissions",
icon: <ListCheck size={20} />,
title: (
<Text id="app.settings.channel_pages.permissions.title" />
),
},
]}
2021-08-05 09:47:00 -04:00
children={
<Switch>
<Route path="/server/:server/channel/:channel/settings/permissions">
<Permissions channel={channel} />
</Route>
<Route path="/channel/:channel/settings/permissions">
<Permissions channel={channel} />
</Route>
2021-07-05 06:23:23 -04:00
2021-08-05 09:47:00 -04:00
<Route>
<Overview channel={channel} />
</Route>
</Switch>
}
2021-07-05 06:25:20 -04:00
category="channel_pages"
switchPage={switchPage}
defaultPage="overview"
showExitButton
/>
);
2021-06-19 17:37:12 -04:00
}