이준호

feat: 서버 통신 코드 작성

...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
8 "@testing-library/react": "^11.1.0", 8 "@testing-library/react": "^11.1.0",
9 "@testing-library/user-event": "^12.1.10", 9 "@testing-library/user-event": "^12.1.10",
10 "antd": "^4.8.2", 10 "antd": "^4.8.2",
11 + "axios": "^0.21.0",
11 "node-sass": "4", 12 "node-sass": "4",
12 "react": "^17.0.1", 13 "react": "^17.0.1",
13 "react-dom": "^17.0.1", 14 "react-dom": "^17.0.1",
......
...@@ -6,9 +6,9 @@ function Card({data,onClick}){ ...@@ -6,9 +6,9 @@ function Card({data,onClick}){
6 return( 6 return(
7 <> 7 <>
8 <div className="card" onClick={onClick}> 8 <div className="card" onClick={onClick}>
9 - <div className="card__desc">{data.desc}</div> 9 + <div className="card__desc">{data.question}</div>
10 - <div className="card__content">{data.ans1}</div> 10 + <div className="card__content">{data.answer1}</div>
11 - <div className="card__content">{data.ans2}</div> 11 + <div className="card__content">{data.answer2}</div>
12 </div> 12 </div>
13 </> 13 </>
14 ); 14 );
......
1 -import React, { useState, useRef } from "react"; 1 +import React, { useState, useEffect } from "react";
2 import Card from "../components/card/Card"; 2 import Card from "../components/card/Card";
3 import ProgressBar from "../components/progressbar/ProgressBar"; 3 import ProgressBar from "../components/progressbar/ProgressBar";
4 +import axios from 'axios';
4 import "./SurveyPage.scss"; 5 import "./SurveyPage.scss";
5 6
6 -const cardList = [ 7 +// const cardList = [
7 - { 8 +// {
8 - index: 0, 9 +// index: 0,
9 - desc: "나는 오랫동안 서 있을 수 있다.", 10 +// desc: "나는 오랫동안 서 있을 수 있다.",
10 - ans1: "그렇습니다.", 11 +// ans1: "그렇습니다.",
11 - ans2: "아닙니다.", 12 +// ans2: "아닙니다.",
12 - }, 13 +// },
13 - { 14 +// {
14 - index: 1, 15 +// index: 1,
15 - desc: "배경호는 오랫동안 서 있을 수 있다.", 16 +// desc: "배경호는 오랫동안 서 있을 수 있다.",
16 - ans1: "그렇습니다.", 17 +// ans1: "그렇습니다.",
17 - ans2: "아닙니다.", 18 +// ans2: "아닙니다.",
18 - }, 19 +// },
19 - { 20 +// {
20 - index: 2, 21 +// index: 2,
21 - desc: "이준호는 오랫동안 서 있을 수 있다.", 22 +// desc: "이준호는 오랫동안 서 있을 수 있다.",
22 - ans1: "그렇습니다.", 23 +// ans1: "그렇습니다.",
23 - ans2: "아닙니다.", 24 +// ans2: "아닙니다.",
24 - }, 25 +// },
25 - { 26 +// {
26 - index: 3, 27 +// index: 3,
27 - desc: "박기홍은 오랫동안 서 있을 수 있다.", 28 +// desc: "박기홍은 오랫동안 서 있을 수 있다.",
28 - ans1: "그렇습니다.", 29 +// ans1: "그렇습니다.",
29 - ans2: "아닙니다.", 30 +// ans2: "아닙니다.",
30 - }, 31 +// },
31 -]; 32 +// ];
32 33
33 function SurveyPage() { 34 function SurveyPage() {
34 const [curIdx, setCurIdx] = useState(0); 35 const [curIdx, setCurIdx] = useState(0);
35 - const clickToNext = (index) =>{ 36 + const [question, setQuestion] = useState([]);
37 + const clickToNext = () =>{
36 setCurIdx(curIdx+1); 38 setCurIdx(curIdx+1);
37 } 39 }
38 40
41 + useEffect(()=>{
42 + (async () => {
43 + try{
44 + const result = await axios.get("192.168.0.16:8000/getquestions");
45 + setQuestion(result);
46 + console.log(result);
47 + }catch(e){
48 + console.log("서버 통신 실패");
49 + }
50 + })();
51 + },[]);
52 +
39 return ( 53 return (
40 <div className="container"> 54 <div className="container">
41 <div className="container__progress"> 55 <div className="container__progress">
42 <ProgressBar percent={curIdx*10} /> 56 <ProgressBar percent={curIdx*10} />
43 </div> 57 </div>
44 <div className="slider"> 58 <div className="slider">
45 - {cardList.map((card) => ( 59 + {question && question.map((data,index) => (
46 <div className="slider__wrapper"> 60 <div className="slider__wrapper">
47 <Card 61 <Card
48 - data={card} 62 + key={data.num}
49 - onClick={()=>clickToNext(card.index)} 63 + data={data}
64 + onClick={clickToNext}
50 style={{ 65 style={{
51 - transform: `translateX(${-30*card.index}rem)`, 66 + transform: `translateX(${(-30)*curIdx}rem)`,
52 transition: "0.5s", 67 transition: "0.5s",
53 }} 68 }}
54 /> 69 />
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
18 border: 1px solid red; 18 border: 1px solid red;
19 width: 30rem; 19 width: 30rem;
20 } 20 }
21 -
22 &__desc{ 21 &__desc{
23 font-size: 2rem; 22 font-size: 2rem;
24 font-weight: bold; 23 font-weight: bold;
......
...@@ -2847,6 +2847,13 @@ axe-core@^4.0.2: ...@@ -2847,6 +2847,13 @@ axe-core@^4.0.2:
2847 resolved "https://registry.yarnpkg.com/axe-core/-/axe-core-4.0.2.tgz#c7cf7378378a51fcd272d3c09668002a4990b1cb" 2847 resolved "https://registry.yarnpkg.com/axe-core/-/axe-core-4.0.2.tgz#c7cf7378378a51fcd272d3c09668002a4990b1cb"
2848 integrity sha512-arU1h31OGFu+LPrOLGZ7nB45v940NMDMEJeNmbutu57P+UFDVnkZg3e+J1I2HJRZ9hT7gO8J91dn/PMrAiKakA== 2848 integrity sha512-arU1h31OGFu+LPrOLGZ7nB45v940NMDMEJeNmbutu57P+UFDVnkZg3e+J1I2HJRZ9hT7gO8J91dn/PMrAiKakA==
2849 2849
2850 +axios@^0.21.0:
2851 + version "0.21.0"
2852 + resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.0.tgz#26df088803a2350dff2c27f96fef99fe49442aca"
2853 + integrity sha512-fmkJBknJKoZwem3/IKSSLpkdNXZeBu5Q7GA/aRsr2btgrptmSCxi2oFjZHqGdK9DoTil9PIHlPIZw2EcRJXRvw==
2854 + dependencies:
2855 + follow-redirects "^1.10.0"
2856 +
2850 axobject-query@^2.2.0: 2857 axobject-query@^2.2.0:
2851 version "2.2.0" 2858 version "2.2.0"
2852 resolved "https://registry.yarnpkg.com/axobject-query/-/axobject-query-2.2.0.tgz#943d47e10c0b704aa42275e20edf3722648989be" 2859 resolved "https://registry.yarnpkg.com/axobject-query/-/axobject-query-2.2.0.tgz#943d47e10c0b704aa42275e20edf3722648989be"
...@@ -5600,6 +5607,11 @@ follow-redirects@^1.0.0: ...@@ -5600,6 +5607,11 @@ follow-redirects@^1.0.0:
5600 dependencies: 5607 dependencies:
5601 debug "^3.0.0" 5608 debug "^3.0.0"
5602 5609
5610 +follow-redirects@^1.10.0:
5611 + version "1.13.0"
5612 + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.13.0.tgz#b42e8d93a2a7eea5ed88633676d6597bc8e384db"
5613 + integrity sha512-aq6gF1BEKje4a9i9+5jimNFIpq4Q1WiwBToeRK5NvZBd/TRsmW8BsJfOEGkr76TbOyPVD3OVDN910EcUNtRYEA==
5614 +
5603 for-in@^0.1.3: 5615 for-in@^0.1.3:
5604 version "0.1.8" 5616 version "0.1.8"
5605 resolved "https://registry.yarnpkg.com/for-in/-/for-in-0.1.8.tgz#d8773908e31256109952b1fdb9b3fa867d2775e1" 5617 resolved "https://registry.yarnpkg.com/for-in/-/for-in-0.1.8.tgz#d8773908e31256109952b1fdb9b3fa867d2775e1"
......