Skip to content

Commit

Permalink
catch if an artist is already performing as a featured artist in some…
Browse files Browse the repository at this point in the history
…body else's show, by searching for the featured artist name in the concert title
  • Loading branch information
sam9116 committed Feb 12, 2024
1 parent 16dd5eb commit 8b15912
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions src/BaseInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,44 +61,59 @@ const BaseInput = forwardRef(({ setConcerts, setUserLocation, setMapStyle, start


const submitArtist = async (incomingArtistName) => {
incomingArtistName = incomingArtistName.toLowerCase();
try {
let res = await fetch(`${process.env.REACT_APP_BACKEND}/concerts`, {
method: "POST",
headers: {
"content-type": "application/json;charset=utf-8",
},
body: JSON.stringify({
artistName: incomingArtistName.toLowerCase(),
artistName: incomingArtistName,
startDate: startDate,
endDate: endDate
}),
});

let resJson = await res.json();
let incomingConcerts = await res.json();
if (res.status === 200) {

if (resJson.length < 1) {
if (incomingConcerts.length < 1) {
alert(`no upcoming concerts for ${incomingArtistName} found`);
return;
}
console.log(`resJson: ${resJson.length}`);
console.log(`add incoming concerts into allconcerts`);
console.log(`total Number Of Concerts Memorized: ${allConcerts.length}`);
console.log(`incoming concerts: ${incomingConcerts.length}`);
//console.log(`add incoming concerts into allconcerts`);
//console.log(`total Number Of Concerts Memorized: ${allConcerts.length}`);
//avoid adding the same concert.. check the title of the concert
const found = concerts.some((concert) => {
var incomingConcertTitles = incomingConcerts.map(concert => concert.title);

var found = resJson.map(concert => concert.title).includes(concert.title);
var found = concerts.some((concert) => {

if (found) {
alert(`${incomingArtistName} is already performing as part of ${concert.title} on ${formattedDate(concert.date)}`);
return found;
var concertFound = incomingConcertTitles.includes(concert.title);
var artistFound = false;
var artistFoundConcert = concerts.find((concert) => {
return concert.title.includes(concert.artist);
});

if (concertFound) {
if (incomingArtistName !== concert.artist.toLowerCase()) {
alert(`${concert.artist} is already performing as part of ${concert.title} on ${formattedDate(concert.date)}`);
}
}
if (artistFoundConcert) {
if (incomingArtistName !== artistFoundConcert.artist.toLowerCase()) {
alert(`${incomingArtistName} is already performing as part of ${artistFoundConcert.title} on ${formattedDate(artistFoundConcert.date)}`);
}
artistFound = true;
}
return concertFound || artistFound;

});

if (!found) {
setAllConcerts((prev) => prev.concat(resJson));
sortArtist(allConcerts.concat(resJson), userLocation);
setAllConcerts((prev) => prev.concat(incomingConcerts));
sortArtist(allConcerts.concat(incomingConcerts), userLocation);
}

} else {
Expand All @@ -117,7 +132,7 @@ const BaseInput = forwardRef(({ setConcerts, setUserLocation, setMapStyle, start
const sortArtist = (incomingAllConcerts, userLocation) => {
console.log(`total Number Of Concerts Memorized after submitArtist: ${incomingAllConcerts.length}`);
console.log(`sort all concerts`);

incomingAllConcerts = incomingAllConcerts.sort((a, b) => {
return (new Date(a.date) - new Date(b.date));
});
Expand Down

0 comments on commit 8b15912

Please sign in to comment.