diff --git a/client/coral-embed-stream/src/actions/embed.js b/client/coral-embed-stream/src/actions/embed.js new file mode 100644 index 000000000..09d68dbf1 --- /dev/null +++ b/client/coral-embed-stream/src/actions/embed.js @@ -0,0 +1,4 @@ +import * as actions from '../constants/embed'; + +export const setActiveTab = (tab) => ({type: actions.SET_ACTIVE_TAB, tab}); + diff --git a/client/coral-embed-stream/src/components/Embed.js b/client/coral-embed-stream/src/components/Embed.js index 09d919c76..e84d86ec2 100644 --- a/client/coral-embed-stream/src/components/Embed.js +++ b/client/coral-embed-stream/src/components/Embed.js @@ -13,29 +13,24 @@ import RestrictedContent from 'coral-framework/components/RestrictedContent'; import ConfigureStreamContainer from 'coral-configure/containers/ConfigureStreamContainer'; export default class Embed extends React.Component { - state = { - activeTab: 0, - }; - changeTab = (tab) => { - if (tab === 0) { - if (this.props.data.comment) { - this.props.viewAllComments(); - } - else { - - // TODO: don't rely on refetching. - this.props.data.refetch(); - } + switch(tab) { + case 0: + this.props.setActiveTab('stream'); + break; + case 1: + this.props.setActiveTab('profile'); + break; + case 2: + this.props.setActiveTab('config'); + break; + default: + throw new Error(`Unknown tab ${tab}`); } - - this.setState({ - activeTab: tab - }); } render () { - const {activeTab} = this.state; + const {activeTab} = this.props; const {asset, comment} = this.props.data; const {loggedIn, isAdmin, user, showSignInDialog} = this.props.auth; @@ -63,7 +58,7 @@ export default class Embed extends React.Component { {lang.t('showAllComments')} } - + { loggedIn ? userBox : null } - + - + { loggedIn ? userBox : null } diff --git a/client/coral-embed-stream/src/constants/embed.js b/client/coral-embed-stream/src/constants/embed.js new file mode 100644 index 000000000..178e5d6e4 --- /dev/null +++ b/client/coral-embed-stream/src/constants/embed.js @@ -0,0 +1 @@ +export const SET_ACTIVE_TAB = 'SET_ACTIVE_TAB'; diff --git a/client/coral-embed-stream/src/containers/Embed.js b/client/coral-embed-stream/src/containers/Embed.js index 808af8645..937cec89f 100644 --- a/client/coral-embed-stream/src/containers/Embed.js +++ b/client/coral-embed-stream/src/containers/Embed.js @@ -14,6 +14,7 @@ import {notificationActions, authActions, assetActions, pym} from 'coral-framewo import {NEW_COMMENT_COUNT_POLL_INTERVAL} from '../constants/stream'; import Embed from '../components/Embed'; import {setCommentCountCache, setActiveReplyBox, viewAllComments} from '../actions/stream'; +import {setActiveTab} from '../actions/embed'; import * as Stream from './Stream'; const {logout, showSignInDialog, requestConfirmEmail} = authActions; @@ -260,6 +261,7 @@ const mapStateToProps = state => ({ commentId: state.stream.commentId, assetId: state.stream.assetId, assetUrl: state.stream.assetUrl, + activeTab: state.embed.activeTab, }); const mapDispatchToProps = dispatch => @@ -274,6 +276,7 @@ const mapDispatchToProps = dispatch => viewAllComments, logout, setActiveReplyBox, + setActiveTab, }, dispatch); export default compose( diff --git a/client/coral-embed-stream/src/reducers/embed.js b/client/coral-embed-stream/src/reducers/embed.js new file mode 100644 index 000000000..e7fe5a533 --- /dev/null +++ b/client/coral-embed-stream/src/reducers/embed.js @@ -0,0 +1,17 @@ +import * as actions from '../constants/embed'; + +const initialState = { + activeTab: 'stream', +}; + +export default function stream(state = initialState, action) { + switch (action.type) { + case actions.SET_ACTIVE_TAB: + return { + ...state, + activeTab: action.tab, + }; + default: + return state; + } +} diff --git a/client/coral-embed-stream/src/reducers/index.js b/client/coral-embed-stream/src/reducers/index.js index 6a312a84a..a9049fc14 100644 --- a/client/coral-embed-stream/src/reducers/index.js +++ b/client/coral-embed-stream/src/reducers/index.js @@ -1,5 +1,7 @@ import stream from './stream'; +import embed from './embed'; export default { - stream + stream, + embed, };