-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #222 from boostcampwm-2024/feature/bookmark
[FE] 즐겨찾기 관련 레이아웃 구현 및 API 연동
- Loading branch information
Showing
13 changed files
with
226 additions
and
11 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,60 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { getBookmarkedStocks } from 'service/bookmark'; | ||
|
||
export default function BookMark() { | ||
const navigation = useNavigate(); | ||
|
||
const handleClick = (code: string) => { | ||
navigation(`/stocks/${code}`); | ||
}; | ||
|
||
const { data, isLoading, isError } = useQuery( | ||
['bookmark', 'stock'], | ||
() => getBookmarkedStocks(), | ||
{ | ||
staleTime: 1000, | ||
}, | ||
); | ||
|
||
if (isLoading) return <div>loading</div>; | ||
if (!data) return <div>No data</div>; | ||
if (isError) return <div>error</div>; | ||
|
||
return ( | ||
<div className='mx-auto flex min-h-[500px] w-full flex-1 flex-col rounded-md bg-white p-4 shadow-md'> | ||
<div className='flex pb-2 text-sm font-bold border-b'> | ||
<p className='w-1/2 text-left truncate'>종목</p> | ||
<p className='w-1/4 text-center'>현재가</p> | ||
<p className='w-1/4 text-right'>등락률</p> | ||
</div> | ||
|
||
<ul className='flex flex-col text-sm divide-y'> | ||
{data.map((stock) => { | ||
const { code, name, stck_prpr, prdy_ctrt, prdy_vrss_sign } = stock; | ||
|
||
return ( | ||
<li | ||
className='flex py-2 transition-colors hover:cursor-pointer hover:bg-gray-50' | ||
key={code} | ||
onClick={() => handleClick(code)} | ||
> | ||
<div className='flex w-1/2 gap-2 text-left truncate'> | ||
<p className='font-semibold'>{name}</p> | ||
<p className='text-gray-500'>{code}</p> | ||
</div> | ||
<p className='w-1/4 text-center truncate'> | ||
{(+stck_prpr).toLocaleString()}원 | ||
</p> | ||
<p | ||
className={`w-1/4 truncate text-right ${+prdy_vrss_sign > 3 ? 'text-juga-blue-50' : 'text-juga-red-60'}`} | ||
> | ||
{prdy_ctrt}% | ||
</p> | ||
</li> | ||
); | ||
})} | ||
</ul> | ||
</div> | ||
); | ||
} |
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
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,23 @@ | ||
import { toast } from 'react-toastify'; | ||
|
||
type ToastType = 'success' | 'error' | 'warning' | 'info'; | ||
|
||
type ToastProps = { | ||
message: string; | ||
type: ToastType; | ||
}; | ||
|
||
export default function Toast({ message, type }: ToastProps) { | ||
switch (type) { | ||
case 'success': | ||
return toast.success(message, { position: 'top-right', autoClose: 1000 }); | ||
case 'error': | ||
return toast.error(message, { position: 'top-right', autoClose: 1000 }); | ||
case 'warning': | ||
return toast.warning(message, { position: 'top-right', autoClose: 1000 }); | ||
case 'info': | ||
return toast.info(message, { position: 'top-right', autoClose: 1000 }); | ||
default: | ||
return null; | ||
} | ||
} |
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,42 @@ | ||
import { BookmakredStock } from 'types'; | ||
|
||
export async function bookmark(code: string) { | ||
const url = import.meta.env.PROD | ||
? `${import.meta.env.VITE_API_URL}/stocks/bookmark/${code}` | ||
: `/api/stocks/bookmark/${code}`; | ||
|
||
return fetch(url, { | ||
method: 'POST', | ||
credentials: 'include', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
} | ||
|
||
export async function unbookmark(code: string) { | ||
const url = import.meta.env.PROD | ||
? `${import.meta.env.VITE_API_URL}/stocks/bookmark/${code}` | ||
: `/api/stocks/bookmark/${code}`; | ||
|
||
return fetch(url, { | ||
method: 'DELETE', | ||
credentials: 'include', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
} | ||
|
||
export async function getBookmarkedStocks(): Promise<BookmakredStock[]> { | ||
const url = import.meta.env.PROD | ||
? `${import.meta.env.VITE_API_URL}/stocks/bookmark` | ||
: '/api/stocks/bookmark'; | ||
|
||
return fetch(url, { | ||
credentials: 'include', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}).then((res) => res.json()); | ||
} |
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