Skip to content
Commits on Source (2)
......@@ -38,11 +38,16 @@ export default class ChannelActions extends Component {
super(props)
this.state = {
selected: '',
scheduledCount: '',
}
this.handleSelection = this.handleSelection.bind(this);
}
componentWillMount() {
this.getScheduledCount();
}
showActionSheet = () => {
this.ActionSheet.show();
}
......@@ -110,6 +115,21 @@ export default class ChannelActions extends Component {
this.props.onEditAction();
}
onViewScheduledAction = async () => {
this.props.onViewScheduledAction();
}
getScheduledCount = async () => {
if (featuresService.has('post-scheduler')) {
const count = await this.props.store.feedStore.getScheduledCount();
this.setState({ scheduledCount: count });
}
}
shouldRenderScheduledButton = () => {
return featuresService.has('post-scheduler') && !this.state.edit;
}
/**
* Get Action Button, Message or Subscribe
*/
......@@ -117,14 +137,25 @@ export default class ChannelActions extends Component {
if (!this.props.store.loaded && sessionService.guid !== this.props.store.channel.guid )
return null;
if (sessionService.guid === this.props.store.channel.guid) {
return (
const viewScheduledButton = this.shouldRenderScheduledButton() ? (
<ButtonCustom
onPress={this.onEditAction}
containerStyle={[CS.rowJustifyCenter, CS.marginLeft0x]}
accessibilityLabel={this.props.editing ? i18n.t('channel.saveChanges') : i18n.t('channel.editChannel')}
text={this.props.editing ? i18n.t('save').toUpperCase() : i18n.t('edit').toUpperCase()}
loading={this.props.saving}
/>
onPress={this.onViewScheduledAction}
accessibilityLabel={i18n.t('channel.viewScheduled')}
text={`${i18n.t('channel.viewScheduled').toUpperCase()}: ${this.state.scheduledCount}`}
loading={this.state.saving}
inverted={this.props.store.feedStore.endpoint == this.props.store.feedStore.scheduledEndpoint ? true : undefined}
/> ) : null ;
return (
<View style={{ flexDirection: 'row', justifyContent: 'flex-end' }}>
{ viewScheduledButton }
<ButtonCustom
onPress={this.onEditAction}
containerStyle={[CS.rowJustifyCenter, CS.marginLeft0x]}
accessibilityLabel={this.props.editing ? i18n.t('channel.saveChanges') : i18n.t('channel.editChannel')}
text={this.props.editing ? i18n.t('save').toUpperCase() : i18n.t('edit').toUpperCase()}
loading={this.props.saving}
/>
</View>
);
} else if (!!this.props.store.channel.subscribed) {
return (
......
......@@ -153,10 +153,4 @@ export default class ChannelFeedStore {
this.endpoint = this.endpoint == this.feedsEndpoint ? this.scheduledEndpoint : this.feedsEndpoint;
this.setFilter(this.filter);
}
@action
toggleScheduled() {
this.endpoint = this.endpoint == this.feedsEndpoint ? this.scheduledEndpoint : this.feedsEndpoint;
this.setFilter(this.filter);
}
}
......@@ -59,8 +59,6 @@ export default class ChannelHeader extends Component {
name: '',
saving: false,
edit: false,
viewScheduled: false,
scheduledCount: '',
};
uploads = {
......@@ -96,10 +94,6 @@ export default class ChannelHeader extends Component {
}
}
componentWillMount() {
this.getScheduledCount();
}
componentDidMount() {
const isOwner = session.guid === this.props.store.channel.guid;
if(isOwner) this.props.onboarding.getProgress();
......@@ -150,73 +144,6 @@ export default class ChannelHeader extends Component {
this.props.store.feedStore.toggleScheduled();
}
getScheduledCount = async () => {
if (featuresService.has('post-scheduler')) {
const count = await this.props.store.feedStore.getScheduledCount();
this.setState({ scheduledCount: count });
}
}
shouldRenderScheduledButton = () => {
return featuresService.has('post-scheduler') && !this.state.edit;
}
/**
* Get Action Button, Message or Subscribe
*/
getActionButton() {
const styles = this.props.styles;
if (!this.props.store.loaded && session.guid !== this.props.store.channel.guid )
return null;
if (session.guid === this.props.store.channel.guid) {
const viewScheduledButton = this.shouldRenderScheduledButton() ? (
<ButtonCustom
onPress={this.onViewScheduledAction}
accessibilityLabel={i18n.t('channel.viewScheduled')}
text={`${i18n.t('channel.viewScheduled').toUpperCase()}: ${this.state.scheduledCount}`}
loading={this.state.saving}
inverted={this.props.store.feedStore.endpoint == this.props.store.feedStore.scheduledEndpoint ? true : undefined}
/> ) : null ;
return (
<View style={{ flexDirection: 'row', justifyContent: 'flex-end' }}>
{ viewScheduledButton }
<ButtonCustom
onPress={this.onEditAction}
accessibilityLabel={this.state.edit ? i18n.t('channel.saveChanges') : i18n.t('channel.editChannel')}
text={this.state.edit ? i18n.t('save').toUpperCase() : i18n.t('edit').toUpperCase()}
loading={this.state.saving}
/>
</View>
);
} else if (!!this.props.store.channel.subscribed) {
return (
<TouchableHighlightCustom
onPress={() => { this._navToConversation() }}
underlayColor='transparent'
style={[ComponentsStyle.button, ComponentsStyle.buttonAction, styles.bluebutton]}
accessibilityLabel={i18n.t('channel.sendMessage')}
>
<Text style={{ color: colors.primary }} > {i18n.t('channel.message')} </Text>
</TouchableHighlightCustom>
);
} else if (session.guid !== this.props.store.channel.guid) {
return (
<TouchableHighlightCustom
onPress={() => { this.subscribe() }}
underlayColor='transparent'
style={[ComponentsStyle.button, ComponentsStyle.buttonAction, styles.bluebutton]}
accessibilityLabel={i18n.t('channel.subscribeMessage')}
>
<Text style={{ color: colors.primary }} > {i18n.t('channel.subscribe').toUpperCase()} </Text>
</TouchableHighlightCustom>
);
} else if (this.props.store.isUploading) {
return (
<ActivityIndicator size="small" />
)
}
}
subscribe() {
this.props.store.channel.toggleSubscription();
}
......@@ -326,6 +253,7 @@ export default class ChannelHeader extends Component {
navigation={this.props.navigation}
store={this.props.store}
onEditAction={this.onEditAction}
onViewScheduledAction={this.onViewScheduledAction}
editing={this.state.edit}
saving={this.state.saving}
/>
......
......@@ -239,7 +239,7 @@ export default class FeedsService {
if (this.paginated && more) params.from_timestamp = this.pagingToken;
const response = await apiService.get(this.endpoint, params, this);
if (response.entities.length) {
if (response.entities && response.entities.length) {
if (more) {
this.feed = this.feed.concat(response.entities);
} else {
......