RecommandPage.js 2.31 KB
import React, { useCallback, useEffect, useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import { useNavigate } from "react-router-dom";
import { logout } from "../../../modules/user";
import "../style/RecommandPage.scss"

function RecommandPage(props) {

    const clothesResult = useSelector((state) => state.clothes.clothesRecommend);

    const [IsRain, setIsRain] = useState("");
    const [TopPath, setTopPath] = useState('');
    const [BottomPath, setBottomPath] = useState('');

    const dispatch = useDispatch();

    useEffect(() => {
        clothesResult.then((result) => {

            if (result.umbrella == 1) {
                setIsRain("비 예보가 있습니다. 우산을 꼭 챙겨주세요!");
            }
            else {
                setIsRain("비 예보가 없습니다!");
            }

            setTopPath(result.top);
            setBottomPath(result.bottom);
        })
    }, [clothesResult])

    const navigate = useNavigate();

    const onClickLogout = useCallback((event) => {
      dispatch(logout());
      navigate('/login');
    })

    const onClickRegister = useCallback((event) => {
        navigate('/');
    })  

    const onClickTitle = useCallback((event) => {
      navigate('/main')
    })

    return (
        <> 
        <dir id = "header">
            <dir className="header_title" onClick = {onClickTitle}>
                <h1>Weather_Briefing</h1>
            </dir>
            <dir className="header_choice_box">
                <button type="button" onClick={onClickLogout}>Logout</button>
                <button type="button" onClick={onClickRegister}>Register</button>
            </dir>
        </dir>

        <div id = "recommand_body">
            <dir className="fashion_recommand">
                <dir className="rainOrnot">{IsRain}</dir>
                <dir className="clothes">
                    <dir className="Top">
                        <h1>TOP</h1>
                        <img src={TopPath} className='Top_Image' />
                    </dir>
                    <dir className="Bottom">
                        <h1>BOTTOM</h1>
                        <img src={BottomPath} className='Bottom_Image' />
                    </dir>
                </dir>
            </dir>
        </div>
    </>
    );
};

export default RecommandPage;