page.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 type { WorldIndexRow } from '@/types/worldIndex';
  5. import type { MarketQuoteRow } from '@/types/marketQuote';
  6. import { fetchWorldIndices } from '@/lib/api/worldIndices';
  7. import { fetchMarketQuotes } from '@/lib/api/marketQuotes';
  8. import type { DomesticIndexRow } from '@/types/domesticSummary';
  9. import { fetchDomesticSummary } from '@/lib/api/domesticSummary';
  10. import HomeBannerCarousel from './_components/HomeBannerCarousel';
  11. import WorldMarketMap from './_components/WorldMarketMap';
  12. import DomesticSummary from './_components/DomesticSummary';
  13. import MajorQuotesGrid from './_components/MajorQuotesGrid';
  14. import LiveChannelGrid from './_components/LiveChannelGrid';
  15. import LiveChannelEmpty from './_components/LiveChannelEmpty';
  16. import { FEATURE_CHANNEL } from '@/constants/features';
  17. import './_components/home.scss';
  18. const BANNER_POSITION_CODE = 'main-top';
  19. const LIVE_PAGE_SIZE = 24;
  20. async function loadActiveBanners(): Promise<BannerItem[]> {
  21. const res = await fetchJson<BannerActiveListResponse>('/api/banner/items', {
  22. method: 'POST',
  23. body: JSON.stringify({ code: BANNER_POSITION_CODE, onlyActive: true })
  24. });
  25. if (!res.success || !res.data) {
  26. return [];
  27. }
  28. return res.data.list.filter(b => b.desktopImage !== null || b.mobileImage !== null);
  29. }
  30. async function loadLiveChannels(): Promise<{ channels: LiveChannelListResponse['channels']; total: number }> {
  31. const res = await fetchJson<LiveChannelListResponse>(`/api/channel/live-list?limit=${LIVE_PAGE_SIZE}&offset=0`, { method: 'GET' });
  32. if (!res.success || !res.data) {
  33. return { channels: [], total: 0 };
  34. }
  35. return { channels: res.data.channels, total: res.data.total };
  36. }
  37. async function loadWorldIndices(): Promise<WorldIndexRow[]> {
  38. // 백엔드 미기동/데이터 없음이어도 홈은 렌더 — 지도는 데이터 있을 때만 표시
  39. const res = await fetchWorldIndices();
  40. if (!res.success || !res.data) {
  41. return [];
  42. }
  43. return res.data.list;
  44. }
  45. async function loadMarketQuotes(): Promise<MarketQuoteRow[]> {
  46. // 백엔드 미기동/데이터 없음이어도 홈은 렌더 — 그리드는 데이터 있을 때만 표시
  47. const res = await fetchMarketQuotes();
  48. if (!res.success || !res.data) {
  49. return [];
  50. }
  51. return res.data.list;
  52. }
  53. async function loadDomesticSummary(): Promise<DomesticIndexRow[]> {
  54. const res = await fetchDomesticSummary();
  55. if (!res.success || !res.data) {
  56. return [];
  57. }
  58. return res.data.list;
  59. }
  60. export default async function Home() {
  61. // 채널 기능 OFF: 라이브 채널 섹션 미노출이므로 조회 생략
  62. const [banners, live, worldIndices, marketQuotes, domesticSummary] = await Promise.all([
  63. loadActiveBanners(),
  64. FEATURE_CHANNEL ? loadLiveChannels() : Promise.resolve({ channels: [], total: 0 }),
  65. loadWorldIndices(),
  66. loadMarketQuotes(),
  67. loadDomesticSummary()
  68. ]);
  69. return (
  70. <div className="home">
  71. <div className="home__inner">
  72. {worldIndices.length > 0 && <WorldMarketMap rows={worldIndices} />}
  73. {domesticSummary.length > 0 && <DomesticSummary rows={domesticSummary} />}
  74. {marketQuotes.length > 0 && <MajorQuotesGrid rows={marketQuotes} />}
  75. <HomeBannerCarousel items={banners} />
  76. {FEATURE_CHANNEL && (
  77. live.channels.length === 0 ? (
  78. <LiveChannelEmpty />
  79. ) : (
  80. <LiveChannelGrid
  81. initialChannels={live.channels}
  82. initialTotal={live.total}
  83. pageSize={LIVE_PAGE_SIZE}
  84. />
  85. )
  86. )}
  87. </div>
  88. </div>
  89. );
  90. }