2022-08-19 19:15:10 +00:00
|
|
|
import { Modal, Input, List, Button } from 'antd';
|
|
|
|
import { ChannelsWrapper, AddFooter } from './Channels.styled';
|
2022-08-13 02:07:58 +00:00
|
|
|
import { CommentOutlined, SearchOutlined } from '@ant-design/icons';
|
2022-08-09 18:14:36 +00:00
|
|
|
import { useChannels } from './useChannels.hook';
|
|
|
|
import { ChannelItem } from './channelItem/ChannelItem';
|
2022-08-19 19:15:10 +00:00
|
|
|
import { AddChannel } from './addChannel/AddChannel';
|
2022-08-08 06:30:34 +00:00
|
|
|
|
2022-08-18 22:30:41 +00:00
|
|
|
export function Channels({ open }) {
|
2022-08-09 18:14:36 +00:00
|
|
|
|
|
|
|
const { state, actions } = useChannels();
|
|
|
|
|
2022-08-19 19:15:10 +00:00
|
|
|
const addChannel = async () => {
|
|
|
|
try {
|
|
|
|
await actions.addChannel();
|
|
|
|
actions.clearShowAdd();
|
|
|
|
}
|
|
|
|
catch(err) {
|
|
|
|
console.log(err);
|
|
|
|
Modal.error({
|
|
|
|
title: 'Failed to Create Channel',
|
|
|
|
content: 'Please try again.',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const addFooter = (
|
|
|
|
<AddFooter>
|
|
|
|
<Button key="back" onClick={actions.clearShowAdd}>Cancel</Button>
|
|
|
|
<Button key="save" type="primary" loading={state.busy} onClick={addChannel}>Save</Button>
|
|
|
|
</AddFooter>
|
|
|
|
);
|
|
|
|
|
2022-08-08 06:30:34 +00:00
|
|
|
return (
|
2022-08-19 19:15:10 +00:00
|
|
|
<ChannelsWrapper>
|
2022-08-15 05:19:23 +00:00
|
|
|
<div class="search">
|
|
|
|
<div class="filter">
|
|
|
|
<Input bordered={false} allowClear={true} placeholder="Channels" prefix={<SearchOutlined />}
|
2022-08-16 19:13:17 +00:00
|
|
|
spellCheck="false" onChange={(e) => actions.onFilter(e.target.value)} />
|
2022-08-08 06:30:34 +00:00
|
|
|
</div>
|
2022-08-15 05:19:23 +00:00
|
|
|
{ state.display === 'small' && (
|
|
|
|
<div class="inline">
|
2022-08-19 19:15:10 +00:00
|
|
|
<div class="add" onClick={actions.setShowAdd}>
|
2022-08-15 05:19:23 +00:00
|
|
|
<CommentOutlined />
|
|
|
|
<div class="label">New</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
<div class="view">
|
2022-08-09 18:14:36 +00:00
|
|
|
<List local={{ emptyText: '' }} itemLayout="horizontal" dataSource={state.channels} gutter="0"
|
|
|
|
renderItem={item => (
|
2022-08-19 19:15:10 +00:00
|
|
|
<ChannelItem item={item} openChannel={open} />
|
2022-08-09 18:14:36 +00:00
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</div>
|
2022-08-13 02:07:58 +00:00
|
|
|
{ state.display !== 'small' && (
|
|
|
|
<div class="bar">
|
2022-08-19 19:15:10 +00:00
|
|
|
<div class="add" onClick={actions.setShowAdd}>
|
2022-08-13 02:07:58 +00:00
|
|
|
<CommentOutlined />
|
|
|
|
<div class="label">New Channel</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
2022-08-19 19:15:10 +00:00
|
|
|
<Modal title="New Channel" centered visible={state.showAdd} footer={addFooter}
|
|
|
|
onCancel={actions.clearShowAdd}>
|
|
|
|
<AddChannel state={state} actions={actions} />
|
|
|
|
</Modal>
|
2022-08-08 06:30:34 +00:00
|
|
|
</ChannelsWrapper>
|
|
|
|
);
|
2022-08-05 22:06:53 +00:00
|
|
|
}
|
|
|
|
|