Skip to content

Commit

Permalink
loading animation when generating trip titles
Browse files Browse the repository at this point in the history
  • Loading branch information
sam9116 committed Dec 8, 2024
1 parent e82c646 commit d7a4477
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
1 change: 0 additions & 1 deletion src/Odyssey/FetchName.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export const FetchName = async (concerts) => {
body: JSON.stringify(concerts),
}
);
console.log(`response status code: ${response.status}`);
if (response.status === 200) {
let resJson = await response.json();
return resJson;
Expand Down
32 changes: 17 additions & 15 deletions src/Odyssey/SharePage.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React from 'react';
import { Stack, TextField, Button } from '@mui/material';
import React, { useState } from 'react';
import { Stack, TextField, Button, CircularProgress } from '@mui/material';
import Map from "./map";
import { useLoadScript } from "@react-google-maps/api"
import SharePageList from './SharePageList';
import { FetchName } from './FetchName.js';

const SharePage = ({ concerts, userLocation, mapStyle, setPosterName, posterName, posterNameSuggestions, setPosterNameSuggestions }) => {


const [isLoading, setIsLoading] = useState(false);
// Your component logic goes here
const { isLoaded } = useLoadScript({
googleMapsApiKey: process.env.REACT_APP_GCP_KEY, // Add your API key
Expand All @@ -23,17 +23,17 @@ const SharePage = ({ concerts, userLocation, mapStyle, setPosterName, posterName
// send a request to openAI
// attach the conerts, but strip the GPS data, that is not very useful for suggesting trip titles
// New list with only 'title', 'artist', 'venue', 'city' and 'date' fields
console.log("getting new titles");
const newList = concerts.map(({ title, artist, location, date }) => ({ title, artist, date, venue: location.name, city: location.address }));
setIsLoading(true);
// now make a request and send it to open AI
var suggestions = await FetchName(newList);
if (suggestions.length >= 1)
{
if (suggestions.length >= 1) {
setPosterName(suggestions[0].title);
}
if (suggestions.length >= 2) {
setPosterNameSuggestions(suggestions.slice(1));
}
}
setIsLoading(false);
}
else {
setPosterName(posterNameSuggestions[0].title);
Expand All @@ -46,17 +46,19 @@ const SharePage = ({ concerts, userLocation, mapStyle, setPosterName, posterName
<Stack disablePadding spacing={3}>
{isLoaded ? <Map concerts={concerts} userLocation={userLocation} mapStyle={mapStyle} /> : null}
<Stack spacing={2} direction={'row'} sx={{ width: '100%' }}>
<TextField
variant="standard"
placeholder="Write a cool name for your trip here"
InputProps={{ sx: { 'input': { textAlign: 'center', color: 'white' } } }}
value={posterName}
onChange={(e) => setPosterName(e.target.value)}
sx={{ flex: 1 }} />
{isLoading ? <Stack direction={"column"} sx={{ flex: 1 }} > <CircularProgress size={24} /> </Stack> :
<TextField
variant="standard"
placeholder="Write a cool name for your trip here"
InputProps={{ sx: { 'input': { textAlign: 'center', color: 'white' } } }}
value={posterName}
onChange={(e) => setPosterName(e.target.value)}
sx={{ flex: 1 }} />}
<Button
color="primary"
onClick={GenerateTripTitle}
disabled={concerts.length === 0}
disabled={(concerts.length === 0 || isLoading)}
justifyContent="flex-end"
variant="contained">
Generate
</Button>
Expand Down

0 comments on commit d7a4477

Please sign in to comment.