From c29914f240f3b901ba4429c25adbe9aafb325698 Mon Sep 17 00:00:00 2001 From: Benson Wally Tran Date: Sat, 18 Nov 2023 20:32:45 -0600 Subject: [PATCH] todos for patricio to add images --- components/generate/GenerateStoryContext.tsx | 42 +++++++++++--------- components/pdf/StoryPDFViewer.tsx | 2 + operations/chatOperations.ts | 7 ++++ 3 files changed, 32 insertions(+), 19 deletions(-) diff --git a/components/generate/GenerateStoryContext.tsx b/components/generate/GenerateStoryContext.tsx index 3f1814472..251161cd5 100644 --- a/components/generate/GenerateStoryContext.tsx +++ b/components/generate/GenerateStoryContext.tsx @@ -1,45 +1,49 @@ 'use client'; import chatOperations, { IStory } from 'operations/chatOperations'; -import { PropsWithChildren, createContext, useContext, useMemo, useState } from 'react'; +import { + PropsWithChildren, + createContext, + useCallback, + 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] - ); + const value = useMemo(() => ({ story, loading }), [story, loading]); + + /* + TODO(Benson -> Patricio): Make network call to get images + TODO(Benson -> Patricio): Write a helper function in this directory /generate/utils.ts + called mergeImages(story: IStory, images: string[]): IStory; + */ + const getStoryAsync = useCallback(async () => { + setLoading(true); + const story = await chatOperations.createStoryAsync(); + // const images = await imageOperations.getStoryImagesAsync(story); + setStory(story); + setLoading(false); + }, []); return ( <>