diff --git a/bowwowcare/src/views/HomePage/HomePage.js b/bowwowcare/src/views/HomePage/HomePage.js index 539a61f..dadc26b 100644 --- a/bowwowcare/src/views/HomePage/HomePage.js +++ b/bowwowcare/src/views/HomePage/HomePage.js @@ -11,8 +11,7 @@ import anxiety from "../../assets/images/anxiety.png"; import aggression from "../../assets/images/aggression.png"; function HomePage() { - const [petlist, setPetlist] = useState([]); - const [pet, setPet] = useState([]); + const [petList, setPetList] = useState([]); const navigate = useNavigate(); const fileInput = React.useRef(null); @@ -48,30 +47,21 @@ function HomePage() { headers: authHeader(), }).then((res) => { if (res.status === 200) { - console.log(res); - setPetlist(res.data); + setPetList(res.data); } }).catch((e) => { console.log(e.message); }) }; - const getPetDetail = async () => { - const promise = petlist.map(async (v) => { - const res = await axios.get(`${API_URL}/pets/${v.petId}`); - return res.data; - }); - return Promise.all(promise).then((result) => setPet(result)); - }; useEffect(() => { getPetList(); - getPetDetail(); }, []); return (
-
{pet && }
+
{petList?.length && }

우리 아이 이상행동 확인해보기

diff --git a/bowwowcare/src/views/HomePage/PetList/Sections/PetInfo.js b/bowwowcare/src/views/HomePage/PetList/Sections/PetInfo.js index a83cf55..8563f4b 100644 --- a/bowwowcare/src/views/HomePage/PetList/Sections/PetInfo.js +++ b/bowwowcare/src/views/HomePage/PetList/Sections/PetInfo.js @@ -1,31 +1,56 @@ -import React from "react"; +import React, { useEffect, useState } from "react"; +import axios from "axios"; +import { API_URL } from "../../../../Config"; import { getAge } from "../../../../utils/Calculator"; import { getDurationDate } from "../../../../utils/Calculator"; function PetInfo(props) { - const birthDate = new Date(Date.parse(props.pet.birthDate)); - const adoptDate = new Date(Date.parse(props.pet.adoptionDate)); + const [petName, setPetName] = useState(""); + const [petImg, setPetImg] = useState(""); + const [age, setAge] = useState(); + const [day, setDay] = useState(); - const age = getAge(birthDate); - const day = getDurationDate(adoptDate); + useEffect(() => { + getPetDetail(); + }, []); + + const getPetDetail = () => { + axios({ + method: 'get', + url: `${API_URL}/pets/${props.pet.petId}` + }) + .then(response => { + if (response.status===200) { + const pet = response.data; + setPetName(pet.name); + setPetImg(pet.petImg); + const birthDate = new Date(Date.parse(pet.birthDate)); + const adoptionDate = new Date(Date.parse(pet.adoptionDate)); + setAge(getAge(birthDate)); + setDay(getDurationDate(adoptionDate)); + } + }) + }; return (
- {props.pet.fileImg && ( + {petImg && ( 프로필 이미지 )}
-
- {props.pet.name} - {age}살 -
함께한지 {day}일째
-
+ {petName ? ( +
+ {petName} + {age}살 +
함께한지 {day}일째
+
+ ) : null}
); }