Autosave a Note

Write the code, see it run, pass the checks.

The problem

  • medium
  • Code
  • Pro

Build a note that saves itself. Props: save, a function that takes the note's text and returns a Promise; and delay, in milliseconds (default 1000). Give it a textarea labelled "Note" and an element with role="status" that is always there and empty at first. As soon as the note changes, the status reads "Unsaved changes". Once delay milliseconds pass with no more typing, call save with the whole text and show "Saving..." (three full stops) until it settles, then "Saved" if it resolved or "Couldn't save" if it rejected. Don't save before the first change. The checks use a delay of 150.

Your code must pass

  • Shows "Unsaved changes" while typing, without saving yet
  • Saves the whole note once, after typing pauses
  • Shows "Saving..." until the save finishes, then "Saved"
  • Says it couldn't save when saving fails