Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create basic structure rockets Setup #28

Merged
merged 7 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
79 changes: 78 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
"prop-types": "^15.8.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-redux": "^7.2.6",
"react-router-dom": "^6.2.2",
"react-scripts": "5.0.0",
"redux": "^4.1.2",
"redux-logger": "^3.0.6",
"styled-components": "^5.3.3",
"web-vitals": "^2.1.4"
Expand Down
18 changes: 17 additions & 1 deletion src/components/Missions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
import React from 'react';
import { useDispatch } from 'react-redux';
import {
incrementedMission,
decrementedMission,
} from '../redux/missions/missions';

function Missions() {
return <div>Missions</div>;
const dispatch = useDispatch();
return (
<div>
Missions
<button type="button" onClick={() => dispatch(incrementedMission())}>
Click me!
</button>
<button type="button" onClick={() => dispatch(decrementedMission(2))}>
Click me!
</button>
</div>
);
}

export default Missions;
14 changes: 13 additions & 1 deletion src/components/Rockets.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
import React from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { incrementedRocket } from '../redux/rockets/rockets';
import { selectCountMission } from '../redux/missions/missions';

function Rockets() {
return <div>Rockets</div>;
const dispatch = useDispatch();
const count = useSelector(selectCountMission);
return (
<div>
Rocket
<button type="button" onClick={() => dispatch(incrementedRocket())}>
{`Click me! ${count}`}
</button>
</div>
);
}

export default Rockets;
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import './index.css';
import store from './redux/configureStore';
import App from './App';

ReactDOM.render(
<React.StrictMode>
<App />
<Provider store={store}>
<App />
</Provider>
</React.StrictMode>,
document.getElementById('root'),
);
14 changes: 14 additions & 0 deletions src/redux/configureStore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { configureStore } from '@reduxjs/toolkit';
import logger from 'redux-logger';
import reducerRockets from './rockets/rockets';
import reducerMissions from './missions/missions';

const store = configureStore({
reducer: {
missions: reducerMissions,
rockets: reducerRockets,
},
middleware: [logger],
});

export default store;
25 changes: 25 additions & 0 deletions src/redux/missions/missions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { createSlice } from '@reduxjs/toolkit';

const initialState = {
countMission: 0,
};

const missionsSlice = createSlice({
name: 'missions',
initialState,
reducers: {
incrementedMission: (state) => ({
...state,
countMission: state.countMission + 1,
}),
decrementedMission: (state, action) => ({
...state,
countMission: state.countMission - action.payload,
}),
},
});

export const { incrementedMission, decrementedMission } = missionsSlice.actions;
export const selectCountMission = (state) => state.missions.countMission;

export default missionsSlice.reducer;
19 changes: 19 additions & 0 deletions src/redux/rockets/rockets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { createSlice } from '@reduxjs/toolkit';

const rocketsSlice = createSlice({
name: 'rockets',
initialState: {
countRocket: 0,
},
reducers: {
incrementedRocket: (state) => ({
...state,
countRocket: state.countRocket + 1,
}),
},
});

export const { incrementedRocket } = rocketsSlice.actions;
export const selectCountRocket = (state) => state.rockets.countRocket;

export default rocketsSlice.reducer;