Skip to content

Commit

Permalink
added result
Browse files Browse the repository at this point in the history
  • Loading branch information
Aryankpoor committed Jul 13, 2024
1 parent c538603 commit 57a4d88
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
20 changes: 16 additions & 4 deletions src/components/Main/Main.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
import React from 'react'
import React, { useContext } from 'react'
import './Main.css'
import { assets } from '../../assets/assets'
import { Context } from '../../context/Context'

const Main = () => {

const {onSent,recentPrompt,showResult,loading,resultData,input,setInput} = useContext(Context);

return (
<div className='main'>
<div className="nav">
<p>Core Assistant Inspired by Gemini</p>
<img src={assets.user_icon} alt="" />
</div>


<div className="main-container">
<div className="greet">

{!showResult
?<>
<div className="greet">
<p><span>Hello, Traveller</span></p>
<p>How can I help you today?</p>
</div>
Expand All @@ -32,14 +41,17 @@ const Main = () => {
<img src={assets.code_icon} alt="" />
</div>
</div>
</>:<div className='result'>
</div>}


<div className="main-bottom">
<div className="search-box">
<input type="text" placeholder="Enter a prompt here" />
<input type="text" onChange={(e)=>setInput(e.target.value)} value={input} placeholder="Enter a prompt here" />
<div>
<img src={assets.gallery_icon} alt="" />
<img src={assets.mic_icon} alt="" />
<img src={assets.send_icon} alt="" />
<img src={assets.send_icon} onClick={()=>onSent()} alt="" />
</div>
</div>
<p className="bottom-info">Made using Gemini Api. Core may display inaccurate info, including about people, so double-check it's responses</p>
Expand Down
2 changes: 1 addition & 1 deletion src/config/gemini.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async function runChat(prompt) {
const result = await chat.sendMessage(prompt);
const response = result.response;
console.log(response.text());

return response.text();
}

export default runChat;
11 changes: 9 additions & 2 deletions src/context/Context.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createContext } from "react";
import { createContext, useState } from "react";
import runChat from "../config/gemini";

export const Context = createContext();
Expand All @@ -13,7 +13,14 @@ const ContextProvider = (props) => {
const [resultData,setResultData] = useState("");

const onSent = async (prompt) => {
await runChat(prompt)

setResultData("")
setLoading(true)
setShowResult(true)
const response = await runChat(input)
setResultData(response)
setLoading(false)
setInput('')
}


Expand Down

0 comments on commit 57a4d88

Please sign in to comment.