import { Textarea } from "@chakra-ui/react"; import { useRef, useState } from "react"; import useSWRMutation from "swr/mutation"; import useSWRImmutable from "swr/immutable"; import fetcher from "src/lib/fetcher"; import poster from "src/lib/poster"; import { Messages } from "src/components/Messages"; import { TwoColumns } from "src/components/TwoColumns"; import { Button } from "src/components/Button"; const UserReply = () => { const [tasks, setTasks] = useState([]); const inputRef = useRef(null); const { isLoading } = useSWRImmutable("/api/new_task/user_reply", fetcher, { onSuccess: (data) => { console.log(data); setTasks([data]); }, }); const { trigger, isMutating } = useSWRMutation("/api/update_task", poster, { onSuccess: async (data) => { const newTask = await data.json(); setTasks((oldTasks) => [...oldTasks, newTask]); }, }); const submitResponse = (task: { id: string }) => { const text = inputRef.current.value.trim(); trigger({ id: task.id, update_type: "text_reply_to_post", content: { text, }, }); }; /** * TODO: Make this a nicer loading screen. */ if (tasks.length == 0) { return
Loading...
; } const task = tasks[0].task; return (
<>
Reply as a user

Given the following conversation, provide an adequate reply

{task.hint &&

Hint: {task.hint}

}