'use-client'; import Image from 'next/image'; import chatOperations from 'operations/chatOperations'; import imageOperations from 'operations/imageOperations'; import { useState } from 'react'; import GenerateStoryContextProvider, { IGenerateStoryContext } from './GenerateStoryContext'; export default function GenerateStoryComponent() { const [loading, setLoading] = useState(false); const [data, setData] = useState(); const [cover, setCover] = useState(''); const getStory = async () => { setLoading(true); const data = await chatOperations.createStoryAsync(); setData(data); setLoading(false); }; const getCover = async () => { setLoading(true); const data = await imageOperations.createImageAsync( 'make a cover image of the best book in the world for children' ); const coverURL = data.text[0].url; setCover(coverURL); setLoading(false); }; return ( {({ story }: IGenerateStoryContext) => { return (
{loading ?
Loading...
: null} {cover && } {JSON.stringify(data)} {JSON.stringify(data)}
); }}
); }