diff --git a/package-lock.json b/package-lock.json index 426a028..bce8f99 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4906,6 +4906,28 @@ "resolved": "https://registry.npmjs.org/@types/node/-/node-20.4.5.tgz", "integrity": "sha512-rt40Nk13II9JwQBdeYqmbn2Q6IVTA5uPhvSO+JVqdXw/6/4glI6oR9ezty/A9Hg5u7JH4OmYmuQ+XvjKm0Datg==" }, + "node_modules/@types/node-fetch": { + "version": "2.6.12", + "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.12.tgz", + "integrity": "sha512-8nneRWKCg3rMtF69nLQJnOYUcbafYeFSjqkw3jCRLsqkWFlHaoQrr5mXmofFGOx3DKn7UfmBMyov8ySvLRVldA==", + "dependencies": { + "@types/node": "*", + "form-data": "^4.0.0" + } + }, + "node_modules/@types/node-fetch/node_modules/form-data": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.1.tgz", + "integrity": "sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/@types/node-forge": { "version": "1.3.11", "resolved": "https://registry.npmjs.org/@types/node-forge/-/node-forge-1.3.11.tgz", @@ -5437,6 +5459,17 @@ "integrity": "sha512-j2afSsaIENvHZN2B8GOpF566vZ5WVk5opAiMTvWgaQT8DkbOqsTfvNAvHoRGU2zzP8cPoqys+xHTRDWW8L+/BA==", "deprecated": "Use your platform's native atob() and btoa() methods instead" }, + "node_modules/abort-controller": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz", + "integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==", + "dependencies": { + "event-target-shim": "^5.0.0" + }, + "engines": { + "node": ">=6.5" + } + }, "node_modules/accepts": { "version": "1.3.8", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", @@ -5535,6 +5568,17 @@ "node": ">= 6.0.0" } }, + "node_modules/agentkeepalive": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/agentkeepalive/-/agentkeepalive-4.5.0.tgz", + "integrity": "sha512-5GG/5IbQQpC9FpkRGsSvZI5QYeSCzlJHdpBQntCsuTOxhKD8lqKhrleg2Yi7yvMIf82Ycmmqln9U8V9qwEiJew==", + "dependencies": { + "humanize-ms": "^1.2.1" + }, + "engines": { + "node": ">= 8.0.0" + } + }, "node_modules/ajv": { "version": "6.12.6", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", @@ -8764,6 +8808,14 @@ "node": ">= 0.6" } }, + "node_modules/event-target-shim": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz", + "integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==", + "engines": { + "node": ">=6" + } + }, "node_modules/eventemitter3": { "version": "4.0.7", "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz", @@ -9366,6 +9418,31 @@ "node": ">= 6" } }, + "node_modules/form-data-encoder": { + "version": "1.7.2", + "resolved": "https://registry.npmjs.org/form-data-encoder/-/form-data-encoder-1.7.2.tgz", + "integrity": "sha512-qfqtYan3rxrnCk1VYaA4H+Ms9xdpPqvLZa6xmMgFvhO32x7/3J/ExcTd6qpxM0vH2GdMI+poehyBZvqfMTto8A==" + }, + "node_modules/formdata-node": { + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/formdata-node/-/formdata-node-4.4.1.tgz", + "integrity": "sha512-0iirZp3uVDjVGt9p49aTaqjk84TrglENEDuqfdlZQ1roC9CWlPk6Avf8EEnZNcAqPonwkG35x4n3ww/1THYAeQ==", + "dependencies": { + "node-domexception": "1.0.0", + "web-streams-polyfill": "4.0.0-beta.3" + }, + "engines": { + "node": ">= 12.20" + } + }, + "node_modules/formdata-node/node_modules/web-streams-polyfill": { + "version": "4.0.0-beta.3", + "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-4.0.0-beta.3.tgz", + "integrity": "sha512-QW95TCTaHmsYfHDybGMwO5IJIM93I/6vTRk+daHTWFPhwh+C8Cg7j7XyKrwrj8Ib6vYXe0ocYNrmzY4xAAN6ug==", + "engines": { + "node": ">= 14" + } + }, "node_modules/formdata-polyfill": { "version": "4.0.10", "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", @@ -10052,6 +10129,14 @@ "node": ">=10.17.0" } }, + "node_modules/humanize-ms": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/humanize-ms/-/humanize-ms-1.2.1.tgz", + "integrity": "sha512-Fl70vYtsAFb/C06PTS9dZBo7ihau+Tu/DNCk/OyHhea07S+aeMWpFFkUaXRa8fI+ScZbEI8dfSxwY7gxZ9SAVQ==", + "dependencies": { + "ms": "^2.0.0" + } + }, "node_modules/iconv-lite": { "version": "0.6.3", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", @@ -17934,16 +18019,16 @@ } }, "node_modules/typescript": { - "version": "5.6.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.3.tgz", - "integrity": "sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw==", + "version": "4.9.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", + "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" }, "engines": { - "node": ">=14.17" + "node": ">=4.2.0" } }, "node_modules/unbox-primitive": { @@ -17965,6 +18050,11 @@ "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.12.1.tgz", "integrity": "sha512-hEQt0+ZLDVUMhebKxL4x1BTtDY7bavVofhZ9KZ4aI26X9SRaE+Y3m83XUL1UP2jn8ynjndwCCpEHdUG+9pP1Tw==" }, + "node_modules/undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==" + }, "node_modules/unicode-canonical-property-names-ecmascript": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-2.0.1.tgz", diff --git a/src/App.js b/src/App.js index f8e2ec3..38dccc9 100644 --- a/src/App.js +++ b/src/App.js @@ -19,6 +19,7 @@ function App() { const [allConcerts, setAllConcerts] = useState([]); const [userLocation, setUserLocation] = useState(null); const [posterName, setPosterName] = useState(""); + const [posterNameSuggestions, setPosterNameSuggestions] = useState([]); const [followedArtists, setFollowedArtists] = useState([]); const [artistName, setArtistName] = useState("Taylor Swift"); const [artistList, setArtistList] = useState([]); @@ -82,7 +83,10 @@ function App() { posterName={posterName} startDate={startDate} endDate={endDate} - shareId={shareId} /> + shareId={shareId} + posterNameSuggestions = {posterNameSuggestions} + setPosterNameSuggestions = {setPosterNameSuggestions} + /> } /> diff --git a/src/Odyssey/FetchName.js b/src/Odyssey/FetchName.js new file mode 100644 index 0000000..ae7df7e --- /dev/null +++ b/src/Odyssey/FetchName.js @@ -0,0 +1,18 @@ +export const FetchName = async (concerts) => { + const response = await fetch( + `${process.env.REACT_APP_BACKEND}/GetTripTitleSuggestion`, + { + method: 'POST', + headers: { + 'content-type': 'application/json;charset=utf-8' + }, + body: JSON.stringify(concerts), + } + ); + console.log(`response status code: ${response.status}`); + if (response.status === 200) { + let resJson = await response.json(); + return resJson; + } + return; +}; diff --git a/src/Odyssey/Odyssey.js b/src/Odyssey/Odyssey.js index 0bf8be7..b90a88c 100644 --- a/src/Odyssey/Odyssey.js +++ b/src/Odyssey/Odyssey.js @@ -1,5 +1,5 @@ import React from 'react'; -import { Grid, Button, Stack, Box } from "@mui/material"; +import { Grid, Button, Stack } from "@mui/material"; // Import other components import SharePage from "./SharePage.js"; @@ -31,7 +31,6 @@ function transformSpecificChildKeys(obj, targetKey) { - const Odyssey = ({ concerts, userLocation, @@ -41,6 +40,8 @@ const Odyssey = ({ startDate, endDate, shareId, + posterNameSuggestions, + setPosterNameSuggestions, setShareId }) => { const handleShareAsLink = async function () { @@ -94,13 +95,16 @@ const Odyssey = ({ }; return ( - +
diff --git a/src/Odyssey/SharePage.js b/src/Odyssey/SharePage.js index 10db462..8693097 100644 --- a/src/Odyssey/SharePage.js +++ b/src/Odyssey/SharePage.js @@ -1,10 +1,13 @@ import React from 'react'; -import { Stack, TextField } from '@mui/material'; +import { Stack, TextField, Button } 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 SharePage = ({ concerts, userLocation, mapStyle, setPosterName }) => { // Your component logic goes here const { isLoaded } = useLoadScript({ googleMapsApiKey: process.env.REACT_APP_GCP_KEY, // Add your API key @@ -14,15 +17,45 @@ const SharePage = ({ concerts, userLocation, mapStyle, setPosterName }) => { const concerts1 = concerts.slice(0, middleIndex); const concerts2 = concerts.slice(middleIndex); + const GenerateTripTitle = async function () { + + if (posterNameSuggestions.length < 1) { + // 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 })); + // now make a request and send it to open AI + var suggestions = await FetchName(newList); + setPosterNameSuggestions(suggestions.slice(1)); + setPosterName(suggestions[0].title); + } + else + { + setPosterName(posterNameSuggestions[0].title); + setPosterNameSuggestions(posterNameSuggestions=> posterNameSuggestions.slice(1)); + } + + }; return ( {isLoaded ? : null} - setPosterName(e.target.value)} /> + + setPosterName(e.target.value)} /> + +