From 6237631a85b79311a60b87df423abbdce56c7876 Mon Sep 17 00:00:00 2001 From: hmhealey Date: Mon, 16 Nov 2015 12:08:05 -0500 Subject: Ported EditChannelModal to React-Bootstrap --- web/react/components/channel_header.jsx | 27 ++--- web/react/components/edit_channel_modal.jsx | 174 ++++++++++++--------------- web/react/components/navbar.jsx | 56 ++++++--- web/react/components/toggle_modal_button.jsx | 17 ++- web/react/pages/channel.jsx | 6 - web/react/utils/channel_intro_mssages.jsx | 51 +++----- web/react/utils/utils.jsx | 17 +-- 7 files changed, 161 insertions(+), 187 deletions(-) diff --git a/web/react/components/channel_header.jsx b/web/react/components/channel_header.jsx index 8c721348f..06d5db8b0 100644 --- a/web/react/components/channel_header.jsx +++ b/web/react/components/channel_header.jsx @@ -4,6 +4,7 @@ import NavbarSearchBox from './search_bar.jsx'; import MessageWrapper from './message_wrapper.jsx'; import PopoverListMembers from './popover_list_members.jsx'; +import EditChannelModal from './edit_channel_modal.jsx'; import EditChannelPurposeModal from './edit_channel_purpose_modal.jsx'; import ChannelInfoModal from './channel_info_modal.jsx'; import ChannelInviteModal from './channel_invite_modal.jsx'; @@ -167,17 +168,13 @@ export default class ChannelHeader extends React.Component { key='edit_header_direct' role='presentation' > - {'Set Channel Header...'} - + ); } else { @@ -235,17 +232,13 @@ export default class ChannelHeader extends React.Component { key='set_channel_header' role='presentation' > - - {'Set '}{channelTerm}{' Header...'} - + {`Set ${channelTerm} Header...`} + ); dropdownContents.push( diff --git a/web/react/components/edit_channel_modal.jsx b/web/react/components/edit_channel_modal.jsx index 80dab4a57..487ae6964 100644 --- a/web/react/components/edit_channel_modal.jsx +++ b/web/react/components/edit_channel_modal.jsx @@ -3,39 +3,51 @@ import * as Client from '../utils/client.jsx'; import * as AsyncClient from '../utils/async_client.jsx'; +import * as Utils from '../utils/utils.jsx'; + +const Modal = ReactBootstrap.Modal; export default class EditChannelModal extends React.Component { constructor(props) { super(props); this.handleEdit = this.handleEdit.bind(this); - this.handleUserInput = this.handleUserInput.bind(this); - this.handleClose = this.handleClose.bind(this); + this.onShow = this.onShow.bind(this); - this.handleShown = this.handleShown.bind(this); + this.onHide = this.onHide.bind(this); this.state = { - header: '', - title: '', - channelId: '', serverError: '' }; } + + componentDidMount() { + if (this.props.show) { + this.onShow(); + } + } + + componentDidUpdate(prevProps) { + if (this.props.show && !prevProps.show) { + this.onShow(); + } + } + handleEdit() { var data = {}; - data.channel_id = this.state.channelId; + data.channel_id = this.props.channel.id; if (data.channel_id.length !== 26) { return; } - data.channel_header = this.state.header.trim(); + data.channel_header = ReactDOM.findDOMNode(this.refs.textarea).value; Client.updateChannelHeader(data, () => { this.setState({serverError: ''}); - AsyncClient.getChannel(this.state.channelId); - $(ReactDOM.findDOMNode(this.refs.modal)).modal('hide'); + AsyncClient.getChannel(this.props.channel.id); + this.onHide(); }, (err) => { if (err.message === 'Invalid channel_header parameter') { @@ -46,105 +58,69 @@ export default class EditChannelModal extends React.Component { } ); } - handleUserInput(e) { - this.setState({header: e.target.value}); - } - handleClose() { - this.setState({header: '', serverError: ''}); - } - onShow(e) { - const button = e.relatedTarget; - this.setState({header: $(button).attr('data-header'), title: $(button).attr('data-title'), channelId: $(button).attr('data-channelid'), serverError: ''}); - } - handleShown() { - $('#edit_channel #edit_header').focus(); - } - componentDidMount() { - $(ReactDOM.findDOMNode(this.refs.modal)).on('show.bs.modal', this.onShow); - $(ReactDOM.findDOMNode(this.refs.modal)).on('hidden.bs.modal', this.handleClose); - $(ReactDOM.findDOMNode(this.refs.modal)).on('shown.bs.modal', this.handleShown); + + onShow() { + const textarea = ReactDOM.findDOMNode(this.refs.textarea); + Utils.placeCaretAtEnd(textarea); } - componentWillUnmount() { - $(ReactDOM.findDOMNode(this.refs.modal)).off('hidden.bs.modal', this.handleClose); + + onHide() { + this.setState({ + serverError: '' + }); + + this.props.onHide(); } + render() { var serverError = null; if (this.state.serverError) { serverError =

; } - var editTitle = ( -

- {'Edit Header'} -

- ); - if (this.state.title) { - editTitle = ( -

- {'Edit Header for '}{this.state.title} -

- ); - } - return ( -