Skip to content

Commit

Permalink
intelliware-coe-web#7 wire up first cut of action for avatar
Browse files Browse the repository at this point in the history
  • Loading branch information
Gary Ng committed Jul 30, 2018
1 parent 7c00031 commit 3141425
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 7 deletions.
15 changes: 11 additions & 4 deletions src/UserProfile.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { Component } from 'react';
import avatar from './avatars/cat-avatars.jpg';

class UserProfile extends Component {
render() {
Expand All @@ -10,10 +11,16 @@ class UserProfile extends Component {
}
return (
<div className="UserProfile">
<p>Username: {this.props.userProfile.username}</p>
<p>Created Date: {this.props.userProfile.createdDate}</p>
<p>Description: {this.props.userProfile.description}</p>
<p>{storiesMessage}</p>
<div className="avatar">
<img src={avatar} width="100px"/>
<button onClick={this.props.makeCat}>Make Cat</button>
</div>
<div>
<p>Username: {this.props.userProfile.username}</p>
<p>Created Date: {this.props.userProfile.createdDate}</p>
<p>Description: {this.props.userProfile.description}</p>
<p>{storiesMessage}</p>
</div>
</div>
);
}
Expand Down
3 changes: 2 additions & 1 deletion src/UserProfileContainer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { connect } from 'react-redux'
import UserProfile from './UserProfile'
import { makeCat } from './actions'

const getUserProfile = (userProfile) => {
return userProfile;
Expand All @@ -11,7 +12,7 @@ const mapStateToProps = state => ({

const mapDispatchToProps = dispatch => {
return {
//no actions right now
makeCat: username => dispatch(makeCat(username))
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/actions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const makeCat = username => ({
type:'MAKE_CAT',
username
})
Binary file added src/avatars/cat-avatars.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { createStore } from 'redux';
import UserProfileReducer from './reducers/UserProfileReducer'
import UserProfileReducer from './reducers/UserProfileReducer';
import './index.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';
Expand Down
9 changes: 8 additions & 1 deletion src/reducers/UserProfileReducer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const initialState = {
//Mock initial state
userProfile: {
avatar:1,
username:'Jane Doe II',
createdDate:'2015-06-31',
description:'Amazing user',
Expand All @@ -11,8 +12,14 @@ const initialState = {
const UserProfileReducer = (state = [], action) => {
//Mock state until we start adding user profile data
if (typeof state === 'undefined' || state.length === 0) {
return initialState
state = initialState;
}

if (action.type === 'MAKE_CAT') {
state.userProfile.avatar++;
console.log("make cat clicked", state.userProfile, action);
}

return state
}
export default UserProfileReducer

0 comments on commit 3141425

Please sign in to comment.