generated from microverseinc/readme-template
-
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
1 parent
9fcabb2
commit 82e2eb0
Showing
5 changed files
with
243 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,11 +1,15 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom/client'; | ||
import { Provider } from 'react-redux'; | ||
import './index.css'; | ||
import App from './App'; | ||
import elementStore from './redux/configureStore'; | ||
|
||
const root = ReactDOM.createRoot(document.getElementById('root')); | ||
root.render( | ||
<React.StrictMode> | ||
<App /> | ||
<Provider store={elementStore}> | ||
<App /> | ||
</Provider> | ||
</React.StrictMode>, | ||
); |
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 { createStore, combineReducers, applyMiddleware } from 'redux'; | ||
import logger from 'redux-logger'; | ||
import thunk from 'redux-thunk'; | ||
import rocketReducer, { fetchRocketsAPI } from './rockets/rockets'; | ||
|
||
const reducer = combineReducers({ | ||
rocketReducer, | ||
}); | ||
|
||
const elementStore = createStore(reducer, applyMiddleware(thunk, logger)); | ||
elementStore.dispatch(fetchRocketsAPI()); | ||
|
||
export default elementStore; |
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,56 @@ | ||
const ADD_RESERVATION = 'space-travelers/rockets/ADD_ROCKET_RESERVATION'; | ||
const REMOVE_RESERVATION = 'space-travelers/rockets/REMOVE__ROCKET_RESERVATION'; | ||
const GET_ROCKETS = 'space-travelers/rockets/GET_ROCKETS'; | ||
const baseURL = 'https://api.spacexdata.com/v3/rockets'; | ||
|
||
const initialState = []; | ||
|
||
export const addRocketReservation = (payload) => ({ | ||
type: ADD_RESERVATION, | ||
payload, | ||
}); | ||
|
||
export const removeRocketReservation = (payload) => ({ | ||
type: REMOVE_RESERVATION, | ||
payload, | ||
}); | ||
|
||
export const getRockets = (payload) => ({ | ||
type: GET_ROCKETS, | ||
payload, | ||
}); | ||
|
||
export const fetchRocketsAPI = () => async (dispatch) => { | ||
await fetch(`${baseURL}`) | ||
.then((response) => response.json()) | ||
.then((rocketList) => { | ||
console.log('rocketList: ', rocketList); | ||
|
||
const arrangedList = rocketList.map((rocket) => ({ | ||
id: rocket.rocket_id, | ||
name: rocket.rocket_name, | ||
type: rocket.rocket_type, | ||
flickr_images: rocket.flickr_images, | ||
reservation: false, | ||
})); | ||
if (arrangedList) { | ||
dispatch(getRockets(arrangedList)); | ||
} | ||
}); | ||
}; | ||
|
||
// reducer | ||
const reducer = (state = initialState, action) => { | ||
switch (action.type) { | ||
case ADD_RESERVATION: | ||
return [...state, action.payload]; | ||
case REMOVE_RESERVATION: | ||
return state.filter((book) => book.item_id !== action.payload); | ||
case GET_ROCKETS: | ||
return [...action.payload]; | ||
default: | ||
return state; | ||
} | ||
}; | ||
|
||
export default reducer; |