Skip to content

Commit

Permalink
Fixing artist chip duplicating onclick
Browse files Browse the repository at this point in the history
  • Loading branch information
sam9116 committed Jun 1, 2024
1 parent 30e3555 commit 87b5ba6
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/BaseInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const BaseInput = forwardRef(({ setConcerts, setUserLocation, setMapStyle, start
}));

const [artistName, setArtistName] = useState("Taylor Swift");
const submitArtistInfo = async (incomingArtistInfo) => {
const submitArtistInfo = async (incomingArtistInfo) => {
console.log(incomingArtistInfo);
let incomingArtistName = incomingArtistInfo.name;
let incomingArtistId = incomingArtistInfo.id
Expand Down Expand Up @@ -122,16 +122,19 @@ const BaseInput = forwardRef(({ setConcerts, setUserLocation, setMapStyle, start
sortArtist(allConcerts.concat(incomingConcerts), userLocation);
}


setOpen(false);
closeDialog();

const existingArtists = followedArtists;
var updatedArtists = existingArtists.push(incomingArtistInfo);
var checkForDuplicateArtists = updatedArtists.filter(
(value, index, self) => self.findIndex(otherItem => otherItem.id === value.id) === index
);
setFollowedArtists(checkForDuplicateArtists);
//check for duplicates
const hasElementWithValue = followedArtists.some(artist => artist.id === incomingArtistInfo.id);
var updatedArtists = followedArtists;

if (!hasElementWithValue) {
updatedArtists.push(incomingArtistInfo);
}

setFollowedArtists(updatedArtists);

} else {
console.log("Some error occured");
}
Expand Down

0 comments on commit 87b5ba6

Please sign in to comment.