refactoring

This commit is contained in:
Niel 2019-04-18 01:47:47 +02:00
parent 72c72a2ec1
commit e5dff62e1b
4 changed files with 21 additions and 12 deletions

View file

@ -12,11 +12,11 @@ const ChannelEntry = (props: ChannelEntryProps) => {
return (
<>
<div>{channel.name}</div>
{channel.name}
{joined.length > 0 && (
<ul>
{joined.map(e => (
<li>{e.nickname}</li>
<li key={e.databaseId}>{e.nickname}</li>
))}
</ul>
)}

View file

@ -2,24 +2,26 @@ import React, { Component } from 'react';
import ApiService from '../../services/ApiService';
import ChannelList from './ChannelList';
class Channels extends Component<any, any> {
class Channels extends Component<{}, ChannelState> {
constructor(props: any) {
super(props);
this.state = {
loaded: false,
channels: [],
users: [],
clients: [],
};
}
componentDidMount() {
ApiService.fetchAllChannels().then(data => {
this.setState({
channels: data.channelJson,
clients: data.clientJson,
loaded: true,
});
});
ApiService.fetchAllChannels()
.then(data => {
this.setState({
channels: data.channelJson,
clients: data.clientJson,
loaded: true,
});
})
.catch(e => console.error(e));
}
render() {
const { loaded, channels, clients } = this.state;

View file

@ -15,6 +15,12 @@ interface Client {
awayMessage: string;
}
interface ChannelState {
loaded: boolean;
channels: Channel[];
clients: Client[];
}
interface ChannelListProps {
channels: Channel[];
clients: Client[];

View file

@ -14,7 +14,8 @@
"jsx-boolean-value": false,
"member-access": false,
"no-console": false,
"strict-type-predicates": false
"strict-type-predicates": false,
"interface-name": false
},
"rulesDirectory": []
}