Header.tsx 5.2 KB

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