ButtonKit icon indicating copy to clipboard operation
ButtonKit copied to clipboard

Add isLoading binding to AsyncButton

Open finnvoor opened this issue 1 year ago • 1 comments

I often have some kind of editor form with multiple fields and a save button. When the save is loading, I want to disable all the forms in the view. This PR adds an isLoading binding to AsyncButton, so I can easily add .disabled(isLoading) to any view I want. Not sure if this is exactly the best way to implement it, open to feedback!

finnvoor avatar Sep 27 '24 14:09 finnvoor

Hi!

Thanks for your proposal!

The problem with binding is that it implies that you can input manually from the outside. But that's not true. Setting isLoading outside of the button is possible, but makes no sense.

I think the following approach would work for you:

  • have your own isLoading as a state
  • set that state using the task event modifier already available:
AsyncButton {
  ...
}
.asyncButtonTaskStarted { task in
    // Task started
}
.asyncButtonTaskEnded {
    // Task ended or was cancelled
}

Dean151 avatar Sep 28 '24 23:09 Dean151