fixed channel-select to not have internal state
This commit is contained in:
parent
c0b856d1f8
commit
e482c5f2f8
11 changed files with 37 additions and 28 deletions
|
@ -51,3 +51,10 @@ export function updateError (name, value) {
|
||||||
value,
|
value,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function updateSelectedChannel (value) {
|
||||||
|
return {
|
||||||
|
type: actions.SELECTED_CHANNEL_UPDATE,
|
||||||
|
value,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
|
@ -9,3 +9,4 @@ export const CLAIM_UPDATE = 'CLAIM_UPDATE';
|
||||||
export const SET_PUBLISH_IN_CHANNEL = 'SET_PUBLISH_IN_CHANNEL';
|
export const SET_PUBLISH_IN_CHANNEL = 'SET_PUBLISH_IN_CHANNEL';
|
||||||
export const PUBLISH_STATUS_UPDATE = 'PUBLISH_STATUS_UPDATE';
|
export const PUBLISH_STATUS_UPDATE = 'PUBLISH_STATUS_UPDATE';
|
||||||
export const ERROR_UPDATE = 'ERROR_UPDATE';
|
export const ERROR_UPDATE = 'ERROR_UPDATE';
|
||||||
|
export const SELECTED_CHANNEL_UPDATE = 'SELECTED_CHANNEL_UPDATE';
|
||||||
|
|
2
react/constants/channel_select_states.js
Normal file
2
react/constants/channel_select_states.js
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
export const LOGIN = 'Existing';
|
||||||
|
export const CREATE = 'New';
|
|
@ -1,4 +1,3 @@
|
||||||
// publishing states
|
|
||||||
export const LOAD_START = 'LOAD_START';
|
export const LOAD_START = 'LOAD_START';
|
||||||
export const LOADING = 'LOADING';
|
export const LOADING = 'LOADING';
|
||||||
export const PUBLISHING = 'PUBLISHING';
|
export const PUBLISHING = 'PUBLISHING';
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { updateLoggedInChannel } from 'actions/channel';
|
import { updateLoggedInChannel } from 'actions/channel';
|
||||||
import View from './view';
|
import View from './view';
|
||||||
|
import {updateSelectedChannel} from '../../actions/publish';
|
||||||
|
|
||||||
const mapDispatchToProps = dispatch => {
|
const mapDispatchToProps = dispatch => {
|
||||||
return {
|
return {
|
||||||
onChannelLogin: (name, shortId, longId) => {
|
onChannelLogin: (name, shortId, longId) => {
|
||||||
dispatch(updateLoggedInChannel(name, shortId, longId));
|
dispatch(updateLoggedInChannel(name, shortId, longId));
|
||||||
|
dispatch(updateSelectedChannel(name));
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { updateLoggedInChannel } from 'actions/channel';
|
import { updateLoggedInChannel } from 'actions/channel';
|
||||||
import View from './view';
|
import View from './view';
|
||||||
|
import {updateSelectedChannel} from '../../actions/publish';
|
||||||
|
|
||||||
const mapDispatchToProps = dispatch => {
|
const mapDispatchToProps = dispatch => {
|
||||||
return {
|
return {
|
||||||
onChannelLogin: (name, shortId, longId) => {
|
onChannelLogin: (name, shortId, longId) => {
|
||||||
dispatch(updateLoggedInChannel(name, shortId, longId));
|
dispatch(updateLoggedInChannel(name, shortId, longId));
|
||||||
|
dispatch(updateSelectedChannel(name));
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
import {connect} from 'react-redux';
|
import {connect} from 'react-redux';
|
||||||
import {setPublishInChannel} from 'actions/publish';
|
import {setPublishInChannel} from 'actions/publish';
|
||||||
import View from './view.jsx';
|
import View from './view.jsx';
|
||||||
|
import {updateSelectedChannel} from '../../actions/publish';
|
||||||
|
|
||||||
const mapStateToProps = ({ channel, publish }) => {
|
const mapStateToProps = ({ channel, publish }) => {
|
||||||
return {
|
return {
|
||||||
loggedInChannelName: channel.loggedInChannel.name,
|
loggedInChannelName: channel.loggedInChannel.name,
|
||||||
publishInChannel : publish.publishInChannel,
|
publishInChannel : publish.publishInChannel,
|
||||||
|
selectedChannel : publish.selectedChannel,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -14,6 +16,9 @@ const mapDispatchToProps = dispatch => {
|
||||||
onPublishInChannelChange: (value) => {
|
onPublishInChannelChange: (value) => {
|
||||||
dispatch(setPublishInChannel(value));
|
dispatch(setPublishInChannel(value));
|
||||||
},
|
},
|
||||||
|
onChannelSelect: (value) => {
|
||||||
|
dispatch(updateSelectedChannel(value));
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,29 +1,13 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ChannelLoginForm from 'containers/ChannelLoginForm';
|
import ChannelLoginForm from 'containers/ChannelLoginForm';
|
||||||
import ChannelCreateForm from 'containers/ChannelCreateForm';
|
import ChannelCreateForm from 'containers/ChannelCreateForm';
|
||||||
|
import * as states from 'constants/channel_select_states';
|
||||||
const LOGIN = 'Existing';
|
|
||||||
const CREATE = 'New';
|
|
||||||
|
|
||||||
class ChannelSelect extends React.Component {
|
class ChannelSelect extends React.Component {
|
||||||
constructor (props) {
|
constructor (props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
|
||||||
selectedOption: LOGIN,
|
|
||||||
};
|
|
||||||
this.toggleAnonymousPublish = this.toggleAnonymousPublish.bind(this);
|
this.toggleAnonymousPublish = this.toggleAnonymousPublish.bind(this);
|
||||||
this.handleSelection = this.handleSelection.bind(this);
|
this.handleSelection = this.handleSelection.bind(this);
|
||||||
this.selectOption = this.selectOption.bind(this);
|
|
||||||
}
|
|
||||||
componentDidMount () {
|
|
||||||
if (this.props.loggedInChannelName) {
|
|
||||||
this.selectOption(this.props.loggedInChannelName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
componentWillReceiveProps ({ loggedInChannelName }) {
|
|
||||||
if (loggedInChannelName && (loggedInChannelName !== this.props.loggedInChannelName)) {
|
|
||||||
this.selectOption(loggedInChannelName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
toggleAnonymousPublish (event) {
|
toggleAnonymousPublish (event) {
|
||||||
const value = event.target.value;
|
const value = event.target.value;
|
||||||
|
@ -35,10 +19,7 @@ class ChannelSelect extends React.Component {
|
||||||
}
|
}
|
||||||
handleSelection (event) {
|
handleSelection (event) {
|
||||||
const selectedOption = event.target.selectedOptions[0].value;
|
const selectedOption = event.target.selectedOptions[0].value;
|
||||||
this.selectOption(selectedOption);
|
this.props.onChannelSelect(selectedOption);
|
||||||
}
|
|
||||||
selectOption (option) {
|
|
||||||
this.setState({selectedOption: option});
|
|
||||||
}
|
}
|
||||||
render () {
|
render () {
|
||||||
return (
|
return (
|
||||||
|
@ -59,14 +40,14 @@ class ChannelSelect extends React.Component {
|
||||||
<div className="column column--3">
|
<div className="column column--3">
|
||||||
<label className="label" htmlFor="channel-name-select">Channel:</label>
|
<label className="label" htmlFor="channel-name-select">Channel:</label>
|
||||||
</div><div className="column column--7">
|
</div><div className="column column--7">
|
||||||
<select type="text" id="channel-name-select" className="select select--arrow" value={this.state.selectedOption} onChange={this.handleSelection}>
|
<select type="text" id="channel-name-select" className="select select--arrow" value={this.props.selectedChannel} onChange={this.handleSelection}>
|
||||||
{ this.props.loggedInChannelName && <option value={this.props.loggedInChannelName} id="publish-channel-select-channel-option">{this.props.loggedInChannelName}</option> }
|
{ this.props.loggedInChannelName && <option value={this.props.loggedInChannelName} id="publish-channel-select-channel-option">{this.props.loggedInChannelName}</option> }
|
||||||
<option value={LOGIN}>Existing</option>
|
<option value={states.LOGIN}>Existing</option>
|
||||||
<option value={CREATE}>New</option>
|
<option value={states.CREATE}>New</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
{ (this.state.selectedOption === LOGIN) && <ChannelLoginForm /> }
|
{ (this.props.selectedChannel === states.LOGIN) && <ChannelLoginForm /> }
|
||||||
{ (this.state.selectedOption === CREATE) && <ChannelCreateForm /> }
|
{ (this.props.selectedChannel === states.CREATE) && <ChannelCreateForm /> }
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { updateLoggedInChannel } from 'actions/channel';
|
import { updateLoggedInChannel } from 'actions/channel';
|
||||||
import View from './view';
|
import View from './view';
|
||||||
|
import {updateSelectedChannel} from '../../actions/publish';
|
||||||
|
|
||||||
const mapStateToProps = ({ channel }) => {
|
const mapStateToProps = ({ channel }) => {
|
||||||
return {
|
return {
|
||||||
|
@ -14,6 +15,7 @@ const mapDispatchToProps = dispatch => {
|
||||||
return {
|
return {
|
||||||
onChannelLogin: (name, shortId, longId) => {
|
onChannelLogin: (name, shortId, longId) => {
|
||||||
dispatch(updateLoggedInChannel(name, shortId, longId));
|
dispatch(updateLoggedInChannel(name, shortId, longId));
|
||||||
|
dispatch(updateSelectedChannel(name));
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -43,8 +43,10 @@ class NavBar extends React.Component {
|
||||||
let channelName, channelShortId, channelLongId;
|
let channelName, channelShortId, channelLongId;
|
||||||
({ channelName, channelShortId, channelLongId } = getUserCookies());
|
({ channelName, channelShortId, channelLongId } = getUserCookies());
|
||||||
console.log(`cookies found for channel: ${channelName} ${channelShortId} ${channelLongId}`);
|
console.log(`cookies found for channel: ${channelName} ${channelShortId} ${channelLongId}`);
|
||||||
|
if (channelName) {
|
||||||
this.props.onChannelLogin(channelName, channelShortId, channelLongId);
|
this.props.onChannelLogin(channelName, channelShortId, channelLongId);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
handleSelection (event) {
|
handleSelection (event) {
|
||||||
const value = event.target.selectedOptions[0].value;
|
const value = event.target.selectedOptions[0].value;
|
||||||
switch (value) {
|
switch (value) {
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
import * as actions from 'constants/action_types';
|
import * as actions from 'constants/action_types';
|
||||||
|
import * as channelSelectStates from 'constants/channel_select_states';
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
publishInChannel: false,
|
publishInChannel: false,
|
||||||
|
selectedChannel : channelSelectStates.LOGIN,
|
||||||
status : {
|
status : {
|
||||||
status : null,
|
status : null,
|
||||||
message: null,
|
message: null,
|
||||||
|
@ -61,6 +63,10 @@ export default function (state = initialState, action) {
|
||||||
[action.name]: action.value,
|
[action.name]: action.value,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
case actions.SELECTED_CHANNEL_UPDATE:
|
||||||
|
return Object.assign({}, state, {
|
||||||
|
selectedChannel: action.value,
|
||||||
|
});
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue