Skip to content

Commit 1e2b61f

Browse files
authored
Merge pull request #1332 from Moadong/develop-fe
[release] FE
2 parents ab6ef67 + b77407b commit 1e2b61f

File tree

7 files changed

+85
-65
lines changed

7 files changed

+85
-65
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@
66
.env
77

88
CLAUDE.md
9-
.claude
9+
.claude
10+
11+
dailyNote/

frontend/src/apis/banner.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import API_BASE_URL from '@/constants/api';
2+
import { handleResponse } from './utils/apiHelpers';
3+
4+
export type BannerType = 'WEB' | 'APP_HOME' | 'WEB_MOBILE';
5+
6+
export interface Banner {
7+
id: string;
8+
imageUrl: string;
9+
linkTo: string | null;
10+
alt: string;
11+
}
12+
13+
// Banner API
14+
export const bannerApi = {
15+
getBanners: async (type: BannerType = 'WEB'): Promise<Banner[]> => {
16+
const url = new URL(`${API_BASE_URL}/api/banner`);
17+
url.searchParams.set('type', type);
18+
19+
const response = await fetch(url);
20+
const data = await handleResponse<{
21+
statuscode: string;
22+
message: string;
23+
images: Banner[];
24+
}>(response, `배너 목록 조회 실패 : ${response.status}`);
25+
26+
return data?.images ?? [];
27+
},
28+
};

frontend/src/constants/queryKeys.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,9 @@ export const queryKeys = {
2323
all: ['promotions'] as const,
2424
list: () => ['promotions', 'list'] as const,
2525
},
26+
banner: {
27+
all: ['banner'] as const,
28+
list: (type: 'WEB' | 'APP_HOME' | 'WEB_MOBILE') =>
29+
['banner', type] as const,
30+
},
2631
} as const;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { useQuery } from '@tanstack/react-query';
2+
import { Banner, bannerApi, BannerType } from '@/apis/banner';
3+
import { queryKeys } from '@/constants/queryKeys';
4+
5+
export const useGetBanners = (type: BannerType = 'WEB') => {
6+
return useQuery<Banner[]>({
7+
queryKey: queryKeys.banner.list(type),
8+
queryFn: () => bannerApi.getBanners(type),
9+
staleTime: 24 * 60 * 60 * 1000,
10+
gcTime: 24 * 60 * 60 * 1000,
11+
});
12+
};

frontend/src/pages/FestivalPage/components/BoothMapSection/BoothMapSection.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -665,15 +665,12 @@ const BoothMapSection = () => {
665665
cursor: booth.link ? 'pointer' : 'default',
666666
}}
667667
onClick={() => {
668+
if (isInAppWebView()) return;
668669
if (booth.link) {
669670
trackEvent(USER_EVENT.FESTIVAL_BOOTH_CLICKED, {
670671
booth: booth.name,
671672
});
672-
if (isInAppWebView()) {
673-
navigate(`/webview/club/${booth.link}`);
674-
} else {
675-
navigate(`/clubDetail/${booth.link}`);
676-
}
673+
navigate(`/clubDetail/${booth.link}`);
677674
}
678675
}}
679676
>

frontend/src/pages/MainPage/components/Banner/Banner.stories.tsx

Lines changed: 0 additions & 51 deletions
This file was deleted.

frontend/src/pages/MainPage/components/Banner/Banner.tsx

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import NextButton from '@/assets/images/icons/next_button_icon.svg';
66
import PrevButton from '@/assets/images/icons/prev_button_icon.svg';
77
import { USER_EVENT } from '@/constants/eventName';
88
import useMixpanelTrack from '@/hooks/Mixpanel/useMixpanelTrack';
9+
import { useGetBanners } from '@/hooks/Queries/useBanner';
910
import useDevice from '@/hooks/useDevice';
1011
import useNavigator from '@/hooks/useNavigator';
1112
import { detectPlatform, getAppStoreLink } from '@/utils/appStoreLink';
@@ -18,6 +19,23 @@ const Banner = () => {
1819
const trackEvent = useMixpanelTrack();
1920
const [swiperInstance, setSwiperInstance] = useState<SwiperType | null>(null);
2021
const [currentIndex, setCurrentIndex] = useState(0);
22+
const bannerType = isMobile ? 'WEB_MOBILE' : 'WEB';
23+
const { data: banners, isLoading, isFetched } = useGetBanners(bannerType);
24+
25+
const fallbackBanners = BANNERS.map((banner) => ({
26+
id: banner.id,
27+
imageUrl: isMobile ? banner.mobileImage : banner.desktopImage,
28+
linkTo: banner.linkTo ?? null,
29+
alt: banner.alt,
30+
}));
31+
32+
const hasApiBanners = (banners?.length ?? 0) > 0;
33+
const shouldUseFallback = isFetched && !hasApiBanners;
34+
const displayBanners = hasApiBanners
35+
? banners
36+
: shouldUseFallback
37+
? fallbackBanners
38+
: [];
2139

2240
const handlePrev = () => {
2341
swiperInstance?.slidePrev();
@@ -53,6 +71,14 @@ const Banner = () => {
5371
handleLink(url);
5472
};
5573

74+
if (isLoading) {
75+
return null;
76+
}
77+
78+
if (displayBanners?.length === 0) {
79+
return null;
80+
}
81+
5682
return (
5783
<Styled.BannerContainer>
5884
<Styled.BannerWrapper>
@@ -76,31 +102,32 @@ const Banner = () => {
76102
}}
77103
speed={500}
78104
>
79-
{BANNERS.map((banner) => (
105+
{displayBanners?.map((banner) => (
80106
<SwiperSlide key={banner.id}>
81107
<Styled.BannerItem
82108
isClickable={!!banner.linkTo}
83109
onClick={() =>
84-
handleBannerClick(banner.id, banner.alt, banner.linkTo)
110+
handleBannerClick(
111+
banner.id,
112+
banner.alt,
113+
banner.linkTo || undefined,
114+
)
85115
}
86116
>
87-
<img
88-
src={isMobile ? banner.mobileImage : banner.desktopImage}
89-
alt={banner.alt}
90-
/>
117+
<img src={banner.imageUrl} alt={banner.alt} />
91118
</Styled.BannerItem>
92119
</SwiperSlide>
93120
))}
94121
</Swiper>
95122
{isMobile && (
96123
<Styled.NumericPagination>
97-
{currentIndex + 1} / {BANNERS.length}
124+
{currentIndex + 1} / {displayBanners?.length ?? 0}
98125
</Styled.NumericPagination>
99126
)}
100127

101128
{!isMobile && (
102129
<Styled.DotPagination>
103-
{BANNERS.map((_, index) => (
130+
{displayBanners?.map((_, index) => (
104131
<Styled.Dot key={index} active={currentIndex === index} />
105132
))}
106133
</Styled.DotPagination>

0 commit comments

Comments
 (0)