forked from programandopy/hackathon-desafio-ai
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.jsx
54 lines (50 loc) · 1.59 KB
/
App.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import MapComponent from "./components/Map.jsx";
import { Loading } from "./components/Loading.jsx";
import openaiService from "./services/openai.js";
import Chatbot from "./components/Chatbot.jsx";
import { useState } from "react";
const App = () => {
// const [loading, setLoading] = useState(true);
const [places, setPlaces] = useState([{}]);
const [response, setResponse] = useState("");
const [limited, setLimited] = useState(false);
const [loading, setLoading] = useState(false);
const fetchPlaces = async (prompt) => {
try {
setLoading(true);
const { parsedPlaces, chatResponse } = await openaiService.getPlaces(
prompt,
limited
);
console.log(parsedPlaces, chatResponse);
setResponse(chatResponse);
setPlaces(parsedPlaces);
} catch (error) {
console.error("Error fetching places:", error);
setResponse("Algo salió mal, por favor intenta de nuevo.");
} finally {
setLoading(false);
}
};
return (
<div className="App h-screen flex bg-gradient-to-r from-blue-400 to-green-600">
<div className="flex flex-1">
<div className="w-2/3 p-4 h-full">
<MapComponent locations={places ? places : []} />
</div>
<div className="w-1/3 p-4 h-full">
<Chatbot
fetchPlaces={fetchPlaces}
setLimited={setLimited}
limited={limited}
loading={loading}
response={response}
chatMessage={response}
setPlaces={setPlaces}
/>
</div>
</div>
</div>
);
};
export default App;