Fixed EditChannelHeaderModal's contents not always being updated when a change is made
Этот коммит содержится в:
@@ -1,8 +1,9 @@
|
|||||||
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
|
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
|
||||||
// See License.txt for license information.
|
// See License.txt for license information.
|
||||||
|
|
||||||
|
import AppDispatcher from '../dispatcher/app_dispatcher.jsx';
|
||||||
import * as Client from '../utils/client.jsx';
|
import * as Client from '../utils/client.jsx';
|
||||||
import * as AsyncClient from '../utils/async_client.jsx';
|
import Constants from '../utils/constants.jsx';
|
||||||
import * as Utils from '../utils/utils.jsx';
|
import * as Utils from '../utils/utils.jsx';
|
||||||
|
|
||||||
const Modal = ReactBootstrap.Modal;
|
const Modal = ReactBootstrap.Modal;
|
||||||
@@ -11,12 +12,14 @@ export default class EditChannelHeaderModal extends React.Component {
|
|||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
this.handleEdit = this.handleEdit.bind(this);
|
this.handleChange = this.handleChange.bind(this);
|
||||||
|
this.handleSubmit = this.handleSubmit.bind(this);
|
||||||
|
|
||||||
this.onShow = this.onShow.bind(this);
|
this.onShow = this.onShow.bind(this);
|
||||||
this.onHide = this.onHide.bind(this);
|
this.onHide = this.onHide.bind(this);
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
|
header: props.channel.header,
|
||||||
serverError: ''
|
serverError: ''
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -27,27 +30,38 @@ export default class EditChannelHeaderModal extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentWillReceiveProps(nextProps) {
|
||||||
|
if (this.props.channel.header !== nextProps.channel.header) {
|
||||||
|
this.setState({
|
||||||
|
header: nextProps.channel.header
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
componentDidUpdate(prevProps) {
|
componentDidUpdate(prevProps) {
|
||||||
if (this.props.show && !prevProps.show) {
|
if (this.props.show && !prevProps.show) {
|
||||||
this.onShow();
|
this.onShow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleEdit() {
|
handleChange(e) {
|
||||||
var data = {};
|
this.setState({
|
||||||
data.channel_id = this.props.channel.id;
|
header: e.target.value
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (data.channel_id.length !== 26) {
|
handleSubmit() {
|
||||||
return;
|
Client.updateChannelHeader(
|
||||||
}
|
this.props.channel.id,
|
||||||
|
this.state.header,
|
||||||
data.channel_header = ReactDOM.findDOMNode(this.refs.textarea).value;
|
(channel) => {
|
||||||
|
|
||||||
Client.updateChannelHeader(data,
|
|
||||||
() => {
|
|
||||||
this.setState({serverError: ''});
|
this.setState({serverError: ''});
|
||||||
AsyncClient.getChannel(this.props.channel.id);
|
|
||||||
this.onHide();
|
this.onHide();
|
||||||
|
|
||||||
|
AppDispatcher.handleServerAction({
|
||||||
|
type: Constants.ActionTypes.RECIEVED_CHANNEL,
|
||||||
|
channel
|
||||||
|
});
|
||||||
},
|
},
|
||||||
(err) => {
|
(err) => {
|
||||||
if (err.message === 'Invalid channel_header parameter') {
|
if (err.message === 'Invalid channel_header parameter') {
|
||||||
@@ -66,7 +80,8 @@ export default class EditChannelHeaderModal extends React.Component {
|
|||||||
|
|
||||||
onHide() {
|
onHide() {
|
||||||
this.setState({
|
this.setState({
|
||||||
serverError: ''
|
serverError: '',
|
||||||
|
header: this.props.channel.header
|
||||||
});
|
});
|
||||||
|
|
||||||
this.props.onHide();
|
this.props.onHide();
|
||||||
@@ -94,7 +109,8 @@ export default class EditChannelHeaderModal extends React.Component {
|
|||||||
rows='6'
|
rows='6'
|
||||||
id='edit_header'
|
id='edit_header'
|
||||||
maxLength='1024'
|
maxLength='1024'
|
||||||
defaultValue={this.props.channel.header}
|
value={this.state.header}
|
||||||
|
onChange={this.handleChange}
|
||||||
/>
|
/>
|
||||||
{serverError}
|
{serverError}
|
||||||
</Modal.Body>
|
</Modal.Body>
|
||||||
@@ -102,14 +118,14 @@ export default class EditChannelHeaderModal extends React.Component {
|
|||||||
<button
|
<button
|
||||||
type='button'
|
type='button'
|
||||||
className='btn btn-default'
|
className='btn btn-default'
|
||||||
onClick={this.props.onHide}
|
onClick={this.onHide}
|
||||||
>
|
>
|
||||||
{'Cancel'}
|
{'Cancel'}
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
type='button'
|
type='button'
|
||||||
className='btn btn-primary'
|
className='btn btn-primary'
|
||||||
onClick={this.handleEdit}
|
onClick={this.handleSubmit}
|
||||||
>
|
>
|
||||||
{'Save'}
|
{'Save'}
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -317,7 +317,9 @@ ChannelStore.dispatchToken = AppDispatcher.register((payload) => {
|
|||||||
|
|
||||||
case ActionTypes.RECIEVED_CHANNEL:
|
case ActionTypes.RECIEVED_CHANNEL:
|
||||||
ChannelStore.pStoreChannel(action.channel);
|
ChannelStore.pStoreChannel(action.channel);
|
||||||
ChannelStore.pStoreChannelMember(action.member);
|
if (action.member) {
|
||||||
|
ChannelStore.pStoreChannelMember(action.member);
|
||||||
|
}
|
||||||
currentId = ChannelStore.getCurrentId();
|
currentId = ChannelStore.getCurrentId();
|
||||||
if (currentId) {
|
if (currentId) {
|
||||||
ChannelStore.resetCounts(currentId);
|
ChannelStore.resetCounts(currentId);
|
||||||
|
|||||||
@@ -590,7 +590,12 @@ export function updateChannel(channel, success, error) {
|
|||||||
track('api', 'api_channels_update');
|
track('api', 'api_channels_update');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateChannelHeader(data, success, error) {
|
export function updateChannelHeader(channelId, header, success, error) {
|
||||||
|
const data = {
|
||||||
|
channel_id: channelId,
|
||||||
|
channel_header: header
|
||||||
|
};
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '/api/v1/channels/update_header',
|
url: '/api/v1/channels/update_header',
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user