Skip to content

Commit

Permalink
Clear results button
Browse files Browse the repository at this point in the history
  • Loading branch information
mshumayl committed Mar 20, 2023
1 parent ee2f8a9 commit b4bd988
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/components/PromptInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,22 @@ const PromptInput: FC = ({ }) => {
const submitApi = api.openai.submitPrompt.useMutation();

const handleSubmit = async (e: FormEvent<HTMLFormElement>) => {

setDisplayLoader((prevState) => !prevState);
e.preventDefault();
console.log(inputValue);
console.log(displayLoader);

// eslint-disable-next-line @typescript-eslint/no-unsafe-return
const res = await submitApi.mutateAsync({ userPrompt: inputValue });
// console.log(res);
const json = JSON.parse(res.response.replace(/[\n\r]/g, ''));
// console.log(json);

setAiResponse(json);
setDisplayLoader((prevState) => !prevState);
console.log(displayLoader);
}

const handleClear = () => {
setAiResponse(defaultResponse);
}

useEffect(() => {
setInputLength(inputValue.length);
}, [inputValue]);
Expand Down Expand Up @@ -90,11 +89,16 @@ const PromptInput: FC = ({ }) => {
Submit
</button>
</form>

{(aiResponse.length === 3)
? (<button onClick={handleClear} className="underline underline-offset-2 flex flex-col items-center text-sm font-zilla-slab-italic hover:text-gray-500">Clear results</button>)
: (<></>)}

<ul className="flex flex-col items-center w-full">
{/* Check if aiResponse is a valid array of objects before mapping. */}
{aiResponse && aiResponse.map && aiResponse.map(({ surah, verse }) => {
return ((displayLoader)
? (<div key={`${surah}_${verse}`} className="animate-ping font-zilla-slab-italic text-xs h-max w-max text-slate-500 my-4 rounded-lg bg-slate-200 py-1 px-2">Thinking...</div>)
? (<div key={`${surah}_${verse}`} className="animate-ping font-zilla-slab-italic text-xs h-max w-max text-slate-500 my-4 rounded-lg bg-slate-200 mt-10 py-1 px-2">Thinking...</div>)
: (surah !== 0)
? (<VerseCard surah={surah} verse={verse}/>)
: (<></>)
Expand Down

1 comment on commit b4bd988

@vercel
Copy link

@vercel vercel bot commented on b4bd988 Mar 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ai-daleel – ./

ai-daleel.vercel.app
ai-daleel-mshumayl.vercel.app
ai-daleel-git-main-mshumayl.vercel.app

Please sign in to comment.