Commit 21e90205 authored by Richard Bowman's avatar Richard Bowman 🔬
Browse files

Streamlined autofocus code

There now aren't any nested promises at the top level.  I think we should be able to get rid of the ones in the store.dispatch method too, but that bothers me less because I can't see it!
parent 604a5c1f
Loading
Loading
Loading
Loading
+9 −15
Original line number Diff line number Diff line
@@ -218,28 +218,22 @@ export default {
      if (!this.$store.state.moveLock) {
        // Lock move requests
        this.$store.commit('changeMoveLock', true);
        this.isAutofocusing = true
        axios.post(this.autofocusApiUri, {dz: dz})
        .then(response => { 
          console.log("Autofocus Task ID: " + response.data[0].id)
          this.isAutofocusing = true
          // Start the store polling TaskId for success
          self = this;
          this.$store.dispatch('pollTask', [response.data[0].id, null, null])
          .then(function() {
            UIkit.notification({message: "Finished recalibration.", status: 'success'})
          return this.$store.dispatch('pollTask', [response.data[0].id, null, null])
        })
        .then(() => { console.log("Successfully finished autofocus"); })
        .catch(error => {
          UIkit.notification({message: `<span uk-icon=\'icon: warning\'></span> ${error}`, status: 'danger'})
          this.$store.dispatch('handleHTTPError', error);  // Let store handle error
        })
        .finally(() => {
            self.isAutofocusing = false
            this.$store.commit('changeMoveLock', false)  // Release the move lock
          })
        })
        .catch(error => {
          this.$store.dispatch('handleHTTPError', error);  // Let store handle error
          self.isAutofocusing = false
          this.$store.commit('changeMoveLock', false)  // Release the move lock
          console.log("Cleaning up after autofocus.")
          this.isAutofocusing = false;
          this.$store.commit('changeMoveLock', false);  // Release the move lock
        })
      }
    }