From b8c4232bc8200fd7450c4c526b0bb5c127e384e2 Mon Sep 17 00:00:00 2001 From: Youngbae1126 Date: Sat, 16 Mar 2024 16:07:50 +0900 Subject: [PATCH] =?UTF-8?q?:sparkels:=20Feat:=20/api/feeds/all=20api=20?= =?UTF-8?q?=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/FeedCard.js | 8 ++---- src/pages/Feed.jsx | 56 ++++++++++++++++++++++++++++---------- src/styles/Feed.css | 4 +-- src/styles/FeedCard.css | 1 - 4 files changed, 47 insertions(+), 22 deletions(-) diff --git a/src/components/FeedCard.js b/src/components/FeedCard.js index b9d7496..cbd42c1 100644 --- a/src/components/FeedCard.js +++ b/src/components/FeedCard.js @@ -3,16 +3,14 @@ import React from 'react'; //STYLES import '../styles/FeedCard.css'; -const FeedCard = ({ title, author, nickname, imgUrl }) => { +const FeedCard = ({ title, author, nickname, imgUrl, comment }) => { return ( <>
-

- 죽는 날까지 하늘을 우러러 한 점 부끄럼이 없기를 -

+

{comment}

@@ -29,7 +27,7 @@ const FeedCard = ({ title, author, nickname, imgUrl }) => {
-
별헤는밤
+
{nickname}
diff --git a/src/pages/Feed.jsx b/src/pages/Feed.jsx index 74bda8d..f194a65 100644 --- a/src/pages/Feed.jsx +++ b/src/pages/Feed.jsx @@ -1,6 +1,9 @@ import React, { useState, useEffect } from 'react'; import axios from 'axios'; +// SERVICES +import api from '../services/api'; + // COMPONENTS import Header from '../components/Header'; import FeedGrid from '../components/FeedGrid'; @@ -11,11 +14,11 @@ import '../styles/Feed.css'; const Feed = () => { const [dogArr, setDogArr] = useState([]); + const [feedArr, setFeedArr] = useState([]); const [page, setPage] = useState(0); const [isLoading, setIsLoading] = useState(false); // Intersection Observer 설정 - const handleObserver = (entries) => { // console.log(entries); const target = entries[0]; @@ -39,21 +42,44 @@ const Feed = () => { // page 변경 감지에 따른 API호출 useEffect(() => { fetchData(); - // console.log(page); + console.log(page); }, [page]); + let feedFetchData = { page: { page }, size: 9 }; + // API를 호출하는 부분 const fetchData = async () => { setIsLoading(true); try { - const API_URL = `https://api.thedogapi.com/v1/images/search?size=small&format=json&has_breeds=true&order=ASC&page=${page}&limit=10`; - const response = await axios.get(API_URL); - const newData = response.data.map((dogImg) => ({ - id: dogImg.id, - dogUrl: dogImg.url, + // api.get('/api/feeds/all', feedFetchData).then((res) => { + // // console.log(res.data.content); + // setFeedArr(res.data.content); + // setFeedArr((prevData) => [...prevData, ...res.data.content]); + // }); + const API_URL = + 'https://port-0-backend-book-pharmacy-umnqdut2blqqhv7sd.sel5.cloudtype.app/api/feeds/all?page=0&size=9'; + + const response = await axios.get(API_URL, feedFetchData); + // .then((res) => { + // // console.log(res.data.content); + // setFeedArr(res.data.content); + // }); + + // const newData = response.data.map((dogImg) => ({ + // id: dogImg.id, + // dogUrl: dogImg.url, + // })); + + const newData = response.data.content.map((item) => ({ + title: item.bookTitle, + author: item.bookAuthor, + comment: item.comment, + image: item.imgUrl, + nickName: item.clientNickname, })); - // 불러온 데이터를 배열에 추가 - setDogArr((prevData) => [...prevData, ...newData]); + + // //불러온 데이터를 배열에 추가 + setFeedArr((prevData) => [...prevData, ...newData]); } catch (error) { console.log(error); } @@ -68,18 +94,20 @@ const Feed = () => {
추천 피드
- {dogArr.map((item, idx) => { + {feedArr.map((item, idx) => { return ( ); })} -
+
); diff --git a/src/styles/Feed.css b/src/styles/Feed.css index b06b2f6..d1a024d 100644 --- a/src/styles/Feed.css +++ b/src/styles/Feed.css @@ -10,7 +10,7 @@ margin: 0 auto; max-width: 1440px; padding: 24px; - height: 100vh; + /* height: 108vh; */ display: flex; flex-direction: column; } @@ -34,7 +34,7 @@ display: grid; grid-template-columns: repeat(4, 1fr); width: 1440px; - height: 500px; + /* height: 860px; */ -ms-flex-align: center; align-items: center; margin-left: auto; diff --git a/src/styles/FeedCard.css b/src/styles/FeedCard.css index e8fdb86..ed0da25 100644 --- a/src/styles/FeedCard.css +++ b/src/styles/FeedCard.css @@ -31,7 +31,6 @@ .feed_review_wrapper { display: flex; - flex-direction: column; align-items: center; }