diff --git a/src/app/layout.tsx b/src/app/layout.tsx index a00b485..2942914 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -9,6 +9,7 @@ import { Toaster } from "@/components/ui/sonner"; import { ThemeProvider } from "@/components/ui/theme-provider"; import AuthProvider from "@/provider/authProvider"; +import { UserProvider } from "@/provider/userProvider"; export const metadata: Metadata = { title: "Untitled", @@ -38,26 +39,28 @@ export default function RootLayout({ disableTransitionOnChange > - - - -
-
- -
-
- -
- -
- -
- - {children} -
+ + + + +
+
+ +
+
+ +
+ +
+ +
+ + {children} +
+
); -} \ No newline at end of file +} diff --git a/src/app/user/[userId]/page.tsx b/src/app/user/[userId]/page.tsx index c2cb1e9..95580dc 100644 --- a/src/app/user/[userId]/page.tsx +++ b/src/app/user/[userId]/page.tsx @@ -1,6 +1,7 @@ "use client"; import { useState } from "react"; +import { ChevronDown } from "lucide-react"; import { IconLink, @@ -21,12 +22,15 @@ import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; import UserTrack from "@/features/user/user-track"; import UserAlbum from "@/features/user/user-album"; import UserPlaylist from "@/features/user/user-playlist"; -import { ChevronDown } from "lucide-react"; + +import { useUser } from "@/provider/userProvider"; export default function UserPage() { const [activeTab, setActiveTab] = useState("track"); const [array, setArray] = useState("new"); + const { user } = useUser(); + const tabs = [ { id: "track", label: "트랙", icon: IconMusic, onClick: () => {} }, { id: "album", label: "앨범", icon: IconDisc, onClick: () => {} }, @@ -45,12 +49,12 @@ export default function UserPage() {
- + U
-
YANG RARO
+
{user?.name || "U"}
diff --git a/src/lib/axios.ts b/src/lib/axios.ts new file mode 100644 index 0000000..ccd7c11 --- /dev/null +++ b/src/lib/axios.ts @@ -0,0 +1,8 @@ +import axios from 'axios'; + +export const api = axios.create({ + baseURL: process.env.NEXT_PUBLIC_API_BASE_URL || '', + headers: { + 'Content-Type': 'application/json', + }, +}); \ No newline at end of file diff --git a/src/provider/userProvider.tsx b/src/provider/userProvider.tsx new file mode 100644 index 0000000..82ade2e --- /dev/null +++ b/src/provider/userProvider.tsx @@ -0,0 +1,64 @@ +"use client"; + +import { AxiosError } from "axios"; +import React, { createContext, useContext, useEffect, useState } from "react"; + +import { api } from "../lib/axios"; + +export interface Artist { + uuid: string; + name: string; + email: string; + artistImage: string; +} + +interface UserContextType { + user: Artist | null; + isLoading: boolean; + error: Error | null; +} + +const UserContext = createContext(undefined); + +export function UserProvider({ children }: { children: React.ReactNode }) { + const [user, setUser] = useState(null); + const [isLoading, setIsLoading] = useState(true); + const [error, setError] = useState(null); + + useEffect(() => { + const fetchUser = async () => { + try { + const { data } = await api.get("/artist"); + setUser(data); + } catch (err) { + if (err instanceof AxiosError) { + setError( + new Error( + err.response?.data?.message || "Failed to fetch user data" + ) + ); + } else { + setError(new Error("An unexpected error occurred")); + } + } finally { + setIsLoading(false); + } + }; + + fetchUser(); + }, []); + + return ( + + {children} + + ); +} + +export function useUser() { + const context = useContext(UserContext); + if (context === undefined) { + throw new Error("useUser must be used within a UserProvider"); + } + return context; +}