IT’S FINISHED!!! Tonight I finished the final missing piece for my value app. Well…the last piece on v1.0 at least. It was all thanks to some help I got at a Meetup tonight…super stoked!
I had been really stuck on figuring out how to delete a single date from an array of dates. The array is a property in the MongoDB document, and the list of dates is populated to the site with a
My initial approach was a bit convoluted (in hindsight!):
- Give each date an ID of that date
- On click, event listener creates a variable of that date
- Router takes that variable and looks for a match in the array with a
- On finding a match, that date is deleted:
var deletedUse = new Date(req.body.hiddenDateInput);
The issue with this was that the date stored in the database was being captured by default in UTC time, while the newly created variable to search against was not. So going through the array, there would never be a match and no date would be deleted.
Instead of this, the hero of the day recommended deleting the selected index of the array…that way you wouldn’t have to worry about matching at all. I didn’t know that the forEach function could take additional arguments…turns out it can and one of them is index! This was so much more straightforward:
var index = req.body.usageDatesIndex;
So now the app is fully functional and ready to deploy. Speaking of which…
I really cracked myself up with that one yesterday! 😂😂😂 I figured out what I’d done wrong though—I was updating the dependencies to get ready to deploy, and used
npm update out of habit, but I’d built the project using yarn. So after I’d “updated,” some of the dependencies disappeared all together and the app crashed. Once I figured it out I ran
yarn upgrade to get everything back to normal and it was all good!
I also got started on the AWS deployment. I’m trying Elastic Beanstalk but there’s a bit of extra configuring to do in order to implement GitHub integration. I’m documenting the process step-by-step so will be good to have for future use.
Deploy deploy deploy!