54 lines
2.0 KiB
TypeScript
Raw Normal View History

2021-08-31 14:09:49 +01:00
import { useDispatch, useSelector } from 'react-redux';
2021-07-29 15:54:50 +01:00
import AppNavbar from '../navigation/app-navbar';
2021-07-29 15:56:27 +01:00
import Sidebar from '../navigation/sidebar/sidebar';
2021-07-30 23:38:13 +01:00
import { Redirect, useParams } from 'react-router-dom';
2021-08-27 12:56:18 +01:00
import { actions as uiActions } from '../../store/ui';
2021-07-30 23:38:13 +01:00
import TextBasedChannel from '../channel/text-based-channel';
2021-08-06 00:12:20 +01:00
import MemberList from '../user/member-list';
2021-08-31 14:09:49 +01:00
import { getGuild, getGuildChannels } from '../../store/guilds';
2021-07-30 23:57:18 +01:00
import { useEffect } from 'react';
2021-07-31 16:44:21 +01:00
import PageWrapper from './page-wrapper';
2021-08-25 14:13:15 +01:00
import { getChannel } from '../../store/channels';
2021-07-26 18:41:57 +01:00
2021-08-04 21:08:23 +01:00
const GuildPage: React.FunctionComponent = () => {
2021-08-04 21:13:33 +01:00
const { channelId, guildId }: any = useParams();
2021-07-30 23:38:13 +01:00
const dispatch = useDispatch();
2021-08-23 16:48:36 +01:00
const ui = useSelector((s: Store.AppState) => s.ui);
2021-08-04 21:13:33 +01:00
const guild = useSelector(getGuild(guildId));
2021-08-25 14:13:15 +01:00
const channel = useSelector(getChannel(channelId));
const textChannels = useSelector(getGuildChannels(guildId)).filter(c => c.type === 'TEXT');
2021-07-31 03:14:00 +01:00
2021-07-30 23:57:18 +01:00
useEffect(() => {
2021-08-27 12:56:18 +01:00
dispatch(uiActions.pageSwitched({ channel, guild }));
2021-07-31 03:56:30 +01:00
}, [guild, channel]);
2021-07-30 23:57:18 +01:00
2021-08-12 15:56:19 +01:00
if (!guild)
2021-08-04 21:12:28 +01:00
return <Redirect to="/channels/@me" />;
else if (textChannels.length && !channelId) {
const systemChannel = textChannels[0];
2021-08-04 21:12:28 +01:00
return <Redirect to={`/channels/${guild.id}/${systemChannel.id}`} />;
2021-08-25 14:20:27 +01:00
}
2021-08-23 16:48:36 +01:00
2021-08-04 21:12:28 +01:00
return (ui.activeGuild) ? (
2021-08-10 12:32:36 +01:00
<PageWrapper pageTitle={channel?.name ?? guild.name}>
2021-07-29 15:17:06 +01:00
<Sidebar />
2021-08-07 21:36:52 +01:00
{(channel)
? <div className="bg-bg-primary">
<AppNavbar />
<div
style={{ height: 'calc(100vh - 48px)' }}
className="flex">
{ui.activeChannel && {
'TEXT': <TextBasedChannel />,
2025-03-22 16:23:24 +00:00
'DM': <TextBasedChannel />,
'VOICE': <div className="w-full p-2">Add something cool here for voice channels?</div>,
}[channel.type]}
<MemberList />
2021-08-07 21:36:52 +01:00
</div>
</div>
: <div className="bg-bg-tertiary" />}
2021-07-31 16:44:21 +01:00
</PageWrapper>
2021-08-04 21:12:28 +01:00
) : null;
2021-07-26 18:41:57 +01:00
}
export default GuildPage;