-
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.
[FE] feat: 배너 조회 API 연결 및 배너 컴포넌트 작성 (#790)
* feat: 배너 조회 API 연결 쿼리 작성 * feat: 배너 컴포넌트 작성
- Loading branch information
1 parent
b91e775
commit 52cf2ee
Showing
11 changed files
with
82 additions
and
8 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,26 @@ | ||
import { Link } from '@fun-eat/design-system'; | ||
import styled from 'styled-components'; | ||
|
||
import { useBannerQuery } from '@/hooks/queries/banner'; | ||
|
||
const Banner = () => { | ||
const { data: banners } = useBannerQuery(); | ||
const { link, image } = banners[Math.floor(Math.random() * banners.length)]; | ||
|
||
if (!link) { | ||
return <BannerImage src={image} width={600} height={360} alt="배너" />; | ||
} | ||
|
||
return ( | ||
<Link href={link} isExternal> | ||
<BannerImage src={image} width={600} height={360} alt="배너" /> | ||
</Link> | ||
); | ||
}; | ||
|
||
export default Banner; | ||
|
||
const BannerImage = styled.img` | ||
width: 100%; | ||
height: auto; | ||
`; |
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 @@ | ||
export { default as useBannerQuery } from './useBannerQuery'; |
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,16 @@ | ||
import { useSuspendedQuery } from '../useSuspendedQuery'; | ||
|
||
import { bannerApi } from '@/apis'; | ||
import type { Banner } from '@/types/banner'; | ||
|
||
const fetchBanner = async () => { | ||
const response = await bannerApi.get({}); | ||
const data: Banner[] = await response.json(); | ||
return data; | ||
}; | ||
|
||
const useBannerQuery = () => { | ||
return useSuspendedQuery(['banner'], () => fetchBanner()); | ||
}; | ||
|
||
export default useBannerQuery; |
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,17 @@ | ||
[ | ||
{ | ||
"id": 3, | ||
"link": "https://www.youtube.com/embed/3QlYJ0VY7zg", | ||
"image": "https://i.ytimg.com/vi/3QlYJ0VY7zg/maxresdefault.jpg" | ||
}, | ||
{ | ||
"id": 2, | ||
"link": "https://www.youtube.com/embed/3QlYJ0VY7zg", | ||
"image": "https://i.ytimg.com/vi/3QlYJ0VY7zg/maxresdefault.jpg" | ||
}, | ||
{ | ||
"id": 1, | ||
"link": "https://www.youtube.com/embed/3QlYJ0VY7zg", | ||
"image": "https://i.ytimg.com/vi/3QlYJ0VY7zg/maxresdefault.jpg" | ||
} | ||
] |
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,9 @@ | ||
import { rest } from 'msw'; | ||
|
||
import banners from '../data/banners.json'; | ||
|
||
export const bannerHandlers = [ | ||
rest.get('/api/banners', (req, res, ctx) => { | ||
return res(ctx.status(200), ctx.json(banners)); | ||
}), | ||
]; |
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,5 @@ | ||
export interface Banner { | ||
id: number; | ||
link: string; | ||
image: string; | ||
} |