From 66e1496a73724d95bae123030ec97ccb275eef80 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Mon, 8 Jan 2018 17:46:17 -0800 Subject: [PATCH] added controlled component with redux (title) --- react/actions/index.js | 13 ++++++++++-- react/components/PublishForm.jsx | 6 +----- react/components/PublishTitleInput.jsx | 20 ++++++++++++++++-- react/components/PublishTool.jsx | 1 - react/reducers/index.js | 28 ++++++++++++++++---------- 5 files changed, 47 insertions(+), 21 deletions(-) diff --git a/react/actions/index.js b/react/actions/index.js index e20a077d..161c568d 100644 --- a/react/actions/index.js +++ b/react/actions/index.js @@ -1,12 +1,13 @@ // export action types export const FILE_SELECTED = 'FILE_SELECTED'; export const FILE_CLEAR = 'FILE_CLEAR'; +export const METADATA_UPDATE = 'TITLE_UPDATE'; // export action creators export function selectFile (file) { return { - type : FILE_SELECTED, - payload: file, + type: FILE_SELECTED, + file: file, }; }; @@ -15,3 +16,11 @@ export function clearFile () { type: FILE_CLEAR, }; }; + +export function updateMetadata (name, value) { + return { + type: METADATA_UPDATE, + name, + value, + }; +}; diff --git a/react/components/PublishForm.jsx b/react/components/PublishForm.jsx index f7529c2e..05d18e04 100644 --- a/react/components/PublishForm.jsx +++ b/react/components/PublishForm.jsx @@ -28,10 +28,7 @@ class PublishForm extends React.Component {
- +
@@ -103,7 +100,6 @@ const mapStateToProps = state => { loggedInChannelShortId: state.loggedInChannelShortId, publishToChannel : state.publishToChannel, file : state.file, - title : state.title, claim : state.claim, thumbnail : state.thumbnail, description : state.description, diff --git a/react/components/PublishTitleInput.jsx b/react/components/PublishTitleInput.jsx index 5540fd30..8a806472 100644 --- a/react/components/PublishTitleInput.jsx +++ b/react/components/PublishTitleInput.jsx @@ -1,4 +1,6 @@ import React from 'react'; +import {updateMetadata} from '../actions'; +import {connect} from 'react-redux'; class TitleInput extends React.Component { constructor (props) { @@ -9,7 +11,7 @@ class TitleInput extends React.Component { e.preventDefault(); const name = e.target.name; const value = e.target.value; - this.props.updateUploaderState(name, value); + this.props.onMetadataChange(name, value); } render () { return ( @@ -18,4 +20,18 @@ class TitleInput extends React.Component { } } -module.exports = TitleInput; +const mapStateToProps = state => { + return { + title: state.metadata.title, + }; +}; + +const mapDispatchToProps = dispatch => { + return { + onMetadataChange: (name, value) => { + dispatch(updateMetadata(name, value)); + }, + }; +} + +export default connect(mapStateToProps, mapDispatchToProps)(TitleInput); diff --git a/react/components/PublishTool.jsx b/react/components/PublishTool.jsx index 6af8cd17..066dbe5e 100644 --- a/react/components/PublishTool.jsx +++ b/react/components/PublishTool.jsx @@ -97,7 +97,6 @@ class PublishTool extends React.Component { { this.props.file &&