Showing
10 changed files
with
162 additions
and
60 deletions
... | @@ -12,8 +12,11 @@ | ... | @@ -12,8 +12,11 @@ |
12 | "node-sass": "4", | 12 | "node-sass": "4", |
13 | "react": "^17.0.1", | 13 | "react": "^17.0.1", |
14 | "react-dom": "^17.0.1", | 14 | "react-dom": "^17.0.1", |
15 | + "react-redux": "^7.2.2", | ||
15 | "react-router-dom": "^5.2.0", | 16 | "react-router-dom": "^5.2.0", |
16 | "react-scripts": "4.0.0", | 17 | "react-scripts": "4.0.0", |
18 | + "redux": "^4.0.5", | ||
19 | + "redux-devtools-extension": "^2.13.8", | ||
17 | "sass-loader": "^10.1.0", | 20 | "sass-loader": "^10.1.0", |
18 | "styled-components": "^5.2.1", | 21 | "styled-components": "^5.2.1", |
19 | "swiper": "^6.3.5", | 22 | "swiper": "^6.3.5", |
... | @@ -31,6 +34,7 @@ | ... | @@ -31,6 +34,7 @@ |
31 | "react-app/jest" | 34 | "react-app/jest" |
32 | ] | 35 | ] |
33 | }, | 36 | }, |
37 | + "proxy": "http://localhost:8000", | ||
34 | "browserslist": { | 38 | "browserslist": { |
35 | "production": [ | 39 | "production": [ |
36 | ">0.2%", | 40 | ">0.2%", | ... | ... |
1 | import "./App.scss"; | 1 | import "./App.scss"; |
2 | import MainPage from "./pages/MainPage"; | 2 | import MainPage from "./pages/MainPage"; |
3 | import SurveyPage from "./pages/SurveyPage"; | 3 | import SurveyPage from "./pages/SurveyPage"; |
4 | +import ResultPage from "./pages/ResultPage"; | ||
4 | import { BrowserRouter, Route, Switch } from "react-router-dom"; | 5 | import { BrowserRouter, Route, Switch } from "react-router-dom"; |
5 | 6 | ||
6 | function App() { | 7 | function App() { |
... | @@ -10,6 +11,7 @@ function App() { | ... | @@ -10,6 +11,7 @@ function App() { |
10 | <Switch> | 11 | <Switch> |
11 | <Route exact path="/" component={MainPage} /> | 12 | <Route exact path="/" component={MainPage} /> |
12 | <Route path="/survey" component={SurveyPage} /> | 13 | <Route path="/survey" component={SurveyPage} /> |
14 | + <Route path="/result" component={ResultPage} /> | ||
13 | </Switch> | 15 | </Switch> |
14 | </div> | 16 | </div> |
15 | </BrowserRouter> | 17 | </BrowserRouter> | ... | ... |
1 | import React from 'react'; | 1 | import React from 'react'; |
2 | import './Card.scss'; | 2 | import './Card.scss'; |
3 | 3 | ||
4 | -function Card({data,answer,onClick1,onClick2}){ | 4 | +function Card({question,answer,setAnswer,curIdx,setCurIdx}){ |
5 | // type: true false | 5 | // type: true false |
6 | + const onClickOne=()=>{ | ||
7 | + const temp = [ | ||
8 | + ...answer,{ | ||
9 | + num: question.num, | ||
10 | + choice: 0 | ||
11 | + }]; | ||
12 | + setAnswer(temp); | ||
13 | + setCurIdx(curIdx+1); | ||
14 | + } | ||
15 | + const onClickTwo=()=>{ | ||
16 | + const temp = [ | ||
17 | + ...answer,{ | ||
18 | + num: question.num, | ||
19 | + choice: 1 | ||
20 | + }]; | ||
21 | + setAnswer(temp); | ||
22 | + setCurIdx(curIdx+1); | ||
23 | + } | ||
6 | return( | 24 | return( |
7 | <> | 25 | <> |
8 | <div className="card"> | 26 | <div className="card"> |
9 | - <div className="card__desc">{data.question}</div> | 27 | + <div className="card__desc">{question.question}</div> |
10 | - <div className="card__content" onClick={onClick1}>{data.answer1}</div> | 28 | + <div className="card__content" onClick={onClickOne}>{question.answer1}</div> |
11 | - <div className="card__content" onClick={onClick2}>{data.answer2}</div> | 29 | + <div className="card__content" onClick={onClickTwo}>{question.answer2}</div> |
12 | </div> | 30 | </div> |
13 | </> | 31 | </> |
14 | ); | 32 | ); | ... | ... |
... | @@ -5,10 +5,20 @@ import App from './App'; | ... | @@ -5,10 +5,20 @@ import App from './App'; |
5 | import reportWebVitals from './reportWebVitals'; | 5 | import reportWebVitals from './reportWebVitals'; |
6 | import 'antd/dist/antd.css' | 6 | import 'antd/dist/antd.css' |
7 | 7 | ||
8 | +// import redux | ||
9 | +import {Provider} from "react-redux"; | ||
10 | +import {createStore} from "redux"; | ||
11 | +import rootReducer from "./store/index"; | ||
12 | +import {composeWithDevTools} from "redux-devtools-extension"; | ||
13 | + | ||
14 | +const store = createStore(rootReducer,composeWithDevTools); | ||
15 | + | ||
8 | ReactDOM.render( | 16 | ReactDOM.render( |
9 | - <React.StrictMode> | 17 | + <Provider store={store}> |
10 | - <App /> | 18 | + <React.StrictMode> |
11 | - </React.StrictMode>, | 19 | + <App /> |
20 | + </React.StrictMode> | ||
21 | + </Provider>, | ||
12 | document.getElementById('root') | 22 | document.getElementById('root') |
13 | ); | 23 | ); |
14 | reportWebVitals(); | 24 | reportWebVitals(); | ... | ... |
src/pages/ResultPage.js
0 → 100644
src/pages/ResultPage.scss
0 → 100644
File mode changed
... | @@ -4,75 +4,49 @@ import ProgressBar from "../components/progressbar/ProgressBar"; | ... | @@ -4,75 +4,49 @@ import ProgressBar from "../components/progressbar/ProgressBar"; |
4 | import axios from 'axios'; | 4 | import axios from 'axios'; |
5 | import "./SurveyPage.scss"; | 5 | import "./SurveyPage.scss"; |
6 | 6 | ||
7 | -// const cardList = [ | 7 | +function SurveyPage({history}) { |
8 | -// { | ||
9 | -// index: 0, | ||
10 | -// desc: "나는 오랫동안 서 있을 수 있다.", | ||
11 | -// ans1: "그렇습니다.", | ||
12 | -// ans2: "아닙니다.", | ||
13 | -// }, | ||
14 | -// { | ||
15 | -// index: 1, | ||
16 | -// desc: "배경호는 오랫동안 서 있을 수 있다.", | ||
17 | -// ans1: "그렇습니다.", | ||
18 | -// ans2: "아닙니다.", | ||
19 | -// }, | ||
20 | -// { | ||
21 | -// index: 2, | ||
22 | -// desc: "이준호는 오랫동안 서 있을 수 있다.", | ||
23 | -// ans1: "그렇습니다.", | ||
24 | -// ans2: "아닙니다.", | ||
25 | -// }, | ||
26 | -// { | ||
27 | -// index: 3, | ||
28 | -// desc: "박기홍은 오랫동안 서 있을 수 있다.", | ||
29 | -// ans1: "그렇습니다.", | ||
30 | -// ans2: "아닙니다.", | ||
31 | -// }, | ||
32 | -// ]; | ||
33 | - | ||
34 | -function SurveyPage() { | ||
35 | const [curIdx, setCurIdx] = useState(0); | 8 | const [curIdx, setCurIdx] = useState(0); |
36 | const [question, setQuestion] = useState([]); | 9 | const [question, setQuestion] = useState([]); |
37 | - const [answer, serAnswer] = useState([]); | 10 | + const [answer, setAnswer] = useState([]); |
38 | - | 11 | + const [respond, setRespond] = useState([]); |
39 | - // const clickAns1 = (e) =>{ | ||
40 | - // setCurIdx(curIdx+1); | ||
41 | - // const temp | ||
42 | - // } | ||
43 | - // const clickAns2 = (e) =>{ | ||
44 | - // setCurIdx(curIdx+1); | ||
45 | - // } | ||
46 | 12 | ||
47 | useEffect(()=>{ | 13 | useEffect(()=>{ |
48 | const getApi = async() =>{ | 14 | const getApi = async() =>{ |
49 | - const apis = axios.create({ | 15 | + const {data} = await axios.get("getquestions"); |
50 | - baseURL: "", | 16 | + setQuestion(data); |
51 | - withCredentials: true | 17 | + // console.log(question); |
52 | - }); | ||
53 | - const result = await apis.get("http://192.168.0.16:8000/getquestions"); | ||
54 | - console.log(result); | ||
55 | - return result; | ||
56 | } | 18 | } |
57 | - const data = getApi(); | 19 | + getApi(); |
58 | - // setQuestion(data); | ||
59 | - // console.log(data); | ||
60 | },[]); | 20 | },[]); |
61 | 21 | ||
22 | + useEffect(()=>{ | ||
23 | + if(curIdx === 10){ | ||
24 | + const postApi = async ()=>{ | ||
25 | + const {data} = await axios.post("submit", answer); | ||
26 | + console.log(data); | ||
27 | + setRespond(data); | ||
28 | + | ||
29 | + } | ||
30 | + postApi(); | ||
31 | + history.push('/result'); | ||
32 | + } | ||
33 | + },[curIdx]); | ||
34 | + | ||
62 | return ( | 35 | return ( |
63 | <div className="container"> | 36 | <div className="container"> |
64 | <div className="container__progress"> | 37 | <div className="container__progress"> |
65 | <ProgressBar percent={curIdx*10} /> | 38 | <ProgressBar percent={curIdx*10} /> |
66 | </div> | 39 | </div> |
67 | <div className="slider"> | 40 | <div className="slider"> |
68 | - {question && question.map((data,index) => ( | 41 | + {question && question.map((question,index) => ( |
69 | <div className="slider__wrapper"> | 42 | <div className="slider__wrapper"> |
70 | <Card | 43 | <Card |
71 | - key={data.num} | 44 | + key={question.num} |
72 | - data={data} | 45 | + question={question} |
73 | - // onClick1={clickAns1} | ||
74 | - // onClick2={clickAns2} | ||
75 | answer={answer} | 46 | answer={answer} |
47 | + setAnswer={setAnswer} | ||
48 | + curIdx={curIdx} | ||
49 | + setCurIdx={setCurIdx} | ||
76 | style={{ | 50 | style={{ |
77 | transform: `translateX(${(-30)*curIdx}rem)`, | 51 | transform: `translateX(${(-30)*curIdx}rem)`, |
78 | transition: "0.5s", | 52 | transition: "0.5s", | ... | ... |
src/store/action/result.js
0 → 100644
1 | +// action | ||
2 | +const GET_RESULT = 'GET_RESULT'; | ||
3 | +const GET_RESULT_SUCCESS = 'GET_RESULT_SUCCESS'; | ||
4 | +const GET_RESULT_ERROR = 'GET_RESULT_ERROR'; | ||
5 | + | ||
6 | +// action creators | ||
7 | +export const getResult = () => ({type:GET_RESULT}); | ||
8 | +export const getResultSuccess = (data) => ({type: GET_RESULT_SUCCESS,payload: data}); | ||
9 | +export const getResultError = (e) => ({type: GET_RESULT_ERROR, payload: e}); | ||
10 | + | ||
11 | +const initialState = { | ||
12 | + loading: true, | ||
13 | + data: null, | ||
14 | + error: null | ||
15 | +} | ||
16 | + | ||
17 | +function result( | ||
18 | + state = initialState, | ||
19 | + action | ||
20 | +){ | ||
21 | + switch(action.type){ | ||
22 | + case GET_RESULT: { | ||
23 | + return{ | ||
24 | + loading: true, | ||
25 | + data: null, | ||
26 | + error: null | ||
27 | + } | ||
28 | + } | ||
29 | + case GET_RESULT_SUCCESS:{ | ||
30 | + return{ | ||
31 | + loading: false, | ||
32 | + data: action.payload, | ||
33 | + error: null | ||
34 | + } | ||
35 | + } | ||
36 | + case GET_RESULT_ERROR:{ | ||
37 | + return{ | ||
38 | + loading: false, | ||
39 | + data: null, | ||
40 | + error: action.payload | ||
41 | + } | ||
42 | + } | ||
43 | + } | ||
44 | +} | ||
45 | + | ||
46 | +export default result; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
src/store/index.js
0 → 100644
... | @@ -9986,7 +9986,7 @@ react-error-overlay@^6.0.8: | ... | @@ -9986,7 +9986,7 @@ react-error-overlay@^6.0.8: |
9986 | resolved "https://registry.yarnpkg.com/react-error-overlay/-/react-error-overlay-6.0.8.tgz#474ed11d04fc6bda3af643447d85e9127ed6b5de" | 9986 | resolved "https://registry.yarnpkg.com/react-error-overlay/-/react-error-overlay-6.0.8.tgz#474ed11d04fc6bda3af643447d85e9127ed6b5de" |
9987 | integrity sha512-HvPuUQnLp5H7TouGq3kzBeioJmXms1wHy9EGjz2OURWBp4qZO6AfGEcnxts1D/CbwPLRAgTMPCEgYhA3sEM4vw== | 9987 | integrity sha512-HvPuUQnLp5H7TouGq3kzBeioJmXms1wHy9EGjz2OURWBp4qZO6AfGEcnxts1D/CbwPLRAgTMPCEgYhA3sEM4vw== |
9988 | 9988 | ||
9989 | -react-is@^16.12.0, react-is@^16.6.0, react-is@^16.7.0, react-is@^16.8.1: | 9989 | +react-is@^16.12.0, react-is@^16.13.1, react-is@^16.6.0, react-is@^16.7.0, react-is@^16.8.1: |
9990 | version "16.13.1" | 9990 | version "16.13.1" |
9991 | resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4" | 9991 | resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4" |
9992 | integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ== | 9992 | integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ== |
... | @@ -10001,6 +10001,17 @@ react-lifecycles-compat@^3.0.4: | ... | @@ -10001,6 +10001,17 @@ react-lifecycles-compat@^3.0.4: |
10001 | resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362" | 10001 | resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362" |
10002 | integrity sha512-fBASbA6LnOU9dOU2eW7aQ8xmYBSXUIWr+UmF9b1efZBazGNO+rcXT/icdKnYm2pTwcRylVUYwW7H1PHfLekVzA== | 10002 | integrity sha512-fBASbA6LnOU9dOU2eW7aQ8xmYBSXUIWr+UmF9b1efZBazGNO+rcXT/icdKnYm2pTwcRylVUYwW7H1PHfLekVzA== |
10003 | 10003 | ||
10004 | +react-redux@^7.2.2: | ||
10005 | + version "7.2.2" | ||
10006 | + resolved "https://registry.yarnpkg.com/react-redux/-/react-redux-7.2.2.tgz#03862e803a30b6b9ef8582dadcc810947f74b736" | ||
10007 | + integrity sha512-8+CQ1EvIVFkYL/vu6Olo7JFLWop1qRUeb46sGtIMDCSpgwPQq8fPLpirIB0iTqFe9XYEFPHssdX8/UwN6pAkEA== | ||
10008 | + dependencies: | ||
10009 | + "@babel/runtime" "^7.12.1" | ||
10010 | + hoist-non-react-statics "^3.3.2" | ||
10011 | + loose-envify "^1.4.0" | ||
10012 | + prop-types "^15.7.2" | ||
10013 | + react-is "^16.13.1" | ||
10014 | + | ||
10004 | react-refresh@^0.8.3: | 10015 | react-refresh@^0.8.3: |
10005 | version "0.8.3" | 10016 | version "0.8.3" |
10006 | resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.8.3.tgz#721d4657672d400c5e3c75d063c4a85fb2d5d68f" | 10017 | resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.8.3.tgz#721d4657672d400c5e3c75d063c4a85fb2d5d68f" |
... | @@ -10222,6 +10233,19 @@ redent@^3.0.0: | ... | @@ -10222,6 +10233,19 @@ redent@^3.0.0: |
10222 | indent-string "^4.0.0" | 10233 | indent-string "^4.0.0" |
10223 | strip-indent "^3.0.0" | 10234 | strip-indent "^3.0.0" |
10224 | 10235 | ||
10236 | +redux-devtools-extension@^2.13.8: | ||
10237 | + version "2.13.8" | ||
10238 | + resolved "https://registry.yarnpkg.com/redux-devtools-extension/-/redux-devtools-extension-2.13.8.tgz#37b982688626e5e4993ff87220c9bbb7cd2d96e1" | ||
10239 | + integrity sha512-8qlpooP2QqPtZHQZRhx3x3OP5skEV1py/zUdMY28WNAocbafxdG2tRD1MWE7sp8obGMNYuLWanhhQ7EQvT1FBg== | ||
10240 | + | ||
10241 | +redux@^4.0.5: | ||
10242 | + version "4.0.5" | ||
10243 | + resolved "https://registry.yarnpkg.com/redux/-/redux-4.0.5.tgz#4db5de5816e17891de8a80c424232d06f051d93f" | ||
10244 | + integrity sha512-VSz1uMAH24DM6MF72vcojpYPtrTUu3ByVWfPL1nPfVRb5mZVTve5GnNCUV53QM/BZ66xfWrm0CTWoM+Xlz8V1w== | ||
10245 | + dependencies: | ||
10246 | + loose-envify "^1.4.0" | ||
10247 | + symbol-observable "^1.2.0" | ||
10248 | + | ||
10225 | regenerate-unicode-properties@^8.2.0: | 10249 | regenerate-unicode-properties@^8.2.0: |
10226 | version "8.2.0" | 10250 | version "8.2.0" |
10227 | resolved "https://registry.yarnpkg.com/regenerate-unicode-properties/-/regenerate-unicode-properties-8.2.0.tgz#e5de7111d655e7ba60c057dbe9ff37c87e65cdec" | 10251 | resolved "https://registry.yarnpkg.com/regenerate-unicode-properties/-/regenerate-unicode-properties-8.2.0.tgz#e5de7111d655e7ba60c057dbe9ff37c87e65cdec" |
... | @@ -11554,6 +11578,11 @@ swiper@^6.3.5: | ... | @@ -11554,6 +11578,11 @@ swiper@^6.3.5: |
11554 | dom7 "^3.0.0-alpha.7" | 11578 | dom7 "^3.0.0-alpha.7" |
11555 | ssr-window "^3.0.0-alpha.4" | 11579 | ssr-window "^3.0.0-alpha.4" |
11556 | 11580 | ||
11581 | +symbol-observable@^1.2.0: | ||
11582 | + version "1.2.0" | ||
11583 | + resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-1.2.0.tgz#c22688aed4eab3cdc2dfeacbb561660560a00804" | ||
11584 | + integrity sha512-e900nM8RRtGhlV36KGEU9k65K3mPb1WV70OdjfxlG2EAuM1noi/E/BaW/uMhL7bPEssK8QV57vN3esixjUvcXQ== | ||
11585 | + | ||
11557 | symbol-tree@^3.2.4: | 11586 | symbol-tree@^3.2.4: |
11558 | version "3.2.4" | 11587 | version "3.2.4" |
11559 | resolved "https://registry.yarnpkg.com/symbol-tree/-/symbol-tree-3.2.4.tgz#430637d248ba77e078883951fb9aa0eed7c63fa2" | 11588 | resolved "https://registry.yarnpkg.com/symbol-tree/-/symbol-tree-3.2.4.tgz#430637d248ba77e078883951fb9aa0eed7c63fa2" | ... | ... |
-
Please register or login to post a comment