Channel info favorite (#210)
* Enable toggling of favorite channel from channel_info * Change this binding * Handle favorite toggle with state
This commit is contained in:
parent
c9e513f83b
commit
1bd40d1a40
3 changed files with 33 additions and 6 deletions
|
|
@ -41,20 +41,44 @@ export default class ChannelInfo extends PureComponent {
|
|||
theme: PropTypes.object.isRequired,
|
||||
actions: PropTypes.shape({
|
||||
getChannelStats: PropTypes.func.isRequired,
|
||||
goToChannelMembers: PropTypes.func.isRequired
|
||||
goToChannelMembers: PropTypes.func.isRequired,
|
||||
markFavorite: PropTypes.func.isRequired,
|
||||
unmarkFavorite: PropTypes.func.isRequired
|
||||
})
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
isFavorite: this.props.isFavorite
|
||||
};
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
const isFavorite = nextProps.isFavorite;
|
||||
if (isFavorite !== this.state.isFavorite) {
|
||||
this.setState({isFavorite});
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.props.actions.getChannelStats(this.props.currentChannel.team_id, this.props.currentChannel.id);
|
||||
}
|
||||
|
||||
handleFavorite = () => {
|
||||
const {isFavorite, actions, currentChannel} = this.props;
|
||||
const {markFavorite, unmarkFavorite} = actions;
|
||||
const toggleFavorite = isFavorite ? unmarkFavorite : markFavorite;
|
||||
this.setState({isFavorite: !isFavorite});
|
||||
toggleFavorite(currentChannel.id);
|
||||
}
|
||||
|
||||
render() {
|
||||
const {
|
||||
currentChannel,
|
||||
currentChannelCreatorName,
|
||||
currentChannelMemberCount,
|
||||
isFavorite,
|
||||
theme
|
||||
} = this.props;
|
||||
|
||||
|
|
@ -72,9 +96,9 @@ export default class ChannelInfo extends PureComponent {
|
|||
purpose={currentChannel.purpose}
|
||||
/>
|
||||
<ChannelInfoRow
|
||||
action={() => true}
|
||||
action={this.handleFavorite}
|
||||
defaultMessage='Favorite'
|
||||
detail={isFavorite}
|
||||
detail={this.state.isFavorite}
|
||||
icon='star-o'
|
||||
textId='mobile.routes.channelInfo.favorite'
|
||||
togglable={true}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import {connect} from 'react-redux';
|
|||
|
||||
import {goToChannelMembers} from 'app/actions/navigation';
|
||||
import {getChannelStats} from 'service/actions/channels';
|
||||
import {markFavorite, unmarkFavorite} from 'app/actions/views/channel';
|
||||
import {getCurrentChannel, getCurrentChannelStats, getChannelsByCategory} from 'service/selectors/entities/channels';
|
||||
import {getTheme} from 'service/selectors/entities/preferences';
|
||||
import {getUser} from 'service/selectors/entities/users';
|
||||
|
|
@ -34,7 +35,9 @@ function mapDispatchToProps(dispatch) {
|
|||
return {
|
||||
actions: bindActionCreators({
|
||||
getChannelStats,
|
||||
goToChannelMembers
|
||||
goToChannelMembers,
|
||||
markFavorite,
|
||||
unmarkFavorite
|
||||
}, dispatch)
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ function channelInfoRow(props) {
|
|||
<Text style={style.detail}>{detail}</Text>
|
||||
{togglable ?
|
||||
<Switch
|
||||
action={action}
|
||||
onValueChange={action}
|
||||
value={detail}
|
||||
/> :
|
||||
<Icon
|
||||
|
|
|
|||
Loading…
Reference in a new issue