Header.tsx 5.1 KB

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