// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import $ from 'jquery';
import ReactDOM from 'react-dom';
import * as UserAgent from 'utils/user_agent.jsx';
import {localizeMessage} from 'utils/utils.jsx';
import {FormattedMessage} from 'react-intl';
import React from 'react';
import loadingGif from 'images/load.gif';
export default class FilteredChannelList extends React.Component {
constructor(props) {
super(props);
this.handleFilterChange = this.handleFilterChange.bind(this);
this.createChannelRow = this.createChannelRow.bind(this);
this.filterChannels = this.filterChannels.bind(this);
this.state = {
filter: '',
joiningChannel: '',
channels: this.filterChannels(props.channels)
};
}
componentWillReceiveProps(nextProps) {
// assume the channel list is immutable
if (this.props.channels !== nextProps.channels) {
this.setState({
channels: this.filterChannels(nextProps.channels)
});
}
}
componentDidMount() {
// only focus the search box on desktop so that we don't cause the keyboard to open on mobile
if (!UserAgent.isMobile()) {
ReactDOM.findDOMNode(this.refs.filter).focus();
}
}
componentDidUpdate(prevProps, prevState) {
if (prevState.filter !== this.state.filter) {
$(ReactDOM.findDOMNode(this.refs.channelList)).scrollTop(0);
}
}
handleJoin(channel) {
this.setState({joiningChannel: channel.id});
this.props.handleJoin(
channel,
() => {
this.setState({joiningChannel: ''});
});
}
createChannelRow(channel) {
let joinButton;
if (this.state.joiningChannel === channel.id) {
joinButton = (
);
} else {
joinButton = (
);
}
return (
{channel.display_name}
{channel.purpose}