teemant-react/src/components/MessageBufferWrapper/MessageBufferWrapper.tsx

53 lines
1.4 KiB
TypeScript

import { Dispatch } from 'react';
import {
BufferState,
BufferAction,
BufferActionKind,
} from '../../lib/client-view.types';
import styles from './MessageBufferWrapper.module.scss';
import { MessageBufferView } from '../MessageBufferView/MessageBufferView';
import { NickListView } from '../NickListView/NickListView';
export const MessageBufferWrapper = ({
state,
dispatch,
}: {
state: BufferState;
dispatch: Dispatch<BufferAction>;
}) => {
const buff = state.buffers[state.activeIndex];
return buff ? (
<div className={styles.bufferRow}>
<MessageBufferView
topic={buff.topic}
sendMessage={(msg) => {
if (buff.type === 'channel' || buff.type === 'user') {
buff.connection.connection.write('PRIVMSG %s :%s', buff.name, msg);
dispatch({
type: BufferActionKind.AddBufferLine,
payload: {
connection: buff.connection,
toBuffer: {
type: buff.type,
name: buff.name,
},
message: {
type: 'privmsg',
time: new Date(),
sender: buff.connection.connection.options.nick,
message: msg,
},
},
});
}
}}
messages={buff.lines}
/>
{buff.type === 'channel' && <NickListView nicklist={buff.nicks} />}
</div>
) : (
<></>
);
};