SurveyPage.js
2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import React, { useState, useEffect } from "react";
import Card from "../components/card/Card";
import {useDispatch} from 'react-redux';
import {getResultThunk} from "../store/action/result";
import "antd/dist/antd.css";
import styled, { css } from "styled-components";
const SurveyContainer = styled.div`
display: flex;
justify-content: center;
// 얘도 배경 고려해보기
`;
const Container = styled.div`
/* border: solid 1px red; */
width: 500px;
height: 100vh;
overflow: hidden;
display: flex;
flex-direction: column;
align-items: center;
`;
const ProgressBar = styled.div`
display: flex;
align-items: center;
width: 300px;
padding: 0.25rem;
margin-top: 14rem;
background-color: #747b4b;
border-radius: 1rem;
position: relative;
`;
// 적당한 icon 찾으면 바꿀 것임
const ProgressIcon = styled.div`
position: absolute;
width: 25px;
height: 25px;
border-radius: 50%;
background-color: #3c441d;
${(props)=> css`
transform: translateX(${30 * props.curIdx}px);
transition: 0.5s;
`}
`;
const SliderCotainer = styled.div`
width: 100%;
display: flex;
align-items: center;
${(props) => css`
transform: translateX(${-500 * props.curIdx}px);
transition: 0.5s;
`}
margin-top: 6rem;
`;
function SurveyPage({ history, question }) {
const [curIdx, setCurIdx] = useState(0);
const [answer, setAnswer] = useState([]); // post로 보낼 state
const dispatch = useDispatch();
useEffect(()=>{
if(answer.length === 10){ // answer state 배열에 10개가 채워지면,
dispatch(getResultThunk(answer));
history.push('/result');
}
},[answer]);
return (
<SurveyContainer>
<Container>
{/* 상태바 넣기 */}
<ProgressBar>
<ProgressIcon curIdx={curIdx}/>
</ProgressBar>
<SliderCotainer curIdx={curIdx}>
{/* 얘가 슬라이더 컨테이너 */}
{question.map((question) => (
<Card
key={question.num}
question={question}
answer={answer}
setAnswer={setAnswer}
curIdx={curIdx}
setCurIdx={setCurIdx}
/>
))}
</SliderCotainer>
</Container>
</SurveyContainer>
);
}
export default SurveyPage;