Skip to content

Commit

Permalink
fixes rendering issue after posting a photo before refreshing the page
Browse files Browse the repository at this point in the history
  • Loading branch information
Schwartz10 committed Jan 20, 2018
1 parent 7d4221f commit 203177c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/components/CreatePost.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class CreatePost extends Component {
{this.props.user ?
<div>
<h1>Create Your Post {this.props.user.name}</h1>
<h3>You currently have {this.props.user.coinBalance} Tokens <br /></h3>
<h3>You currently have {this.props.user.coinBalance} Coins <br /></h3>
<TextField
value={this.props.postUrl}
hintText={!this.state.postUrl.length && "Enter Post URL"}
Expand Down
3 changes: 2 additions & 1 deletion src/components/Exchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Exchange extends Component {
render() {
return (
<div>
<h1>Buy Tokens</h1>
<h1>Buy InstaCoins</h1>
<SelectField
floatingLabelText="Coin Amount"
value={this.state.value}
Expand All @@ -35,6 +35,7 @@ class Exchange extends Component {
this.props.buyTokens(e, this.state.value, this.props.contract.buyTokens, this.props.accounts[0])}
label="Buy Tokens" primary={true}
/>
<h3>You have {this.props.user.coinBalance} Coins</h3>
</div>
);
}
Expand Down
1 change: 0 additions & 1 deletion src/components/Post.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import {Card, CardActions, CardHeader, CardMedia, CardTitle } from 'material-ui/Card';
import FlatButton from 'material-ui/FlatButton';
import LikePhoto from './LikePhoto';

const cardStyle = {
Expand Down
3 changes: 2 additions & 1 deletion src/store/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export const post = (url, contractFunc, account) =>
contractFunc(url, {from: account})
.then(res => {
let newPost = {}
newPost[account] = res.logs[0].args.url;
newPost.postUrl = res.logs[0].args.url;
newPost.account = account;
newPost.tokenPot = -5
return dispatch(createPost(newPost));
})
Expand Down
18 changes: 15 additions & 3 deletions src/store/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ const defaultUser = {}
const GET_USER = 'GET_USER';
const CREATE_USER = 'CREATE_USER';
const BUY_TOKENS = 'BUY_TOKENS';
const LIKED_POST = 'LIKED_POST'
const LIKED_POST = 'LIKED_POST';
const CREATE_POST = 'CREATE_POST';

/**
* ACTION CREATORS
*/
const getUser = user => ({type: GET_USER, user})
const createUser = user => ({type: CREATE_USER, user})
const boughtTokens = amount => ({type: BUY_TOKENS, amount})
const likedPost = post => ({type: LIKED_POST, post});

/**
* THUNK CREATORS
Expand All @@ -41,7 +41,14 @@ export const fetchUser = (contractFunc, account) =>
export const addUser = (name, contractFunc, account) =>
dispatch =>
contractFunc(name, {from: account})
.then(res => dispatch(createUser(res.logs[0].args)))
.then(res => {
let newUser = Object.assign({}, res.logs[0].args);
newUser.coinBalance = 0;
newUser.postUrl = "";
newUser.postLottery = "";
newUser.address = account;
dispatch(createUser(newUser));
})
.catch(err => console.log(err));

export const buyTokens = (amount, contractFunc, account) =>
Expand All @@ -63,6 +70,11 @@ export default function (state = defaultUser, action) {
return Object.assign({}, state, {coinBalance: action.amount});
case LIKED_POST:
return likedPostHelper.updateUser(state, action.post);
case CREATE_POST:
let updatedUser = Object.assign({}, state)
updatedUser.postUrl = action.post.postUrl;
updatedUser.postLottery = action.post.tokenPot;
return updatedUser;
default:
return state
}
Expand Down

0 comments on commit 203177c

Please sign in to comment.