69 lines
1.9 KiB
TypeScript
69 lines
1.9 KiB
TypeScript
/**
|
|
* Polderfest 2027 — chat pagina
|
|
* --------------------------------------------------
|
|
* Les 11 — useChat hook + Tailwind chat UI.
|
|
* Plaats dit bestand op: app/chat/page.tsx
|
|
*
|
|
* Werking:
|
|
* - useChat() regelt messages, input, submit-handler, streaming
|
|
* - Praat met /api/chat (de route.ts)
|
|
* - Disabled tijdens streaming
|
|
*
|
|
* Vereist:
|
|
* - app/api/chat/route.ts (zie route.ts)
|
|
* - npm i ai
|
|
* - Tailwind aanwezig in project (standaard in create-next-app)
|
|
*/
|
|
|
|
"use client";
|
|
|
|
import { useChat } from "ai/react";
|
|
|
|
export default function ChatPage() {
|
|
const { messages, input, handleInputChange, handleSubmit, status } =
|
|
useChat();
|
|
|
|
return (
|
|
<main className="max-w-2xl mx-auto p-6 flex flex-col h-screen">
|
|
<h1 className="text-2xl font-bold mb-4">
|
|
Polderfest 2027 — vraag de AI
|
|
</h1>
|
|
|
|
<div className="flex-1 overflow-y-auto space-y-4 mb-4">
|
|
{messages.map((m) => (
|
|
<div
|
|
key={m.id}
|
|
className={
|
|
m.role === "user"
|
|
? "bg-blue-50 p-3 rounded-lg ml-12"
|
|
: "bg-gray-50 p-3 rounded-lg mr-12"
|
|
}
|
|
>
|
|
<div className="font-medium text-sm text-gray-500 mb-1">
|
|
{m.role === "user" ? "Jij" : "Festival AI"}
|
|
</div>
|
|
<div className="whitespace-pre-wrap">{m.content}</div>
|
|
</div>
|
|
))}
|
|
</div>
|
|
|
|
<form onSubmit={handleSubmit} className="flex gap-2">
|
|
<input
|
|
value={input}
|
|
onChange={handleInputChange}
|
|
placeholder="Stel een vraag over de line-up..."
|
|
className="flex-1 p-3 border rounded-lg"
|
|
disabled={status !== "ready"}
|
|
/>
|
|
<button
|
|
type="submit"
|
|
disabled={status !== "ready"}
|
|
className="px-6 py-3 bg-blue-600 text-white rounded-lg disabled:opacity-50"
|
|
>
|
|
Stuur
|
|
</button>
|
|
</form>
|
|
</main>
|
|
);
|
|
}
|