|
1 |
| -import React, { useEffect, useState } from "react"; |
| 1 | +import React, { useEffect, useLayoutEffect, useRef, useState } from "react"; |
| 2 | +import { useDispatch } from "react-redux"; |
2 | 3 | import { useParams } from "react-router-dom";
|
3 | 4 | import { instance } from "../../shared/AxiosInstance";
|
4 |
| -import MainScheduleCards from "./MainScheduleCards"; |
| 5 | +import FriednsScheduleCard from "./FriednsScheduleCard"; |
| 6 | +import { __postFollowState } from "../../redux/modules/FollowSlice"; |
5 | 7 |
|
6 | 8 | const FriendsMain = () => {
|
| 9 | + const dispatch = useDispatch(); |
7 | 10 | const id = useParams();
|
| 11 | + const [status, setStatus] = useState(200); |
8 | 12 | const followid = id.id;
|
| 13 | + const [button, setButton] = useState(false); |
9 | 14 | const [schedule, setSchedule] = useState();
|
| 15 | + |
10 | 16 | const friendName = sessionStorage.getItem("clickedUserName");
|
11 | 17 | const friendImg = sessionStorage.getItem("clickedUserImg");
|
| 18 | + |
12 | 19 | const getSchdule = async () => {
|
13 |
| - await instance.get(`/users/${followid}/events`).then((appData) => { |
14 |
| - setSchedule(appData.data.data); |
15 |
| - }, []); |
| 20 | + try { |
| 21 | + await instance.get(`/users/${followid}/events`).then((response) => { |
| 22 | + setSchedule(response.data.data); |
| 23 | + }); |
| 24 | + } catch (e) { |
| 25 | + if (e.response.status === 403) { |
| 26 | + setStatus(403); |
| 27 | + console.log(status); |
| 28 | + } |
| 29 | + } |
16 | 30 | };
|
17 |
| - |
18 |
| - useEffect(() => { |
| 31 | + const refresh = () => { |
| 32 | + window.location.reload(); |
| 33 | + }; |
| 34 | + const handleClick = () => { |
| 35 | + dispatch(__postFollowState({ id: id.id, state: "following" })); |
| 36 | + setButton(true); |
| 37 | + // window.location.reload(); |
| 38 | + }; |
| 39 | + useLayoutEffect(() => { |
19 | 40 | getSchdule();
|
20 |
| - }, []); |
| 41 | + }, [schedule]); |
21 | 42 |
|
22 | 43 | return (
|
23 | 44 | <>
|
24 | 45 | <div className="container">
|
25 | 46 | <div className="grid grid-flow-row mt-[] ml-[20px] mr-[20px]">
|
26 |
| - <div className="mt-[30px] w-full h-[80px] bg-[#FFFFFF] rounded-[10px] drop-shadow-lg"> |
27 |
| - <div className="flex flex-row gap-[10px]"> |
28 |
| - <div className="p-[10px]"> |
| 47 | + <div> |
| 48 | + {status === 200 ? ( |
| 49 | + <div className="mt-[30px] w-full h-[80px] bg-[#FFFFFF] rounded-[10px] drop-shadow-lg"> |
| 50 | + <div className="flex flex-row gap-[10px]"> |
| 51 | + <div className="p-[10px]"> |
| 52 | + <img |
| 53 | + className="h-[60px] w-[60px] rounded-full" |
| 54 | + src={friendImg} |
| 55 | + alt="프로필이미지" |
| 56 | + /> |
| 57 | + </div> |
| 58 | + <div className="flex items-center"> |
| 59 | + <p className="p-[10px] font-[700] text-[20px] text-textNavy"> |
| 60 | + {friendName}님의 스케쥴입니다! |
| 61 | + </p> |
| 62 | + </div> |
| 63 | + </div> |
| 64 | + <div className="flex flex-col gap-[30px] mt-[28px] rounded-[10px]"> |
| 65 | + {schedule?.map((list) => { |
| 66 | + return ( |
| 67 | + <FriednsScheduleCard |
| 68 | + key={list.eventId} |
| 69 | + schedules={list} |
| 70 | + /> |
| 71 | + ); |
| 72 | + })} |
| 73 | + </div> |
| 74 | + </div> |
| 75 | + ) : ( |
| 76 | + <div className="text-[22px] mt-[100px] font-extralight "> |
| 77 | + 현재 팔로우하고있지 않은 유저입니다! |
| 78 | + <br /> |
| 79 | + <div className="text-[16px] mt-[20px] text-center"> |
| 80 | + {friendName}님의 스케쥴을 확인하시려면 <br /> |
| 81 | + 팔로우해주세요 |
| 82 | + </div> |
29 | 83 | <img
|
30 |
| - className="h-[60px] w-[60px] rounded-full" |
| 84 | + className="h-[80px] m-auto mt-[30px] w-[80px] rounded-full" |
31 | 85 | src={friendImg}
|
32 | 86 | alt="프로필이미지"
|
33 | 87 | />
|
| 88 | + <div className="flex items-center w-[110px] mx-auto h-[39px] justify-center mt-[20px] text-[12px] rounded-[4px] text-white bg-[#002C51] cursor-pointer"> |
| 89 | + <span onClick={button ? refresh : handleClick}> |
| 90 | + {button ? ( |
| 91 | + <span>한번만 더 클릭해줭</span> |
| 92 | + ) : ( |
| 93 | + <span>{friendName}님 팔로우하기</span> |
| 94 | + )} |
| 95 | + </span> |
| 96 | + </div> |
34 | 97 | </div>
|
35 |
| - <div className="flex items-center"> |
36 |
| - <p className="p-[10px] font-[700] text-[20px] text-textNavy"> |
37 |
| - {friendName}님의 스케쥴입니다! |
38 |
| - </p> |
39 |
| - </div> |
40 |
| - </div> |
41 |
| - </div> |
42 |
| - <div> |
43 |
| - {/* <InfiniteScroll /> */} |
44 |
| - <div className="flex flex-col gap-[30px] mt-[28px] rounded-[10px]"> |
45 |
| - {schedule?.map((list) => { |
46 |
| - return ( |
47 |
| - <MainScheduleCards key={list.eventId} schedules={list} /> |
48 |
| - ); |
49 |
| - })} |
50 |
| - </div> |
| 98 | + )} |
51 | 99 | </div>
|
52 | 100 | </div>
|
53 | 101 | </div>
|
|
0 commit comments