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.
- Loading branch information
Showing
15 changed files
with
121 additions
and
14 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
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,4 +1,4 @@ | ||
.container{ | ||
.main.container{ | ||
margin:0 1.5rem; | ||
margin-bottom: 2rem; | ||
} |
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,2 +1,6 @@ | ||
export const GET_ALL = 'GET ALL'; | ||
export const UPDATE_ONE = 'UPDATE ONE CHARACTER'; | ||
export const UPDATE_ONE = 'UPDATE ONE CHARACTER'; | ||
export const GET_ONE = 'GET ONE'; | ||
export const POST_ONE = 'POST ONE'; | ||
|
||
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
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,13 @@ | ||
import { getAll } from '../../Services/apiCalls'; | ||
import { GET_ALL, UPDATE_ONE } from '../actionTypes'; | ||
|
||
export default 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 | ||
getAll() | ||
.then(response => response.data) | ||
.then(data => dispatch({ type: GET_ALL, payload: data })) | ||
.catch(e => console.log(e)); | ||
} | ||
} |
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,28 @@ | ||
import { POST_ONE, GET_ONE, ERR } from '../actionTypes'; | ||
|
||
import { postOne, getOne } from '../../Services/apiCalls'; | ||
|
||
export default function doPostOne(inputs) { | ||
return async (dispatch, getState) => { | ||
const resPostOne = await postOne(inputs).catch(e => console.log(e, 'at 1')); | ||
const dataPostOne = resPostOne.data; | ||
|
||
if ('code' in dataPostOne && dataPostOne.code === '23505') | ||
return dispatch({ type: ERR, payload: "That Character already exists!" }); | ||
else if ('code' in dataPostOne) | ||
return dispatch({ type: ERR, payload: "Oops! Something went wrong while submitting your Character." }) | ||
|
||
const character_id = dataPostOne.character_id; | ||
console.log('got tha char id as', character_id, dataPostOne); | ||
|
||
if (character_id) { | ||
await new Promise(resolve => setTimeout(resolve, 1000)); // needs at least 1 second to get the character | ||
console.log(character_id, 'is the character id'); | ||
const resp = await getOne(character_id).catch('Please check your network connectivity!'); | ||
const newCharacter = resp.data; | ||
console.log('got this', newCharacter); | ||
return dispatch({ type: POST_ONE, payload: { newCharacter, cards: getState().cards } }); | ||
}else console.log('did not happen') | ||
|
||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { GET_ONE } from '../actionTypes'; | ||
|
||
const initialState = ''; // acts as placeholder | ||
|
||
export default function (state = initialState, action) { | ||
switch (action.type) { | ||
case GET_ONE: | ||
console.log('at getone, we have the intial state as ', state, '\n and the action as ', action); | ||
const { cards, newCard } = action.payload; | ||
const newState = cards.unshift(newCard); | ||
return newState; | ||
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { POST_ONE } from '../actionTypes'; | ||
|
||
const initialState = []; | ||
|
||
export default function (state = initialState, action) { | ||
switch (action.type) { | ||
case POST_ONE: console.log('reached postone', action, state); | ||
return state; | ||
break; | ||
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,7 +1,8 @@ | ||
import { combineReducers } from 'redux'; | ||
|
||
import getAll from './getAll'; | ||
import postOne from './postOne'; | ||
|
||
const rootReducer = combineReducers({ cards : getAll }); // getAll is the name of the reducer and we are changing it's name to num | ||
const rootReducer = combineReducers({ cards : getAll, postOne }); // getAll is the name of the reducer and we are changing it's name to num | ||
|
||
export default rootReducer; |