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 ( return (
<> <>
<div>{channel.name}</div> {channel.name}
{joined.length > 0 && ( {joined.length > 0 && (
<ul> <ul>
{joined.map(e => ( {joined.map(e => (
<li>{e.nickname}</li> <li key={e.databaseId}>{e.nickname}</li>
))} ))}
</ul> </ul>
)} )}

View file

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

View file

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

View file

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