Skip to content

Commit

Permalink
Remove need of useChat for now
Browse files Browse the repository at this point in the history
  • Loading branch information
cristiandouce committed Oct 8, 2024
1 parent faa4254 commit 207abb1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
10 changes: 7 additions & 3 deletions app/chat/[id]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async function RootLayout({ children, params }: RootChatParams) {
return (
<ChatProvider chatId={params.id}>
<Header>
<ShareConversation user={user} />
<ShareConversation user={user} chatId={params.id} />
</Header>

<AI initialAIState={messages} conversationID={params.id}>
Expand Down Expand Up @@ -57,8 +57,12 @@ export default withCheckPermission(
// if any of the checks pass, allow access
return checks.some((allowed) => allowed);
},
onUnauthorized: () => (
<UnauthorizedError>The conversation does not exist or you are not authorized to access it.</UnauthorizedError>
onUnauthorized: ({ params }) => (
<ChatProvider chatId={params.id}>
<Header />

<UnauthorizedError>The conversation does not exist or you are not authorized to access it.</UnauthorizedError>
</ChatProvider>
),
},
RootLayout
Expand Down
6 changes: 0 additions & 6 deletions app/chat/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export default function Chat({ params }: { params: { id: string } }) {
const { continueConversation } = useActions();
const { user } = useUser();
const { scrollRef, messagesRef, visibilityRef } = useScrollAnchor();
const { setChatId } = useChat();

const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema),
Expand Down Expand Up @@ -72,11 +71,6 @@ export default function Chat({ params }: { params: { id: string } }) {
setConversation((currentConversation: ClientMessage[]) => [...currentConversation, message]);
};

useEffect(() => {
setChatId(params.id);
return () => setChatId();
}, [params.id, setChatId]);

return (
<main className="flex overflow-hidden h-full mx-auto pt-4" style={{ maxHeight: "calc(100vh - 56px)" }}>
<div className="h-full w-full overflow-hidden rounded-md">
Expand Down
6 changes: 2 additions & 4 deletions components/chat/share.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ import { Input } from "../ui/input";
import { ScrollArea } from "../ui/scroll-area";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../ui/select";
import { useToast } from "../ui/use-toast";
import { useChat } from "./context";

import type { Claims } from "@auth0/nextjs-auth0";
export interface ShareConversationProps {
user: Claims;
chatId: string | undefined;
}

interface PermissionBlockProps {
Expand Down Expand Up @@ -130,9 +130,7 @@ const formSchema = z.object({
role: z.enum(["Viewer", "Editor"]),
});

export function ShareConversation({ user }: ShareConversationProps) {
const { chatId } = useChat();

export function ShareConversation({ user, chatId }: ShareConversationProps) {
const [viewers, setViewers] = useState<{ email?: string }[]>([]);
const { isCopied, copyToClipboard } = useCopyToClipboard({ timeout: 2000 });
const [isLoading, setIsLoading] = useState(true);
Expand Down

0 comments on commit 207abb1

Please sign in to comment.