page.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { fetchJson } from '@/lib/utils/server';
  2. import type { BannerActiveListResponse, BannerItem } from '@/types/response/banner/active-list';
  3. import type { LiveChannelListResponse } from '@/types/response/channel/live-list';
  4. import HomeBannerCarousel from './_components/HomeBannerCarousel';
  5. import LiveChannelGrid from './_components/LiveChannelGrid';
  6. import LiveChannelEmpty from './_components/LiveChannelEmpty';
  7. import { FEATURE_CHANNEL } from '@/constants/features';
  8. import './_components/home.scss';
  9. const BANNER_POSITION_CODE = 'main-top';
  10. const LIVE_PAGE_SIZE = 24;
  11. async function loadActiveBanners(): Promise<BannerItem[]> {
  12. const res = await fetchJson<BannerActiveListResponse>('/api/banner/items', {
  13. method: 'POST',
  14. body: JSON.stringify({ code: BANNER_POSITION_CODE, onlyActive: true })
  15. });
  16. if (!res.success || !res.data) {
  17. return [];
  18. }
  19. return res.data.list.filter(b => b.desktopImage !== null || b.mobileImage !== null);
  20. }
  21. async function loadLiveChannels(): Promise<{ channels: LiveChannelListResponse['channels']; total: number }> {
  22. const res = await fetchJson<LiveChannelListResponse>(`/api/channel/live-list?limit=${LIVE_PAGE_SIZE}&offset=0`, { method: 'GET' });
  23. if (!res.success || !res.data) {
  24. return { channels: [], total: 0 };
  25. }
  26. return { channels: res.data.channels, total: res.data.total };
  27. }
  28. export default async function Home() {
  29. // 채널 기능 OFF: 라이브 채널 섹션 미노출이므로 조회 생략
  30. const [banners, live] = await Promise.all([
  31. loadActiveBanners(),
  32. FEATURE_CHANNEL ? loadLiveChannels() : Promise.resolve({ channels: [], total: 0 })
  33. ]);
  34. return (
  35. <div className="home">
  36. <div className="home__inner">
  37. <HomeBannerCarousel items={banners} />
  38. {FEATURE_CHANNEL && (
  39. live.channels.length === 0 ? (
  40. <LiveChannelEmpty />
  41. ) : (
  42. <LiveChannelGrid
  43. initialChannels={live.channels}
  44. initialTotal={live.total}
  45. pageSize={LIVE_PAGE_SIZE}
  46. />
  47. )
  48. )}
  49. </div>
  50. </div>
  51. );
  52. }