Skip to content

Commit

Permalink
cleanup code spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
sam9116 committed Feb 4, 2024
1 parent d71b7a8 commit de647e0
Showing 1 changed file with 35 additions and 35 deletions.
70 changes: 35 additions & 35 deletions src/BaseInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,45 +88,45 @@ const BaseInput = forwardRef(({ setConcerts, setUserLocation, setMapStyle, start

let handleSubmit = async (e) => {
e.preventDefault();
setConcerts([],submitArtist(artistName));
setConcerts([], submitArtist(artistName));
};

const sortArtist = (incomingAllConcerts , userLocation)=>{
const sortArtist = (incomingAllConcerts, userLocation) => {
console.log(`total Number Of Concerts Memorized after submitArtist: ${incomingAllConcerts.length}`);
console.log(`sort all concerts`);
var sortedAllConcerts = incomingAllConcerts.sort((a, b) => {
console.log(`sort the entire concert list based on date and distance to home location of each concert...`);
var originPoint;

if (concerts.length > 0) {
originPoint = {
latitude: concerts[concerts.length - 1].location.latitude,
longitude: concerts[concerts.length - 1].location.longitude,
};
}
else {
originPoint = {
latitude: userLocation.coords.latitude,
longitude: userLocation.coords.longitude,
};
}

// Calculate the distance between the points
console.log(`Calculate the distance between the points`);
var distancea = distanceInKmBetweenEarthCoordinates(originPoint.latitude, originPoint.longitude, a.location.latitude, a.location.longitude);
var distanceb = distanceInKmBetweenEarthCoordinates(originPoint.latitude, originPoint.longitude, b.location.latitude, b.location.longitude);
console.log(`distancea: ${distancea}`);
console.log(`distanceb: ${distanceb}`);
return (new Date(a.date) - new Date(b.date)) && (distancea - distanceb);
});

console.log(`filter the sorted concert by artist name, so we're only left with one concert per artist`);
var newConcerts = sortedAllConcerts.filter((value, index, self) => {
return self.findIndex(v => v.artist === value.artist) === index;
})
newConcerts = newConcerts.sort((a, b)=>{return (new Date(a.date) - new Date(b.date))});
console.log(`concat the new concerts into the optimized`);
setConcerts(newConcerts);
var sortedAllConcerts = incomingAllConcerts.sort((a, b) => {
console.log(`sort the entire concert list based on date and distance to home location of each concert...`);
var originPoint;

if (concerts.length > 0) {
originPoint = {
latitude: concerts[concerts.length - 1].location.latitude,
longitude: concerts[concerts.length - 1].location.longitude,
};
}
else {
originPoint = {
latitude: userLocation.coords.latitude,
longitude: userLocation.coords.longitude,
};
}

// Calculate the distance between the points
console.log(`Calculate the distance between the points`);
var distancea = distanceInKmBetweenEarthCoordinates(originPoint.latitude, originPoint.longitude, a.location.latitude, a.location.longitude);
var distanceb = distanceInKmBetweenEarthCoordinates(originPoint.latitude, originPoint.longitude, b.location.latitude, b.location.longitude);
console.log(`distancea: ${distancea}`);
console.log(`distanceb: ${distanceb}`);
return (new Date(a.date) - new Date(b.date)) && (distancea - distanceb);
});

console.log(`filter the sorted concert by artist name, so we're only left with one concert per artist`);
var newConcerts = sortedAllConcerts.filter((value, index, self) => {
return self.findIndex(v => v.artist === value.artist) === index;
})
newConcerts = newConcerts.sort((a, b) => { return (new Date(a.date) - new Date(b.date)) });
console.log(`concat the new concerts into the optimized`);
setConcerts(newConcerts);
}
return (
<div>
Expand Down

0 comments on commit de647e0

Please sign in to comment.