Skip to main content
Glama

Storyden

by Southclaws
Mozilla Public License 2.0
229
useReply.ts1.79 kB
import { zodResolver } from "@hookform/resolvers/zod"; import { useState } from "react"; import { useForm } from "react-hook-form"; import { z } from "zod"; import { Reply, Thread } from "src/api/openapi-schema"; import { handle } from "@/api/client"; import { useThreadMutations } from "@/lib/thread/mutation"; export const FormSchema = z.object({ body: z.string().min(1, "Reply is empty."), }); export type Form = z.infer<typeof FormSchema>; export type Props = { thread: Thread; reply: Reply; }; export function useReply({ thread, reply }: Props) { const { revalidate, updateReply } = useThreadMutations(thread); const [resetKey, setResetKey] = useState(""); const [isEditing, setEditing] = useState(false); const [isEmpty, setEmpty] = useState(true); const form = useForm<Form>({ resolver: zodResolver(FormSchema), defaultValues: { body: reply.body, }, }); function handleEmptyStateChange(isEmpty: boolean) { setEmpty(isEmpty); } function handleSetEditing() { setEditing(true); } function handleDiscardChanges() { // TODO: useConfirmation form.reset(reply); setEditing(false); setResetKey(Date.now().toString()); } const handleSave = form.handleSubmit(async (data) => { await handle( async () => { await updateReply(reply.id, data); setEditing(false); form.reset(data); }, { promiseToast: { loading: "Saving...", success: "Saved!", }, cleanup: async () => { await revalidate(); }, }, ); }); return { isEmpty, isEditing, resetKey, form, handlers: { handleSetEditing, handleEmptyStateChange, handleDiscardChanges, handleSave, }, }; }

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Southclaws/storyden'

If you have feedback or need assistance with the MCP directory API, please join our Discord server