From 41010e47c48ab750595bb740414fc88d835489b9 Mon Sep 17 00:00:00 2001 From: limyeonsang Date: Fri, 8 Jul 2022 08:39:14 +0900 Subject: [PATCH] #12 Add follow --- apis/myPage.ts | 31 +++++++++++ constants/queryKey.ts | 4 +- constants/uri.ts | 4 +- pages/myPage/viewFollow.tsx | 105 +++++++++++++----------------------- 4 files changed, 74 insertions(+), 70 deletions(-) diff --git a/apis/myPage.ts b/apis/myPage.ts index 8d763e0..125829a 100644 --- a/apis/myPage.ts +++ b/apis/myPage.ts @@ -59,3 +59,34 @@ export const getQuestionVideos = async ({ pageParam = 0 }) => { ); return res.data; }; + +interface GetFollowListResponse { + id: number; + profile: string; + name: string; +} + +export const getFollowerList = async () => { + const userId = await getUserId(); + const res = await request.get(`${uri.follwerList}`, { + params: { + userId, + }, + }); + + return res.data; +}; + +export const getFollowingList = async () => { + const userId = await getUserId(); + const res = await request.get( + `${uri.followingList}`, + { + params: { + userId, + }, + }, + ); + + return res.data; +}; diff --git a/constants/queryKey.ts b/constants/queryKey.ts index a455971..b0a71c3 100644 --- a/constants/queryKey.ts +++ b/constants/queryKey.ts @@ -1,7 +1,9 @@ const enum queryKey { myInfo = "my-info", userId = "user-id", - myQuestion = "my-question" + myQuestion = "my-question", + followerList = "follower-list", + followingList = "following-list", } export default queryKey; diff --git a/constants/uri.ts b/constants/uri.ts index 40f00cb..6089a10 100644 --- a/constants/uri.ts +++ b/constants/uri.ts @@ -2,7 +2,9 @@ const enum uri { refresh = "/refresh", userInfo = "/user/info", userId = "/user/my", - questionVideos = "/user//question/video" + questionVideos = "/user//question/video", + follwerList = "/follower", + followingList = "/following" } export default uri; diff --git a/pages/myPage/viewFollow.tsx b/pages/myPage/viewFollow.tsx index 3dfc98c..676661c 100644 --- a/pages/myPage/viewFollow.tsx +++ b/pages/myPage/viewFollow.tsx @@ -1,85 +1,54 @@ -import { FC } from "react"; +import { FC, useEffect, useState } from "react"; import styled from "@emotion/styled"; import { UserItem, SelectButton } from "@views/viewFollow"; +import { useQuery } from "react-query"; +import queryKey from "@constants/queryKey"; +import { getFollowerList, getFollowingList } from "@apis/myPage"; const ViewFollowContainer: FC = () => { - const DUMMY = [ - { - id: 2, - profile: "/a.png", - name: "찌찌민", - }, - { - id: 2, - profile: "/a.png", - name: "찌찌민", - }, - { - id: 3, - profile: "/a.png", - name: "찌찌민", - }, - { - id: 4, - profile: "/a.png", - name: "찌찌민", - }, - { - id: 5, - profile: "/a.png", - name: "찌찌민", - }, - { - id: 6, - profile: "/a.png", - name: "찌찌민", - }, - { - id: 7, - profile: "/a.png", - name: "찌찌민", - }, - { - id: 8, - profile: "/a.png", - name: "찌찌민", - }, - { - id: 9, - profile: "/a.png", - name: "찌찌민", - }, - { - id: 10, - profile: "/a.png", - name: "찌찌민", - }, - { - id: 11, - profile: "/a.png", - name: "찌찌민", - }, - { - id: 12, - profile: "/a.png", - name: "찌찌민", - }, - ]; + const res1 = useQuery([queryKey.followerList], getFollowerList); + const res2 = useQuery([queryKey.followingList], getFollowingList); + + const [isFollower, setIsFollower] = useState(true); + + useEffect(() => { + console.log(res1); + }, [res1]); + + if (res1.isLoading || res1.isLoading) { + return
loading
; + } + + if (res1.isError || res2.isError) { + return
error
; + } return ( {}, text: `팔로워 ${2}` }, - { name: "following-list", onActive: () => {}, text: `팔로잉 ${100}` }, + { + name: "follower-list", + onActive: () => { + setIsFollower(true); + }, + text: `팔로워 ${res1.data?.length}`, + }, + { + name: "following-list", + onActive: () => { + setIsFollower(false); + }, + text: `팔로잉 ${res2.data?.length}`, + }, ]} initalName="follower-list" /> - - {DUMMY.map((ele) => ( + {/* + {isFollower ? res1.map((ele) => ( ))} - + */} ); };