-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#46] feat: implement pet list and pet info screen
- Loading branch information
Showing
6 changed files
with
202 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export const getAge = (date) => { | ||
const now = new Date(); | ||
const nowYear = now.getFullYear(); | ||
const birthYear = date.getFullYear(); | ||
|
||
const age = nowYear - birthYear | ||
|
||
return age; | ||
}; | ||
|
||
export const getBwDate = (date) => { | ||
const now = new Date(); | ||
const stDate = new Date(date.getFullYear(), date.getMonth() + 1, date.getDate()); | ||
const endDate = new Date(now.getFullYear(), now.getMonth() + 1, now.getDate()); | ||
|
||
const btMs = endDate.getTime() - stDate.getTime() ; | ||
const btDay = btMs / (1000*60*60*24); | ||
|
||
return btDay; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React from 'react' | ||
|
||
import { getAge } from '../../../../utils/Calculator'; | ||
import { getBwDate } from '../../../../utils/Calculator'; | ||
|
||
function PetInfo(props) { | ||
|
||
const birthDate = new Date( Date.parse(props.pet.birthDate) ); | ||
const adoptDate = new Date( Date.parse(props.pet.adoptDate) ); | ||
|
||
const age = getAge(birthDate); | ||
const day = getBwDate(adoptDate); | ||
|
||
return ( | ||
<div className='flex shadow-lg mt-6 p-8 rounded-lg'> | ||
<div className="rounded-full border w-14 h-14"> | ||
{props.pet.fileImg && ( | ||
<img | ||
src={URL.createObjectURL(props.pet.fileImg)} | ||
alt="프로필 이미지" | ||
className="rounded-full w-14 h-14" | ||
></img> | ||
)} | ||
</div> | ||
<div className='ml-5'> | ||
<span className='text-xl'>{props.pet.petname}</span> | ||
<span className='text-sm'> {age}살</span> | ||
<div>함께한지 {day}일째</div> | ||
</div> | ||
</div> | ||
) | ||
|
||
} | ||
|
||
export default PetInfo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from 'react' | ||
import { Link } from 'react-router-dom'; | ||
|
||
import PetInfo from './PetInfo/PetInfo' | ||
|
||
function PetList(props) { | ||
return ( | ||
<div> | ||
{ props.pet.map((a, i)=>{ | ||
return( | ||
<Link to={`/petinfo/${a.id}`} state={{ pet: a }}> | ||
<PetInfo pet={a} key={i}/> | ||
</Link> | ||
) | ||
})} | ||
</div> | ||
) | ||
} | ||
|
||
export default PetList |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import React from 'react' | ||
import { useLocation, useNavigate, useParams } from "react-router-dom"; | ||
|
||
import Header from '../../components/Header'; | ||
import Button from '../../components/Button'; | ||
|
||
function PetInfoPage() { | ||
|
||
const navigate = useNavigate(); | ||
const location = useLocation(); | ||
const params = useParams(); | ||
//console.log(location.state.pet) | ||
const pet = location.state.pet; | ||
const petname = location.state.pet.petname; | ||
const gender = location.state.pet.gender; | ||
const birthDate = location.state.pet.birthDate.substring(0,10).split('-').join('.'); | ||
const adoptDate = location.state.pet.adoptDate.substring(0,10).split('-').join('.'); | ||
const fileImg = location.state.pet.fileImg; | ||
|
||
return ( | ||
<div className="px-8"> | ||
<Header /> | ||
<div className='flex justify-center mt-30'> | ||
<div className='flex flex-col w-full'> | ||
<div className='text-center'> | ||
<div className='flex justify-center'> | ||
<div className="rounded-full border w-14 h-14 mb-5"> | ||
{fileImg && ( | ||
<img | ||
src={URL.createObjectURL(fileImg)} | ||
alt="프로필 이미지" | ||
className="rounded-full w-14 h-14" | ||
></img> | ||
)} | ||
</div> | ||
</div> | ||
|
||
|
||
<div className='text-xl mb-5'>{petname}</div> | ||
<div className='flex justify-center'> | ||
<div className='text-sm mb-10 border w-28 p-2 rounded-lg'>{gender}</div> | ||
</div> | ||
|
||
</div> | ||
<div className='mb-10'> | ||
<div className='flex justify-center'> | ||
<table className='border-separate border-spacing-3'> | ||
<tr> | ||
<td>태어난 날</td> | ||
<td>{birthDate}</td> | ||
</tr> | ||
<tr> | ||
<td>가족이 된 날</td> | ||
<td>{adoptDate}</td> | ||
</tr> | ||
</table> | ||
</div> | ||
</div> | ||
|
||
<div className='shadow-lg p-10 h-60 mb-10'> | ||
<span>기록</span> | ||
</div> | ||
<Button children="편집" onClick={()=>navigate(`/edit/${params.id}`, { state: pet })}></Button> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default PetInfoPage |