crush-level-web/src/app/(main)/user/[userId]/context/aiUser/index.tsx

46 lines
1.2 KiB
TypeScript
Raw Normal View History

2025-11-13 08:38:25 +00:00
"use client";
import { AiUserBaseOutput } from "@/services/user";
import { createContext } from "react";
import { useGetAIUserBaseInfo } from "@/hooks/aiUser";
import { useParams } from "next/navigation";
import { useCurrentUser } from "@/hooks/auth";
import Empty from "@/components/ui/empty";
export * from "./useAIUser";
const AIUserContext = createContext<{
user: AiUserBaseOutput | undefined;
isOwner: boolean;
userId: number | undefined;
}>({
user: undefined,
isOwner: false,
userId: undefined,
});
export const AIUserProvider = ({ children }: { children: React.ReactNode }) => {
const { userId } = useParams();
const { data, error } = useGetAIUserBaseInfo({ aiId: Number(userId) });
const { data: currentUser } = useCurrentUser();
const isOwner = currentUser?.userId === data?.userId;
if (error) {
return (
<div className="w-full h-full flex justify-center items-center">
<Empty title="Oops, theres nothing here…" />
</div>
)
}
return (
<AIUserContext.Provider value={{ user: data, isOwner, userId: Number(userId) }}>
{children}
</AIUserContext.Provider>
);
}
export default AIUserContext;