이준호

[ADD] 서버 통신에서의 로딩 및 에러처리 코드 추가 & Loading 페이지 추가

...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
8 8
9 20대 남자면 꼭 가야만 하는 군대, 어떤 보직이 알맞을지 미리 추천해 드리겠습니다. 9 20대 남자면 꼭 가야만 하는 군대, 어떤 보직이 알맞을지 미리 추천해 드리겠습니다.
10 10
11 -(이미지 추가하기) 11 +> (이미지 추가 예정)
12 12
13 ## 🔖 프로그램 구조 13 ## 🔖 프로그램 구조
14 14
......
1 +import { Spin } from 'antd';
2 +import { LoadingOutlined } from '@ant-design/icons';
3 +
4 +const antIcon = <LoadingOutlined style={{ fontSize: 40 }} spin />;
5 +
6 +function Loading() {
7 + return (
8 + <Spin indicator={antIcon}
9 + style={{ display: "flex", alignItems: "center", justifyContent:"center", margin: "300px"}}/>
10 + )
11 +}
12 +
13 +export default Loading;
14 +
15 +// 군인 관련 애니메이션 or 움짤로 개선 예정
...\ No newline at end of file ...\ No newline at end of file
1 import React from 'react' 1 import React from 'react'
2 import { useSelector } from 'react-redux'; 2 import { useSelector } from 'react-redux';
3 import ResultPage from '../pages/ResultPage'; 3 import ResultPage from '../pages/ResultPage';
4 +import Loading from '../components/loading/Loading';
4 5
5 export function ResultPageContainer() { 6 export function ResultPageContainer() {
6 - const data = useSelector((state) => state.result.data); 7 + const {loading,data,error} = useSelector((state) => state.result);
7 return ( 8 return (
8 <> 9 <>
9 - <ResultPage 10 + {loading && <Loading />}
10 - result={data} 11 + {data && <ResultPage result={data}/>}
11 - /> 12 + {error && <div>에러 발생!!</div>}
12 </> 13 </>
13 ) 14 )
14 } 15 }
......
1 import React from 'react'; 1 import React from 'react';
2 import { useSelector } from 'react-redux'; 2 import { useSelector } from 'react-redux';
3 import SurveyPage from '../pages/SurveyPage'; 3 import SurveyPage from '../pages/SurveyPage';
4 -// import { createHashHistory } from 'history' 4 +import Loading from '../components/loading/Loading';
5 -// const history = createHashHistory();
6 5
7 export function SurveyPageContainer({history}) { 6 export function SurveyPageContainer({history}) {
8 - const data = useSelector((state) => state.survey.data); 7 + const {loading,data,error} = useSelector((state) => state.survey);
9 return ( 8 return (
10 <> 9 <>
11 - <SurveyPage 10 + {loading && <Loading />}
12 - history={history} 11 + {data && <SurveyPage history={history} question={data}/>}
13 - question={data} 12 + {error && <div>에러 발생!!</div>}
14 - />
15 </> 13 </>
16 ) 14 )
17 } 15 }
......
...@@ -40,7 +40,6 @@ function SurveyPage({ history, question }) { ...@@ -40,7 +40,6 @@ function SurveyPage({ history, question }) {
40 if(answer.length === 10){ // answer state 배열에 10개가 채워지면, 40 if(answer.length === 10){ // answer state 배열에 10개가 채워지면,
41 dispatch(getResultThunk(answer)); 41 dispatch(getResultThunk(answer));
42 history.push('/result'); 42 history.push('/result');
43 - console.log(history);
44 } 43 }
45 },[answer]); 44 },[answer]);
46 45
......