Header.tsx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. 'use client';
  2. import Styles from '../styles/layout.module.scss';
  3. import { useCallback } from 'react';
  4. import Link from 'next/link';
  5. import { usePathname } from 'next/navigation';
  6. import useAuth from '@/hooks/useAuth';
  7. import useDragScroll from '@/hooks/useDragScroll';
  8. import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
  9. import { faBars, faXmark, faCartShopping, faChevronLeft, faChevronRight } from '@fortawesome/free-solid-svg-icons';
  10. import NotificationBell from '@/app/component/NotificationBell';
  11. import HeaderSearch from '@/app/component/HeaderSearch';
  12. import SearchCommand from '@/app/component/SearchCommand';
  13. import Profile from '@/app/component/Profile';
  14. import Logo from '@/app/component/Logo';
  15. import PointChargeIcon from '@/public/icons/layout/point.svg';
  16. import useCart from '@/hooks/useCart';
  17. import { FEATURE_CHANNEL } from '@/constants/features';
  18. // 채널/방송 메뉴(생방송·크리에이터)는 채널 기능 ON 일 때만 노출
  19. const channelNavItems = [
  20. { href: '/live', label: '생방송' },
  21. { href: '/creators', label: '크리에이터' }
  22. ];
  23. const baseNavItems = [
  24. { href: '/market', label: '시장' },
  25. { href: '/stock', label: '종목' },
  26. { href: '/paper', label: '모의투자' },
  27. { href: '/games', label: '게임' },
  28. { href: '/board/briefing', label: '장전 시황' },
  29. { href: '/board/proof', label: '수익인증' },
  30. { href: '/feed/all', label: '피드' },
  31. { href: '/store', label: '상점' },
  32. { href: '/attendance', label: '출석부' },
  33. { href: '/board/notice', label: '고객지원' }
  34. ];
  35. const navItems = FEATURE_CHANNEL ? [...channelNavItems, ...baseNavItems] : baseNavItems;
  36. const SCROLL_AMOUNT = 120;
  37. type Props = {
  38. sidebarOpen: boolean;
  39. onToggle: () => void;
  40. // 좌측 사이드바 노출 여부 — false 면 모바일 햄버거(사이드바 토글)도 숨김
  41. showAside?: boolean;
  42. };
  43. export default function Header({ sidebarOpen, onToggle, showAside = true }: Props)
  44. {
  45. const { isAuthenticated } = useAuth();
  46. const { totalCount: cartCount } = useCart();
  47. const pathname = usePathname();
  48. const dragScroll = useDragScroll<HTMLDivElement>();
  49. const scrollTabs = useCallback((dir: 'left' | 'right') => {
  50. const el = dragScroll.ref.current;
  51. if (!el) {
  52. return;
  53. }
  54. el.scrollBy({ left: dir === 'left' ? -SCROLL_AMOUNT : SCROLL_AMOUNT, behavior: 'smooth' });
  55. }, [dragScroll.ref]);
  56. const handlePopupCharge = useCallback(() => {
  57. const w = 450, h = 635;
  58. const left = window.screenX + (window.outerWidth - w) / 2;
  59. const top = window.screenY + (window.outerHeight - h) / 2;
  60. window.open('/charge', 'charge', `width=${w},height=${h},left=${left},top=${top},scrollbars=no,resizable=no`);
  61. }, []);
  62. return (
  63. <header id='header' className={Styles.header}>
  64. {/* 1줄: 로고 + 우측 아이콘 (PC에서는 전체 내비) */}
  65. <div className={Styles.headerRow1}>
  66. {/* 햄버거 — 좌측 사이드바(채널 or 관심종목) 슬라이드 토글 (모바일 전용). 사이드바 없는 페이지에선 미표시 */}
  67. {showAside && (
  68. <button type='button' className={Styles.hamburger} onClick={onToggle} aria-label='메뉴' aria-expanded={sidebarOpen}>
  69. <FontAwesomeIcon icon={sidebarOpen ? faXmark : faBars} />
  70. </button>
  71. )}
  72. <Link href='/' className={Styles.logo} aria-label="개미투자 홈">
  73. <Logo size="sm" />
  74. </Link>
  75. {/* PC 내비게이션 */}
  76. <nav className={Styles.pcNav} aria-label='주요 메뉴'>
  77. <ul className='flex gap-4'>
  78. {navItems.map(item => (
  79. <li key={item.label}>
  80. <Link href={item.href}>{item.label}</Link>
  81. </li>
  82. ))}
  83. </ul>
  84. </nav>
  85. {/* 중앙 통합 검색 — 디바운스 suggest + combobox (Ctrl+K/'/' 포커스 포함) */}
  86. <HeaderSearch />
  87. {/* 우측 아이콘 (항상 표시) */}
  88. <div className={Styles.headerActions}>
  89. <Link href="/cart" className={Styles.cartBtn} title="장바구니" aria-label="장바구니">
  90. <FontAwesomeIcon icon={faCartShopping} />
  91. {cartCount > 0 && (
  92. <span className={Styles.cartBadge}>{cartCount > 99 ? '99+' : cartCount}</span>
  93. )}
  94. </Link>
  95. {isAuthenticated && (
  96. <>
  97. <button type="button" className={Styles.chargeBtn} onClick={handlePopupCharge} title="캐시 충전">
  98. <PointChargeIcon width={24} height={24} />
  99. </button>
  100. <NotificationBell />
  101. </>
  102. )}
  103. <Profile />
  104. </div>
  105. </div>
  106. {/* 2줄: 모바일 전용 가로 스크롤 탭 */}
  107. <nav className={Styles.headerRow2} aria-label='주요 메뉴 (모바일)'>
  108. <button type='button' className={Styles.scrollArrow} onClick={() => scrollTabs('left')} aria-label='왼쪽 스크롤'>
  109. <FontAwesomeIcon icon={faChevronLeft} />
  110. </button>
  111. <div
  112. className={Styles.mobileTabScroll}
  113. ref={dragScroll.ref}
  114. onMouseDown={dragScroll.onMouseDown}
  115. onMouseMove={dragScroll.onMouseMove}
  116. onMouseUp={dragScroll.onMouseUp}
  117. onMouseLeave={dragScroll.onMouseLeave}
  118. >
  119. {navItems.map(item => (
  120. <Link
  121. key={item.label}
  122. href={item.href}
  123. className={`${Styles.mobileTab}${pathname === item.href || (item.href !== '/' && pathname.startsWith(item.href)) ? ` ${Styles.mobileTabActive}` : ''}`}
  124. >
  125. {item.label}
  126. </Link>
  127. ))}
  128. </div>
  129. <button type='button' className={Styles.scrollArrow} onClick={() => scrollTabs('right')} aria-label='오른쪽 스크롤'>
  130. <FontAwesomeIcon icon={faChevronRight} />
  131. </button>
  132. </nav>
  133. {/* 지수 티커 스트립 — TradingView 임베드 컨테이너 (규격만, 내용 주입 전까지 :empty 로 미표시) */}
  134. <div id='header-ticker' className={Styles.tickerStrip} aria-hidden='true' />
  135. {/* Ctrl+K / ⌘K 커맨드 팔레트 — 전역 (렌더 없음, 열릴 때만 표시) */}
  136. <SearchCommand />
  137. </header>
  138. );
  139. }