This repository has been archived by the owner on Sep 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
card shows up
- Loading branch information
Showing
19 changed files
with
130 additions
and
125 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,101 @@ | ||
import React, { Component } from 'react'; | ||
|
||
import { Segment, Grid } from 'semantic-ui-react'; | ||
import { bindActionCreators } from 'redux'; | ||
import { connect } from 'react-redux'; | ||
import * as actions from '../Store/actions/actionCreators'; | ||
|
||
import { Segment, Grid, Message, Icon, Dimmer } from 'semantic-ui-react'; | ||
import Card from '../Components/Card'; | ||
import Inputs from '../Components/Inputs'; | ||
|
||
import { postOne } from '../Services/apiCalls'; | ||
|
||
|
||
// functions for store subscriptions | ||
function mapStateToProps(state) { | ||
return { ...state }; | ||
} | ||
function mapDispatchToProps(dispatch) { | ||
return bindActionCreators(actions, dispatch); | ||
} | ||
|
||
|
||
|
||
class BuiltForm extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.handleChange = this.handleChange.bind(this); | ||
this.handleSubmit = this.handleSubmit.bind(this); | ||
this.handleDismiss = this.handleDismiss.bind(this); | ||
|
||
const { status } = this.props; | ||
if (status === 'edit') { | ||
this.state = { ...this.props }; | ||
this.state = { ...this.props, err: '' }; | ||
delete this.state[status]; | ||
} else { | ||
// status is new | ||
this.state = { | ||
name: '', | ||
shows: '', | ||
img: '', | ||
abilities: '' | ||
abilities: '', | ||
err: '', | ||
loading: false | ||
} | ||
} | ||
} | ||
|
||
handleChange(e, { name, value }) { | ||
console.log('we have ', name, value); | ||
this.setState({ [name]: value }); | ||
} | ||
|
||
handleSubmit() { | ||
console.log('you submitted the values', this.state); | ||
async handleSubmit() { | ||
console.log('submitting data now', this.state); | ||
this.setState({ loading: true }); | ||
let inputs = { ...this.state }; | ||
delete inputs['err']; // remove the unnecessary fields | ||
delete inputs['loading']; | ||
|
||
const m = await postOne(inputs); | ||
|
||
if (m.status === 0) this.setState({ loading: false, err: m.message }); | ||
if (m.status === 1) { | ||
await new Promise(resolve => setTimeout(resolve, 1500)); // needs at least 1 second to get the character | ||
this.props.doPutOne(m.character_id); | ||
this.props.hideForm(); | ||
this.setState({ | ||
name: '', shows: '', img: '', abilities: '', err: '' | ||
}); | ||
} | ||
} | ||
|
||
handleDismiss() { | ||
this.setState({ err: '' }); | ||
} | ||
|
||
render() { | ||
return ( | ||
<Segment piled> | ||
<Segment piled > | ||
{(this.state.err && this.state.err.length > 0 ? | ||
<Message icon error onDismiss={this.handleDismiss} > | ||
<Icon name='times circle' /> | ||
<Message.Header floated> | ||
{this.state.err} | ||
</Message.Header> | ||
</Message> : null)} | ||
<Grid columns={3} stackable celled='internally'> | ||
<Grid.Column floated='left'> | ||
<Card {...this.state} /> | ||
</Grid.Column> | ||
<Grid.Column floated='right'> | ||
<Inputs handleChange={this.handleChange} handleSubmit={this.handleSubmit} {...this.state} /> | ||
<Inputs handleChange={this.handleChange} handleSubmit={this.handleSubmit} {...this.state} /> | ||
</Grid.Column> | ||
</Grid> | ||
</Segment> | ||
); | ||
} | ||
} | ||
|
||
export default BuiltForm; | ||
const ConnectedBuiltForm = connect(mapStateToProps, mapDispatchToProps)(BuiltForm); | ||
|
||
export default ConnectedBuiltForm; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
export const GET_ALL = 'GET ALL'; | ||
export const UPDATE_ONE = 'UPDATE ONE CHARACTER'; | ||
export const GET_ONE = 'GET ONE'; | ||
export const POST_ONE = 'POST ONE'; | ||
export const PUT_ONE = 'PUT ONE CHARACTER'; | ||
|
||
export const ERR = 'AN ERROR OCCURRED'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,4 @@ | ||
import { GET_ALL, UPDATE_ONE } from '../actionTypes'; | ||
|
||
import * as apicalls from '../../Services/apiCalls'; | ||
|
||
import doGetAll from './doGetAll'; | ||
import doPostOne from './doPostOne'; | ||
|
||
/*export function doGetAll() { | ||
return (dispatch, getState) => { // we are returning a function | ||
console.log('we have getState as', getState()); // notice getState is a function | ||
//let num = 50 + getState().num; // be careful of the name of the variables inside the state | ||
apicalls.getAll() | ||
.then(response => response.data) | ||
.then(data => dispatch({ type: GET_ALL, payload: data })) | ||
.catch(e => console.log(e)); | ||
} | ||
}*/ | ||
import doPutOne from './doPutOne'; | ||
|
||
export { doGetAll, doPostOne }; | ||
export { doGetAll, doPutOne }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { PUT_ONE } from '../actionTypes'; | ||
|
||
import { getOne } from '../../Services/apiCalls'; | ||
|
||
export default function doPutOne(cid) { | ||
return async (dispatch, getState) => { | ||
getOne(cid) | ||
.then(response => response.data) | ||
.then(data => dispatch({ type: PUT_ONE, payload: { cards: getState().cards, newCharacter: data[0] } })) | ||
.catch(error => console.log(error, 'while retreiving that card')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { PUT_ONE } from '../actionTypes'; | ||
|
||
const initialState = ''; | ||
|
||
export default function (state = initialState, action) { | ||
switch (action.type) { | ||
case PUT_ONE: | ||
console.log('AT PUT ONE, we have the intial state as ', state, '\n and the action as ', action); | ||
const { cards, newCharacter } = action.payload; | ||
const newCards = cards.unshift(newCharacter); | ||
return { cards: newCards }; | ||
default: | ||
return state; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { combineReducers } from 'redux'; | ||
|
||
import getAll from './getAll'; | ||
import postOne from './postOne'; | ||
import putOne from './putOne'; | ||
|
||
const rootReducer = combineReducers({ cards : getAll, postOne }); // getAll is the name of the reducer and we are changing it's name to num | ||
const rootReducer = combineReducers({ cards: getAll, putOne }); // getAll is the name of the reducer and we are changing it's name to num | ||
|
||
export default rootReducer; |
Oops, something went wrong.