diff --git a/src/App.tsx b/src/App.tsx index c0ab4b3..5802c45 100755 --- a/src/App.tsx +++ b/src/App.tsx @@ -4,7 +4,6 @@ import { BrowserRouter as Router, Route } from 'react-router-dom'; import Header from './components/Header/Header'; import './App.scss'; -import Channellist from './components/Channel/ChannelList'; import Home from './components/Home'; class App extends Component { diff --git a/src/components/Channel/ChannelEntry.tsx b/src/components/Channel/ChannelEntry.tsx index cd7645d..62a9b27 100644 --- a/src/components/Channel/ChannelEntry.tsx +++ b/src/components/Channel/ChannelEntry.tsx @@ -1,21 +1,30 @@ import React, { Component } from 'react'; +import ChannelList from './ChannelList'; -class ChannelEntry extends Component { - render() { - const { name, subchannels } = this.props.channel; - return ( - <> -
{name}
- {subchannels !== undefined && ( - - )} - - ); +const ChannelEntry = (props: ChannelEntryProps) => { + const { clients, channel } = props; + const joined: Client[] = []; + if (channel.totalClients > 0) { + clients.forEach(client => { + if (client.channelId === channel.id) joined.push(client); + }); } -} + + return ( + <> +
{channel.name}
+ {joined.length > 0 && ( + + )} + {channel.subchannels !== undefined && ( + + )} + + ); +}; export default ChannelEntry; diff --git a/src/components/Channel/ChannelList.scss b/src/components/Channel/ChannelList.scss index 06b21f3..d846b36 100644 --- a/src/components/Channel/ChannelList.scss +++ b/src/components/Channel/ChannelList.scss @@ -1,3 +1,3 @@ -.channelList li { +.channelList { list-style: none } diff --git a/src/components/Channel/ChannelList.tsx b/src/components/Channel/ChannelList.tsx index 8940978..4058702 100644 --- a/src/components/Channel/ChannelList.tsx +++ b/src/components/Channel/ChannelList.tsx @@ -1,39 +1,21 @@ import React, { Component } from 'react'; -import ChannelService from '../../services/ChannelService'; +import ApiService from '../../services/ApiService'; import ChannelEntry from './ChannelEntry'; import './ChannelList.scss'; -export default class Channellist extends Component { - constructor(props: any) { - super(props); - this.state = { - loaded: false, - channels: [], - }; - } +const ChannelList = ({ channels, clients }: ChannelListProps) => { + return ( +
    + {channels.map(channel => { + return ( +
  • + +
  • + ); + })} +
+ ); +}; - componentDidMount() { - ChannelService.fetchAllChannels().then(data => { - this.setState({ channels: data, loaded: true }); - }); - } - public render() { - const { loaded, channels } = this.state; - if (!loaded) { - return
Loading...
; - } else { - return ( -
    - {channels.map((e: Channel) => { - return ( -
  • - -
  • - ); - })} -
- ); - } - } -} +export default ChannelList; diff --git a/src/components/Channel/Channels.tsx b/src/components/Channel/Channels.tsx new file mode 100644 index 0000000..10d2ea6 --- /dev/null +++ b/src/components/Channel/Channels.tsx @@ -0,0 +1,33 @@ +import React, { Component } from 'react'; +import ApiService from '../../services/ApiService'; +import ChannelList from './ChannelList'; + +class Channels extends Component { + constructor(props: any) { + super(props); + this.state = { + loaded: false, + channels: [], + users: [], + }; + } + + componentDidMount() { + ApiService.fetchAllChannels().then(data => { + this.setState({ + channels: data.channelJson, + clients: data.clientJson, + loaded: true, + }); + }); + } + render() { + const { loaded, channels, clients } = this.state; + if (!loaded) return
Loading...
; + else { + return ; + } + } +} + +export default Channels; diff --git a/src/components/Home.tsx b/src/components/Home.tsx index 40794a6..fe8d963 100644 --- a/src/components/Home.tsx +++ b/src/components/Home.tsx @@ -1,11 +1,11 @@ import React, { Component } from 'react'; -import Channellist from './Channel/ChannelList'; +import Channels from './Channel/Channels'; export default class Home extends Component { render() { return (
- +
); } diff --git a/src/interfaces.d.ts b/src/interfaces.d.ts index db9ca9c..63b1dbb 100644 --- a/src/interfaces.d.ts +++ b/src/interfaces.d.ts @@ -6,8 +6,23 @@ interface Channel { subchannels: Channel[]; } +interface Client { + databaseId: number; + channelId: number; + nickname: string; + type: number; + away: boolean; + awayMessage: string; +} + +interface ChannelListProps { + channels: Channel[]; + clients: Client[]; +} + interface ChannelEntryProps { channel: Channel; + clients: Client[]; } interface ChannelViewProps { channel: Channel;