Skip to content

Commit

Permalink
Merge pull request #22 from Youngseo-kangg/feature/redux
Browse files Browse the repository at this point in the history
[Client] #1 Feature/redux : redux ๊ธฐ๋ณธ ์„ธํŒ… ๋ฐ ๊ธฐ์ดˆ ์ž‘์„ฑ
  • Loading branch information
minjman2659 authored Sep 10, 2021
2 parents 3723493 + 738b66c commit 65741eb
Show file tree
Hide file tree
Showing 32 changed files with 618 additions and 426 deletions.
2 changes: 2 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"dotenv": "^10.0.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-redux": "^7.2.5",
"react-scripts": "4.0.3",
"redux": "^4.1.1",
"web-vitals": "^1.0.1"
},
"scripts": {
Expand Down
43 changes: 43 additions & 0 deletions client/src/actions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// ์–ด๋–ค ํ–‰๋™์„ ํ• ์ง€ ์ •์˜ํ•ด ๋‘˜ actions
export const SET_LOGIN_STATE = 'SET_LOGIN_STATE'; // ๋กœ๊ทธ์ธ ์ƒํƒœ ๋ณ€๊ฒฝ(=๋กœ๊ทธ์ธ)
export const SET_LOGOUT_STATE = 'SET_LOGOUT_STATE'; // ๋กœ๊ทธ์•„์›ƒ ์ƒํƒœ ๋ณ€๊ฒฝ
export const EDIT_USERINFO = 'EDIT_USERINFO'; // ์œ ์ € ์ •๋ณด(=์ด๋ฆ„, ๋น„๋ฐ€๋ฒˆํ˜ธ, ์‚ฌ์ง„) ๋ณ€๊ฒฝํ•˜๊ธฐ
export const SET_MODAL_LOGINORSIGNUP = 'SET_MODAL_LOGINORSIGNUP'; // ๋กœ๊ทธ์ธorํšŒ์›๊ฐ€์ž… ๋ชจ๋‹ฌ ์ƒํƒœ
export const SET_MODAL_QUIZ = 'SET_MODAL_QUIZ'; // ํ€ด์ฆˆ ๋ชจ๋‹ฌ ์ƒํƒœ
export const SET_MODAL_SIGNOUT = 'SET_MODAL_SIGNOUT'; // ํšŒ์›ํƒˆํ‡ด ๋ชจ๋‹ฌ ์ƒํƒœ
export const SET_MODAL_LOGOUT = 'SET_MODAL_LOGOUT'; // ๋กœ๊ทธ์•„์›ƒ ๋ชจ๋‹ฌ ์ƒํƒœ
export const SET_MODAL_CHART = 'SET_MODAL_CHART'; // ์ฐจํŠธ ๋ชจ๋‹ฌ ์ƒํƒœ

export const SET_USER_CONTENT = 'SET_USER_CONTENT'; // ์œ ์ €๊ฐ€ ์“ด ๊ธ€ ๋ฐ›์•„์˜ค๊ธฐ
export const DELETE_CONTENT = 'DELETE_CONTENT'; // ์œ ์ €๊ฐ€ ์“ด ๊ธ€ ์‚ญ์ œ
export const EDIT_CONTENT = 'EDIT_CONTENT'; // ์œ ์ €๊ฐ€ ์“ด ๊ธ€ ์ˆ˜์ •

export const setLogin = (userData, isLogin) => {
return {
type: SET_LOGIN_STATE,
userData,
isLogin,
};
};

export const getContent = (userContent) => {
return {
type: SET_USER_CONTENT,
userContent,
};
};

export const deleteContent = (contentId) => {
return {
type: DELETE_CONTENT,
contentId,
};
};

export const editContent = (contentId, wordMean) => {
return {
type: EDIT_CONTENT,
contentId,
wordMean,
};
};
1 change: 1 addition & 0 deletions client/src/components/BestSearch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Chart ์•ˆ์— ์‹ค์‹œ๊ฐ„ ์ˆœ์œ„ ๊ทธ๋ž˜ํ”„ ๋ณด์—ฌ์งˆ ๋ถ€๋ถ„
1 change: 1 addition & 0 deletions client/src/components/Chart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// ์‹ค์‹œ๊ฐ„ ์ˆœ์œ„ ๋ณด์—ฌ์งˆ ๋ถ€๋ถ„
1 change: 1 addition & 0 deletions client/src/components/EditUserInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// EditMyPage์—์„œ ์œ ์ € ์ •๋ณด ๋ณ€๊ฒฝํ•˜๋Š” ๋ถ€๋ถ„
1 change: 1 addition & 0 deletions client/src/components/EditUserPic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// EditMyPage์—์„œ ์‚ฌ์ง„ ๋ณ€๊ฒฝ ์ผ์–ด๋‚˜๋Š” ๋ถ€๋ถ„
1 change: 1 addition & 0 deletions client/src/components/LandingQuiz.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// ๋žœ๋”ฉํŽ˜์ด์ง€์—์„œ ๋ง›๋ณด๊ธฐ๋กœ ์ œ๊ณต๋  ํ€ด์ฆˆ
1 change: 1 addition & 0 deletions client/src/components/Search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// ๋ฉ”์ธํŽ˜์ด์ง€์—์„œ ์ž…๋ ฅ์ฐฝ, ์ž…๋ ฅ์ฐฝ ์ž๋™์™„์„ฑ, ๊ณผ๊ฑฐ ๊ฒ€์ƒ‰๊ธฐ๋ก, ๊ฒ€์ƒ‰๊ฒฐ๊ณผ ๋ณด์—ฌ์งˆ ๋ถ€๋ถ„
1 change: 1 addition & 0 deletions client/src/components/SearchAutoComp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Search์—์„œ ์ž๋™์™„์„ฑ ์ฐฝ
1 change: 1 addition & 0 deletions client/src/components/SearchHistory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// ๊ณผ๊ฑฐ ๊ฒ€์ƒ‰๊ฒฐ๊ณผ ๋ณด๊ด€
1 change: 1 addition & 0 deletions client/src/components/SearchInput.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Search์—์„œ ๊ฒ€์ƒ‰์ฐฝ ๋ถ€๋ถ„
1 change: 1 addition & 0 deletions client/src/components/SearchResult.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Search์—์„œ ๊ฒ€์ƒ‰ ํ›„ ์ข‹์•„์š” ์ˆœ์œผ๋กœ 3๊ฐœ๋งŒ ๋ณด์—ฌ์ง€๋Š” ๋ถ€๋ถ„
1 change: 1 addition & 0 deletions client/src/components/UserContents.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Mypage์—์„œ ์œ ์ €๊ฐ€ ์“ด ๊ธ€ ๋ชฉ๋ก
1 change: 1 addition & 0 deletions client/src/components/UserInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Mypage ์•ˆ์—์„œ ์œ ์ € ์ •๋ณด ๋‚˜ํƒ€๋‚  ๋ถ€๋ถ„
1 change: 1 addition & 0 deletions client/src/modals/ChartModal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// ์‹ค์‹œ๊ฐ„ ์ˆœ์œ„ ๊ทธ๋ž˜ํ”„ ๋‚˜ํƒ€๋‚  ๋ชจ๋‹ฌ
1 change: 1 addition & 0 deletions client/src/modals/EditContent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// ์‚ฌ์šฉ์ž๊ฐ€ ์“ด ๊ธ€ ์ˆ˜์ •ํ•˜๋Š” ๋ชจ๋‹ฌ
1 change: 1 addition & 0 deletions client/src/modals/LoginOrSignUp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// ๋กœ๊ทธ์ธ / ํšŒ์›๊ฐ€์ž… ๋ชจ๋‹ฌ
1 change: 1 addition & 0 deletions client/src/modals/Logout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// ๋กœ๊ทธ์•„์›ƒ ๋ชจ๋‹ฌ
1 change: 1 addition & 0 deletions client/src/modals/NewContent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// ์‚ฌ์šฉ์ž๊ฐ€ ์ƒˆ๋กœ์šด ๊ธ€์„ ์“ฐ๋Š” ๋ชจ๋‹ฌ
1 change: 1 addition & 0 deletions client/src/modals/Quiz.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// ์˜ค๋Š˜์˜ ํ€ด์ฆˆ ๋ถ€๋ถ„
1 change: 1 addition & 0 deletions client/src/modals/SignOut.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// ํšŒ์› ํƒˆํ‡ด ๋ชจ๋‹ฌ
1 change: 1 addition & 0 deletions client/src/pages/EditMyPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// ๊ฐœ์ธ์ •๋ณด ๋ณ€๊ฒฝ ํŽ˜์ด์ง€
1 change: 1 addition & 0 deletions client/src/pages/Footer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// footer ๋ถ€๋ถ„
1 change: 1 addition & 0 deletions client/src/pages/Main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// main ํŽ˜์ด์ง€ (๊ฒ€์ƒ‰ ๋ฐ ๊ฒ€์ƒ‰๊ฒฐ๊ณผ ๋ณด๊ธฐ ํŽ˜์ด์ง€)
1 change: 1 addition & 0 deletions client/src/pages/Mypage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// ๊ฐœ์ธ์ •๋ณด ํ™•์ธ ๋ฐ ์ž‘์„ฑํ•œ ๊ธ€ ๋ณด์ด๋Š” ํŽ˜์ด์ง€
1 change: 1 addition & 0 deletions client/src/pages/Navbar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Navbar ๋ถ€๋ถ„
1 change: 1 addition & 0 deletions client/src/pages/SearchMore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// ๊ฒ€์ƒ‰๊ฒฐ๊ณผ ์ „์ฒด ๋ณด์—ฌ์ง€๋Š” ํŽ˜์ด์ง€
11 changes: 11 additions & 0 deletions client/src/reducers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// reducer๋“ค์„ ํ•œ๋ฒˆ์— ์ •๋ฆฌ
import { combineReducers } from 'redux';
import userInfoReducer from './userInfoReducer';
import userContentReducer from './userContentReducer';

const rootReducer = combineReducers({
userInfoReducer,
userContentReducer,
});

export default rootReducer;
39 changes: 39 additions & 0 deletions client/src/reducers/userContentReducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// ์œ ์ €๊ฐ€ ์“ด ๊ธ€ ๊ด€๋ฆฌ reducer
// ๊ธฐ๋ณธ๊ฐ’: ์œ ์ €๊ฐ€ ์ž‘์„ฑํ•œ ๊ธ€
// ๊ธฐ๋Šฅ : ์œ ์ €๊ฐ€ ์“ด ๊ธ€ ๋ฐ›์•„์˜ค๊ธฐ, ์œ ์ €๊ฐ€ ์“ด ๊ธ€ ์‚ญ์ œ, ์œ ์ €๊ฐ€ ์“ด ๊ธ€ ์ˆ˜์ •

import {
SET_USER_CONTENT,
DELETE_CONTENT,
EDIT_CONTENT,
} from '../actions/index';

const defaultUserContentInfo = {
data: [],
};

const userContentReducer = (state = defaultUserContentInfo, action) => {
switch (action.type) {
case SET_USER_CONTENT: // ์œ ์ €๊ฐ€ ์“ด ๊ธ€ ๋‹ค ๋ฐ›์•„์˜ค๊ธฐ
return { ...action.payload };

case DELETE_CONTENT: // ์œ ์ €๊ฐ€ ์“ด ๊ธ€ ์ œ๊ฑฐํ•˜๋Š” reducer, payload๋กœ contentId ๋“ค์–ด์˜ด
let saveContents = state.data.filter(
(ele) => ele.id !== action.payload.contentId
);
return Object.assign({}, { data: [...saveContents] });

case EDIT_CONTENT:
let editData = state.data.filter(
(ele) => ele.id === action.payload.contentId
);
editData.wordMean = action.payload.wordMean;
return Object.assign({}, { data: [...state.data] });

default:
// ๊ธฐ๋ณธ reducer
return state;
}
};

export default userContentReducer;
41 changes: 41 additions & 0 deletions client/src/reducers/userInfoReducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// ์œ ์ €์˜ ๊ฐœ์ธ์ •๋ณด ๋ฐ ๋ชจ๋‹ฌ ๋‹ซ/์—ด๋ฆผ ์ƒํƒœ ๊ด€๋ฆฌ reducer
// ๊ธฐ๋ณธ๊ฐ’: ๊ฐœ์ธ ์ •๋ณด (username, email, userPic, exp), ๋กœ๊ทธ์ธ ์ƒํƒœ, ๋ชจ๋‹ฌ ์ƒํƒœ(๋กœ๊ทธ์ธ, ๋กœ๊ทธ์•„์›ƒ, โ€ฆ)
// ๊ธฐ๋Šฅ : ๋กœ๊ทธ์ธํ•˜๊ธฐ, ์œ ์ € ์ด๋ฆ„/๋น„๋ฐ€๋ฒˆํ˜ธ/์‚ฌ์ง„ ๋ณ€๊ฒฝ, ๋ชจ๋‹ฌ ์ผœ๊ธฐ/๋„๊ธฐ, ๋กœ๊ทธ์•„์›ƒํ•˜๊ธฐ, ํšŒ์› ํƒˆํ‡ดํ•˜๊ธฐ

import { SET_LOGIN_STATE, SET_LOGOUT_STATE } from '../actions/index';

const defaultUserInfo = {
userInfo: {
id: -1,
email: '',
username: '',
userPic: null,
exp: 0,
}, // ๊ธฐ๋ณธ ์œ ์ € ์ •๋ณด
isLogin: false, //๋กœ๊ทธ์ธ ์ƒํƒœ
isShowLoginOrSignupModal: false, // ๋กœ๊ทธ์ธorํšŒ์›๊ฐ€์ž… ๋ชจ๋‹ฌ ์ƒํƒœ
isShowQuizModal: false, // ํ€ด์ฆˆ ๋ชจ๋‹ฌ ์ƒํƒœ
isShowSignoutModal: false, // ํšŒ์›ํƒˆํ‡ด ๋ชจ๋‹ฌ ์ƒํƒœ
isShowLogoutModal: false, // ๋กœ๊ทธ์•„์›ƒ ๋ชจ๋‹ฌ ์ƒํƒœ
isShowChartModal: false, // ์ฐจํŠธ ๋ชจ๋‹ฌ ์ƒํƒœ
};

const userInfoReducer = (state = defaultUserInfo, action) => {
switch (action.type) {
case SET_LOGIN_STATE: // ๋กœ๊ทธ์ธ reducer
return {
...state,
userInfo: action.userData,
isLogin: action.isLogin,
};
case SET_LOGOUT_STATE: // ๋กœ๊ทธ์•„์›ƒ reducer
return {
...defaultUserInfo,
};
default:
// ๊ธฐ๋ณธ reducer
return state;
}
};

export default userInfoReducer;
14 changes: 14 additions & 0 deletions client/src/store/store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// react-redux์—์„œ ์ƒํƒœ๋“ค์„ ๊ฐ–๊ณ ์žˆ์„ store
import { compose, createStore, applyMiddleware } from 'redux';
import rootReducer from '../reducers/index';
import thunk from 'redux-thunk';

const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({})
: compose;
const store = createStore(
rootReducer,
composeEnhancers(applyMiddleware(thunk))
);

export default store;
Loading

0 comments on commit 65741eb

Please sign in to comment.