손수민

[Update] Recommand Page Server Function Update

Showing 25 changed files with 31 additions and 45 deletions
...@@ -2,11 +2,33 @@ import React, { useCallback, useEffect, useState } from "react"; ...@@ -2,11 +2,33 @@ import React, { useCallback, useEffect, useState } from "react";
2 import { useDispatch, useSelector } from "react-redux"; 2 import { useDispatch, useSelector } from "react-redux";
3 import { useNavigate } from "react-router-dom"; 3 import { useNavigate } from "react-router-dom";
4 import "../style/RecommandPage.scss" 4 import "../style/RecommandPage.scss"
5 -import axios from 'axios';
6 -
7 5
8 function RecommandPage(props) { 6 function RecommandPage(props) {
9 7
8 + const clothesResult = useSelector((state) => state.clothes.clothesRecommend);
9 +
10 + const [IsRain, setIsRain] = useState("");
11 + const [TopPath, setTopPath] = useState('');
12 + const [BottomPath, setBottomPath] = useState('');
13 +
14 + useEffect(() => {
15 + clothesResult.then((result) => {
16 + console.log(result);
17 + console.log(result.top);
18 + console.log(result.bottom);
19 +
20 + if (result.umbrella == 1) {
21 + setIsRain("비 예보가 있습니다. 우산을 꼭 챙겨주세요!");
22 + }
23 + else {
24 + setIsRain("비 예보가 없습니다!");
25 + }
26 +
27 + setTopPath(result.top);
28 + setBottomPath(result.bottom);
29 + })
30 + }, [clothesResult])
31 +
10 const navigate = useNavigate(); 32 const navigate = useNavigate();
11 33
12 const [Time, setTime] = useState("00:00:00"); 34 const [Time, setTime] = useState("00:00:00");
...@@ -33,42 +55,6 @@ function RecommandPage(props) { ...@@ -33,42 +55,6 @@ function RecommandPage(props) {
33 navigate('../register'); 55 navigate('../register');
34 }) 56 })
35 57
36 - console.log(initData);
37 -
38 - useEffect(async() => {
39 - try{
40 - const res = await axios.post('localhost:4000/api/weather')
41 - const _inputData = await res.data.map((weatherData) => (
42 - {
43 - today: weatherData.today,
44 - time: weatherData.time,
45 - temperature: weatherData.temperature,
46 - rainper: weatherData.rainper,
47 - weather: weatherData.weather
48 - })
49 - )
50 - // initData 그릇에 concat 으로 추가
51 - setInitData(initData.concat(_inputData))
52 - } catch(e){
53 - console.error(e.message)
54 - }
55 - },[])
56 -
57 - const [Rainstring, setRainstring] = useState("");
58 - const rain = () => {
59 - if(initData.inputData.umbrella == 1) {
60 - setRainstring("비 예보가 있습니다. 우산을 꼭 챙겨주세요!");
61 - }
62 - else if(initData.inputData.umbrella == 0) {
63 - setRainstring("비 예보가 없습니다!");
64 - }
65 - } //weather.js
66 -
67 - rain();
68 -
69 - const [topPath, settopPath] = useState([""]);
70 - const [bottomPath, setbottomPath] = useState([""]); //clothes.js
71 -
72 return ( 58 return (
73 <> 59 <>
74 <dir id = "header"> 60 <dir id = "header">
...@@ -86,24 +72,24 @@ function RecommandPage(props) { ...@@ -86,24 +72,24 @@ function RecommandPage(props) {
86 72
87 <div id = "recommand_body"> 73 <div id = "recommand_body">
88 <dir className="fashion_recommand"> 74 <dir className="fashion_recommand">
89 - <dir className="rainOrnot">{Rainstring}</dir> 75 + <dir className="rainOrnot">{IsRain}</dir>
90 <dir className="clothes"> 76 <dir className="clothes">
91 <dir className="Top"> 77 <dir className="Top">
92 <h1>TOP</h1> 78 <h1>TOP</h1>
93 - <img src={topClothes} className='Top_Image' /> 79 + <img src={TopPath} className='Top_Image' />
94 </dir> 80 </dir>
95 <dir className="Bottom"> 81 <dir className="Bottom">
96 <h1>BOTTOM</h1> 82 <h1>BOTTOM</h1>
97 - <img src={bottomClothes} className='Bottom_Image' /> 83 + <img src={BottomPath} className='Bottom_Image' />
98 </dir> 84 </dir>
99 - <dir className="Head"> 85 + {/* <dir className="Head">
100 <h1>HEAD</h1> 86 <h1>HEAD</h1>
101 - <img src={topClothes} className='Head_Image' /> 87 + <img src="../../../img/조거팬츠.jpg" className='Head_Image' />
102 </dir> 88 </dir>
103 <dir className="Shoes"> 89 <dir className="Shoes">
104 <h1>SHOES</h1> 90 <h1>SHOES</h1>
105 - <img src={bottomClothes} className='Shoes_Image' /> 91 + <img src="../../../../src/img/조거팬츠.jpg" className='Shoes_Image' />
106 - </dir> 92 + </dir> */}
107 </dir> 93 </dir>
108 </dir> 94 </dir>
109 </div> 95 </div>
......