DEV: Apply optimistic update pattern to badge toggle (#20399)
This commit is contained in:
parent
c11fd4fdf9
commit
c43cb0c571
|
@ -248,8 +248,13 @@ export default class AdminBadgesShowController extends Controller.extend(
|
|||
|
||||
@action
|
||||
toggleBadge() {
|
||||
this.model
|
||||
.save({ enabled: !this.buffered.get("enabled") })
|
||||
.catch(popupAjaxError);
|
||||
const originalState = this.buffered.get("enabled");
|
||||
const newState = !this.buffered.get("enabled");
|
||||
|
||||
this.buffered.set("enabled", newState);
|
||||
this.model.save({ enabled: newState }).catch((error) => {
|
||||
this.buffered.set("enabled", originalState);
|
||||
return popupAjaxError(error);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue