Header.tsx 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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: '/chat', label: '채팅' },
  32. { href: '/store', label: '상점' },
  33. { href: '/attendance', label: '출석부' },
  34. { href: '/board/notice', label: '고객지원' }
  35. ];
  36. const navItems = FEATURE_CHANNEL ? [...channelNavItems, ...baseNavItems] : baseNavItems;
  37. const SCROLL_AMOUNT = 120;
  38. type Props = {
  39. sidebarOpen: boolean;
  40. onToggle: () => void;
  41. };
  42. export default function Header({ sidebarOpen, onToggle }: Props)
  43. {
  44. const { isAuthenticated } = useAuth();
  45. const { totalCount: cartCount } = useCart();
  46. const pathname = usePathname();
  47. const dragScroll = useDragScroll<HTMLDivElement>();
  48. const scrollTabs = useCallback((dir: 'left' | 'right') => {
  49. const el = dragScroll.ref.current;
  50. if (!el) {
  51. return;
  52. }
  53. el.scrollBy({ left: dir === 'left' ? -SCROLL_AMOUNT : SCROLL_AMOUNT, behavior: 'smooth' });
  54. }, [dragScroll.ref]);
  55. const handlePopupCharge = useCallback(() => {
  56. const w = 450, h = 635;
  57. const left = window.screenX + (window.outerWidth - w) / 2;
  58. const top = window.screenY + (window.outerHeight - h) / 2;
  59. window.open('/charge', 'charge', `width=${w},height=${h},left=${left},top=${top},scrollbars=no,resizable=no`);
  60. }, []);
  61. return (
  62. <header id='header' className={Styles.header}>
  63. {/* 1줄: 로고 + 우측 아이콘 (PC에서는 전체 내비) */}
  64. <div className={Styles.headerRow1}>
  65. {/* 햄버거 — 좌측 사이드바(채널 or 관심종목 자리표시) 슬라이드 토글 (모바일 전용) */}
  66. <button type='button' className={Styles.hamburger} onClick={onToggle} aria-label='메뉴' aria-expanded={sidebarOpen}>
  67. <FontAwesomeIcon icon={sidebarOpen ? faXmark : faBars} />
  68. </button>
  69. <Link href='/' className={Styles.logo} aria-label="개미투자 홈">
  70. <Logo size="sm" />
  71. </Link>
  72. {/* PC 내비게이션 */}
  73. <nav className={Styles.pcNav} aria-label='주요 메뉴'>
  74. <ul className='flex gap-4'>
  75. {navItems.map(item => (
  76. <li key={item.label}>
  77. <Link href={item.href}>{item.label}</Link>
  78. </li>
  79. ))}
  80. </ul>
  81. </nav>
  82. {/* 중앙 통합 검색 — 디바운스 suggest + combobox (Ctrl+K/'/' 포커스 포함) */}
  83. <HeaderSearch />
  84. {/* 우측 아이콘 (항상 표시) */}
  85. <div className={Styles.headerActions}>
  86. <Link href="/cart" className={Styles.cartBtn} title="장바구니" aria-label="장바구니">
  87. <FontAwesomeIcon icon={faCartShopping} />
  88. {cartCount > 0 && (
  89. <span className={Styles.cartBadge}>{cartCount > 99 ? '99+' : cartCount}</span>
  90. )}
  91. </Link>
  92. {isAuthenticated && (
  93. <>
  94. <button type="button" className={Styles.chargeBtn} onClick={handlePopupCharge} title="캐시 충전">
  95. <PointChargeIcon width={24} height={24} />
  96. </button>
  97. <NotificationBell />
  98. </>
  99. )}
  100. <Profile />
  101. </div>
  102. </div>
  103. {/* 2줄: 모바일 전용 가로 스크롤 탭 */}
  104. <nav className={Styles.headerRow2} aria-label='주요 메뉴 (모바일)'>
  105. <button type='button' className={Styles.scrollArrow} onClick={() => scrollTabs('left')} aria-label='왼쪽 스크롤'>
  106. <FontAwesomeIcon icon={faChevronLeft} />
  107. </button>
  108. <div
  109. className={Styles.mobileTabScroll}
  110. ref={dragScroll.ref}
  111. onMouseDown={dragScroll.onMouseDown}
  112. onMouseMove={dragScroll.onMouseMove}
  113. onMouseUp={dragScroll.onMouseUp}
  114. onMouseLeave={dragScroll.onMouseLeave}
  115. >
  116. {navItems.map(item => (
  117. <Link
  118. key={item.label}
  119. href={item.href}
  120. className={`${Styles.mobileTab}${pathname === item.href || (item.href !== '/' && pathname.startsWith(item.href)) ? ` ${Styles.mobileTabActive}` : ''}`}
  121. >
  122. {item.label}
  123. </Link>
  124. ))}
  125. </div>
  126. <button type='button' className={Styles.scrollArrow} onClick={() => scrollTabs('right')} aria-label='오른쪽 스크롤'>
  127. <FontAwesomeIcon icon={faChevronRight} />
  128. </button>
  129. </nav>
  130. {/* 지수 티커 스트립 — TradingView 임베드 컨테이너 (규격만, 내용 주입 전까지 :empty 로 미표시) */}
  131. <div id='header-ticker' className={Styles.tickerStrip} aria-hidden='true' />
  132. {/* Ctrl+K / ⌘K 커맨드 팔레트 — 전역 (렌더 없음, 열릴 때만 표시) */}
  133. <SearchCommand />
  134. </header>
  135. );
  136. }