diff --git a/.vs/card_builder/v16/.suo b/.vs/card_builder/v16/.suo index b9cf8f5..4387a54 100644 Binary files a/.vs/card_builder/v16/.suo and b/.vs/card_builder/v16/.suo differ diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite index 9def4f0..4307ebb 100644 Binary files a/.vs/slnx.sqlite and b/.vs/slnx.sqlite differ diff --git a/src/Components/Card.css b/src/Components/Card.css index 28b1c01..e0696d9 100644 --- a/src/Components/Card.css +++ b/src/Components/Card.css @@ -163,7 +163,7 @@ color: white; font-size: 100px; position: relative; - width: 400px; + width: 350px; margin: 0 auto; font-family: 'Bangers', cursive; } diff --git a/src/Components/Card.js b/src/Components/Card.js index f7bd191..56b63c8 100644 --- a/src/Components/Card.js +++ b/src/Components/Card.js @@ -10,16 +10,16 @@ function randomColour() { } function Card(props) { - let { name, shows, abilities, img } = props; + let { name, shows, abilities, img, id } = props; abilities = Array.isArray(abilities) ? abilities : abilities.split(','); - let listAbilities = []; + let listAbilities = [], counter = 0; for (const ability of abilities) { const listAbility = - + listAbilities.push(listAbility); } return ( -
+
diff --git a/src/Containers/Main.js b/src/Containers/Main.js index fd950c1..c83d88a 100644 --- a/src/Containers/Main.js +++ b/src/Containers/Main.js @@ -25,7 +25,7 @@ function produceGrid(n, handleClick, cards) { for (let i = 0; i < n; i++) { let column = - + ; grid.push(column); } @@ -44,8 +44,16 @@ class Main extends Component { render() { const { handleClick, cards } = this.props; let grid = produceGrid(cards.length, handleClick, cards); + + const inputs = { + name: 'last one', + abilities: 'hit,shot', + shows: 'agent 7', + img: 'goimg' + } return ( -
+
+ {grid.map(g => g)} diff --git a/src/Containers/stylesheets/Main.css b/src/Containers/stylesheets/Main.css index 927a39b..030d297 100644 --- a/src/Containers/stylesheets/Main.css +++ b/src/Containers/stylesheets/Main.css @@ -1,4 +1,4 @@ -.container{ +.main.container{ margin:0 1.5rem; margin-bottom: 2rem; } \ No newline at end of file diff --git a/src/Services/apiCalls.js b/src/Services/apiCalls.js index 0853292..e5d83f1 100644 --- a/src/Services/apiCalls.js +++ b/src/Services/apiCalls.js @@ -4,4 +4,25 @@ const BASE_URL = "http://localhost:9000/"; export function getAll() { return axios.get(BASE_URL); -} \ No newline at end of file +} + +export function postOne(data) { + return axios({ + method: 'POST', + url: BASE_URL+'characters', + data: data + }) +} + +export function getOne(id) { + console.log(id, 'is the value of id'); + return axios.get(BASE_URL + id); +} + +async function test() { + getOne(51) + .then(resp => resp.data) + .then(data => console.log(data)) + .catch(e=>console.log(e)) +} +test(); \ No newline at end of file diff --git a/src/Store/actionTypes.js b/src/Store/actionTypes.js index 8700281..f852c6f 100644 --- a/src/Store/actionTypes.js +++ b/src/Store/actionTypes.js @@ -1,2 +1,6 @@ export const GET_ALL = 'GET ALL'; -export const UPDATE_ONE = 'UPDATE ONE CHARACTER'; \ No newline at end of file +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'; \ No newline at end of file diff --git a/src/Store/actions/actionCreators.js b/src/Store/actions/actionCreators.js index 1482236..83f2ba8 100644 --- a/src/Store/actions/actionCreators.js +++ b/src/Store/actions/actionCreators.js @@ -2,7 +2,10 @@ import { GET_ALL, UPDATE_ONE } from '../actionTypes'; import * as apicalls from '../../Services/apiCalls'; -export function doGetAll() { +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 @@ -12,4 +15,6 @@ export function doGetAll() { .catch(e => console.log(e)); } -} \ No newline at end of file +}*/ + +export { doGetAll, doPostOne }; diff --git a/src/Store/actions/doGetAll.js b/src/Store/actions/doGetAll.js new file mode 100644 index 0000000..0d180fd --- /dev/null +++ b/src/Store/actions/doGetAll.js @@ -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)); + } +} \ No newline at end of file diff --git a/src/Store/actions/doPostOne.js b/src/Store/actions/doPostOne.js new file mode 100644 index 0000000..89de9a1 --- /dev/null +++ b/src/Store/actions/doPostOne.js @@ -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') + + } +} \ No newline at end of file diff --git a/src/Store/reducers/getAll.js b/src/Store/reducers/getAll.js index d95642a..1e6085c 100644 --- a/src/Store/reducers/getAll.js +++ b/src/Store/reducers/getAll.js @@ -9,7 +9,6 @@ export default function (state = initialState, action) { const newState = action.payload; return newState; default: - console.log('no case matched'); return state; } } \ No newline at end of file diff --git a/src/Store/reducers/getOne.js b/src/Store/reducers/getOne.js new file mode 100644 index 0000000..de8ffa6 --- /dev/null +++ b/src/Store/reducers/getOne.js @@ -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; + } +} \ No newline at end of file diff --git a/src/Store/reducers/postOne.js b/src/Store/reducers/postOne.js new file mode 100644 index 0000000..015f5c4 --- /dev/null +++ b/src/Store/reducers/postOne.js @@ -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; + } +} \ No newline at end of file diff --git a/src/Store/reducers/rootReducer.js b/src/Store/reducers/rootReducer.js index b1b2691..9881277 100644 --- a/src/Store/reducers/rootReducer.js +++ b/src/Store/reducers/rootReducer.js @@ -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; \ No newline at end of file