Channel.tsx 1.49 KB
Newer Older
insert's avatar
insert committed
1 2 3 4 5 6 7 8
import React, { useContext, useState, useEffect } from 'react';
import styles from './Channel.module.scss';
import classNames from 'classnames';

import { ChatContext, Page } from '../Chat';
import { Channel as RChannel, Collection } from 'riotchat.js';
import { Instance } from '../../internal/Client';
import { Message } from 'riotchat.js/dist/internal/Message';
insert's avatar
insert committed
9
import { scrollable, hiddenScrollbar } from '../../components/util/Scrollbar';
insert's avatar
insert committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42

export default function Channel(props: { id: string }) {
	let chat = useContext(ChatContext);
	let channel: RChannel = Instance.client.channels.get(chat.channel as string) as any;
	let [ synced, setSynced ] = useState(false);

	useEffect(() => {
		if (!synced) {
			channel.fetchMessages()
				.then(() => setSynced(true));
		}
	}, [chat.channel, channel, synced]);

	let sidebar = classNames({
		[styles.sidebar]: true,
		[styles.visible]: !!((Page.GROUP | Page.GUILD) & chat.page)
	});

	let messages = (channel.messages as Collection<string, Message>).array();
	return (
		<div className={styles.root}>
			<div className={styles.header}>
				channel id = {channel.id}
			</div>
			<div className={styles.body}>
				<div className={styles.chat}>
					<div className={classNames(styles.messages, scrollable)}>
						{ messages.map(m => <p>{m.author.username}: {m.content}</p>) }
					</div>
					<div className={styles.messageBox}>
						box
					</div>
				</div>
insert's avatar
insert committed
43
				<div className={classNames(sidebar, hiddenScrollbar)}>
insert's avatar
insert committed
44 45 46 47 48 49
					sidebar time
				</div>
			</div>
		</div>
	);
}