Recap
No new theory here, just a challenge. It uses modules, export and export default, import, a class with a constructor and a method, and destructuring.
Mission: Tidy reports
What you will see: the report form works exactly as before. Type Comet Runner, pick Explorer, press the button, and Comet Runner Explorer shows in the reports. Rest the mouse on it, and a small box says Report 6, with the id the API gave it.
The report form is the last part of the tracker that still does everything in tracker.js. It sends the starship, then builds the report item itself. Give each job its own place.
reportShipmoves fromtracker.jstoapi.js, which exports it.tracker.jsimportsreportShipfromapi.js.- A new file,
report.js, exports by default a classReport. - The constructor of
Reporttakes a starship, as the API answers it. It keeps itsid, itsname, and its class askind. - The method
toItem()ofReportreturns a copy of the templatereport-template, with the name and the class filled in. - The item's
titleisReport, then the id. - When the form is sent,
tracker.jsmakes aReportfrom the API's answer. It puts whattoItem()returns in the list with the idreports. tracker.jsdoesn't fill in the template itself any more.- A report that fails still says why in
#report-status. - The rest of the tracker works as before.
The report is made from the API's answer, not from the form's boxes.