import React, { useEffect, useState } from 'react'; import { LayoutTemplateIcon, LoaderCircleIcon } from 'lucide-react'; import { useCopilot } from '../../../context/copilot.context'; import type { PageTemplatePreset } from '../../../service/visibility/visibility.interface'; import { listPageTemplatePresets } from '../../../service/visibility/visibility.service'; /** * The page templates beside the conversation: the kinds of page Recomaze * knows how to write. Picking one asks for it in the chat rather than * starting a generation from a card - writing a page costs credits, and the * merchant should see what they are agreeing to in the answer above the * button. * * @param props - Component props. * @param props.onAsk - Put the request to the copilot. * @return The gallery. */ export function TemplatesPanel({ onAsk, }: { onAsk: (prompt: string) => void; }): React.ReactElement { const copilot = useCopilot(); const token: string = copilot.token; const clientId: string = copilot.clientId; const [presets, setPresets] = useState([]); const [isLoading, setIsLoading] = useState(true); useEffect(() => { if (!token || !clientId) return undefined; let stale = false; void listPageTemplatePresets(clientId, token) .then(list => { if (!stale) setPresets(list); }) .catch(() => undefined) .finally(() => { if (!stale) setIsLoading(false); }); return () => { stale = true; }; }, [token, clientId]); if (isLoading) { return (
Reading the templates...
); } if (presets.length === 0) { return (

No templates to show right now.

); } return ( ); }