Layout.tsx 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. 'use client';
  2. import { useState, useCallback, useEffect } from 'react';
  3. import Link from 'next/link';
  4. import { usePathname, useRouter } from 'next/navigation';
  5. import Styles from '../styles/common.module.scss';
  6. import useAuth from '@/hooks/useAuth';
  7. import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
  8. import { faBars, faXmark, faCoins, faComments, faNewspaper, faHeadset, faUser, faRightToBracket, faSun, faMoon } from '@fortawesome/free-solid-svg-icons';
  9. import { faCommentDots, faClock } from '@fortawesome/free-regular-svg-icons';
  10. import useTheme from '@/hooks/useTheme';
  11. import ChatSidebar from '@/app/component/chat/ChatSidebar';
  12. type Props = {
  13. children: React.ReactNode;
  14. };
  15. export default function Layout({ children }: Props) {
  16. const { isAuthenticated, isLoading, logout } = useAuth();
  17. const { toggleTheme, isDark } = useTheme();
  18. const [sidebarOpen, setSidebarOpen] = useState(false);
  19. const [chatOpen, setChatOpen] = useState(false);
  20. const pathname = usePathname();
  21. const router = useRouter();
  22. const toggleSidebar = useCallback(() => {
  23. setSidebarOpen((prev) => !prev);
  24. }, []);
  25. const toggleChat = useCallback(() => {
  26. setChatOpen((prev) => !prev);
  27. }, []);
  28. const closeOverlay = useCallback(() => {
  29. setSidebarOpen(false);
  30. setChatOpen(false);
  31. }, []);
  32. const [currentTime, setCurrentTime] = useState('');
  33. useEffect(() => {
  34. const updateTime = () => {
  35. const now = new Date();
  36. setCurrentTime(
  37. `${String(now.getHours()).padStart(2, '0')}:${String(now.getMinutes()).padStart(2, '0')}:${String(now.getSeconds()).padStart(2, '0')}`
  38. );
  39. };
  40. updateTime();
  41. const timer = setInterval(updateTime, 1000);
  42. return () => clearInterval(timer);
  43. }, []);
  44. if (isLoading) {
  45. return <></>;
  46. }
  47. return (
  48. <>
  49. <div id='container' className={`${Styles.container}${sidebarOpen ? ` ${Styles.sidebarOpen}` : ''}${chatOpen ? ` ${Styles.chatOpen}` : ''}`}>
  50. {/* 상단 내용 */}
  51. <header id='header' className={`${Styles.header} flex items-center w-full px-4`}>
  52. <button type='button' className={Styles.hamburger} onClick={toggleSidebar} aria-label='메뉴'>
  53. <FontAwesomeIcon icon={sidebarOpen ? faXmark : faBars} />
  54. </button>
  55. <Link href='/' className={Styles.logo}>
  56. <picture>
  57. <source src="image.webp" type="image/webp" />
  58. <img src="/resources/logo.svg" alt="bitforum logo" />
  59. </picture>
  60. </Link>
  61. <nav className={Styles.pcNav}>
  62. <ul className='flex gap-4'>
  63. <li>
  64. <Link href='/'>
  65. 코인
  66. </Link>
  67. </li>
  68. <li>
  69. <Link href='/latest'>
  70. 토론
  71. </Link>
  72. </li>
  73. <li>
  74. <Link href='/news'>
  75. 뉴스
  76. </Link>
  77. </li>
  78. <li>
  79. <Link href='/board/notice'>
  80. 고객지원
  81. </Link>
  82. </li>
  83. </ul>
  84. <ul className='flex gap-4 items-center'>
  85. <li>
  86. <button type='button' onClick={toggleTheme} aria-label='다크모드 전환' title={isDark ? '라이트 모드' : '다크 모드'}>
  87. <FontAwesomeIcon icon={isDark ? faSun : faMoon} />
  88. </button>
  89. </li>
  90. <li className={`${Styles.clock} text-sm opacity-70`} style={{ fontVariantNumeric: 'tabular-nums' }}>
  91. <FontAwesomeIcon icon={faClock} className='mr-1' />{currentTime}
  92. </li>
  93. {!isAuthenticated ? (
  94. <>
  95. <li>
  96. <a href='/login'>
  97. 로그인
  98. </a>
  99. </li>
  100. <li>
  101. <a href='/register'>
  102. 회원가입
  103. </a>
  104. </li>
  105. </>
  106. ) : (
  107. <>
  108. <li>
  109. <Link href='/profile'>
  110. 내 정보
  111. </Link>
  112. </li>
  113. <li>
  114. <button type='button' onClick={logout}>
  115. 로그아웃
  116. </button>
  117. </li>
  118. </>
  119. )}
  120. </ul>
  121. </nav>
  122. <button type='button' className={Styles.chatToggle} onClick={toggleChat} aria-label='채팅'>
  123. <FontAwesomeIcon icon={faCommentDots} />
  124. </button>
  125. </header>
  126. {/* 모바일 오버레이 */}
  127. <div className={Styles.overlay} onClick={closeOverlay} />
  128. {/* 메인 내용 */}
  129. <main id='main' className={`${Styles.main} relative`}>
  130. {children}
  131. </main>
  132. {/* 우측 채팅 사이드바 */}
  133. <aside id='chatAside' className={Styles.chatAside}>
  134. <ChatSidebar />
  135. </aside>
  136. {/* 하단 내용 */}
  137. <footer id='footer' className={`${Styles.footer} px-4`}>
  138. <ol>
  139. <li>
  140. <Link href='/docs/teams'>이용약관</Link>
  141. </li>
  142. <li>
  143. <Link href='/docs/privacy'>개인정보처리방침</Link>
  144. </li>
  145. {/* 저작권 표시 */}
  146. <li>© 2025 PLAYR. All rights reserved.</li>
  147. </ol>
  148. </footer>
  149. {/* 모바일 하단 탭바 */}
  150. <nav className={Styles.bottomTab}>
  151. <button
  152. type='button'
  153. className={pathname === '/' ? Styles.active : undefined}
  154. onClick={() => {
  155. if (pathname === '/') {
  156. window.dispatchEvent(new CustomEvent('crypto:showList'));
  157. } else {
  158. router.push('/');
  159. }
  160. }}
  161. >
  162. <FontAwesomeIcon icon={faCoins} />
  163. <span>코인</span>
  164. </button>
  165. <Link href='/latest' className={pathname.startsWith('/latest') || (pathname.startsWith('/board') && !pathname.startsWith('/board/notice')) || pathname.startsWith('/post') ? Styles.active : undefined}>
  166. <FontAwesomeIcon icon={faComments} />
  167. <span>토론</span>
  168. </Link>
  169. <Link href='/news' className={pathname.startsWith('/news') ? Styles.active : undefined}>
  170. <FontAwesomeIcon icon={faNewspaper} />
  171. <span>뉴스</span>
  172. </Link>
  173. <Link href='/board/notice' className={pathname.startsWith('/board/notice') || pathname.startsWith('/support') ? Styles.active : undefined}>
  174. <FontAwesomeIcon icon={faHeadset} />
  175. <span>고객지원</span>
  176. </Link>
  177. {isAuthenticated ? (
  178. <Link href='/profile' className={pathname.startsWith('/profile') ? Styles.active : undefined}>
  179. <FontAwesomeIcon icon={faUser} />
  180. <span>내 정보</span>
  181. </Link>
  182. ) : (
  183. <a href='/login'>
  184. <FontAwesomeIcon icon={faRightToBracket} />
  185. <span>로그인</span>
  186. </a>
  187. )}
  188. </nav>
  189. </div>
  190. </>
  191. );
  192. }