'use client'; import chatOperations, { IStory } from 'operations/chatOperations'; import { PropsWithChildren, createContext, useContext, useMemo, useState } from 'react'; export interface IGenerateStoryContext { story?: IStory; images: string[]; loading: boolean; } const GenerateStoryContext = createContext({ story: undefined, images: [], loading: false }); function GenerateStoryContextProvider({ children }: { children: PropsWithChildren }) { const [loading, setLoading] = useState(false); const [story, setStory] = useState(); /* Note(Benson): For now images is an array of urls where each index in the array corresponds to the page number. i.e., index 0 could be title, index 1 is the first page in pages, etc. */ const [images, setImages] = useState([]); const value = useMemo( () => ({ story, images, loading }), [story, images, loading] ); return ( <> {typeof children === 'function' ? children(value) : children} ); } export const useGenerateStoryContext = (): IGenerateStoryContext => useContext(GenerateStoryContext); export default GenerateStoryContextProvider;