@@ -4,32 +4,58 @@ import { Inter } from "next/font/google";
44import { useState } from "react" ;
55
66import "./globals.css" ;
7- import { ThemeType , ThemeProviderValue } from "@/app/type" ;
7+ import { ThemeType , RegisterType } from "@/app/type" ;
88import { ThemeContext } from "@/app/context" ;
9+ import { UserContext , UserContextValue } from "@/app/UserContext" ;
10+
11+ import { User } from "@/app/utils/user" ;
912
1013const inter = Inter ( { subsets : [ "latin" ] } ) ;
1114
1215/**
1316 * RootLayout コンポーネントは、アプリケーション全体のレイアウトを定義します。
14- * @param props - コンポーネントのプロパティ。
15- * @param props.children - レイアウト内に表示する子要素。
16- * @returns HTMLドキュメントのルート要素としてのJSX要素。
17+ *
18+ * - テーマ(light/dark)の切り替え機能を提供します。
19+ * - ユーザー情報を管理し、アプリ全体で利用可能にします。
20+ * @param props コンポーネントのプロパティ
21+ * @param props.children レイアウト内に表示する子要素
22+ * @returns HTMLドキュメントのルート要素としてのJSX要素
1723 */
1824export default function RootLayout ( {
1925 children,
2026} : Readonly < {
2127 children : React . ReactNode ;
2228} > ) {
29+ /**
30+ * テーマ管理
31+ */
2332 const [ theme , setTheme ] = useState < ThemeType > ( "light" ) ;
33+
34+ const userInstance = new User ( ) ;
35+ const [ user , setUserState ] = useState < RegisterType | undefined > (
36+ userInstance . getUser ( ) ,
37+ ) ;
38+
39+ const setUser = ( newUser : RegisterType ) => {
40+ userInstance . setUser ( newUser ) ;
41+ setUserState ( newUser ) ;
42+ } ;
43+
44+ const userContextValue : UserContextValue = {
45+ user,
46+ setUser,
47+ } ;
48+
2449 return (
25- // ライト/ダークモードで背景色と文字色を変更
26- < ThemeContext . Provider value = { { theme : theme , setTheme : setTheme } } >
27- < html
28- lang = "ja"
29- className = { `bg-surface-container text-text-default ${ theme } ` }
30- >
31- < body className = { inter . className } > { children } </ body >
32- </ html >
50+ < ThemeContext . Provider value = { { theme, setTheme } } >
51+ < UserContext . Provider value = { userContextValue } >
52+ < html
53+ lang = "ja"
54+ className = { `bg-surface-container text-text-default ${ theme } ` }
55+ >
56+ < body className = { inter . className } > { children } </ body >
57+ </ html >
58+ </ UserContext . Provider >
3359 </ ThemeContext . Provider >
3460 ) ;
3561}
0 commit comments