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
|
@action
|
||||||
toggleBadge() {
|
toggleBadge() {
|
||||||
this.model
|
const originalState = this.buffered.get("enabled");
|
||||||
.save({ enabled: !this.buffered.get("enabled") })
|
const newState = !this.buffered.get("enabled");
|
||||||
.catch(popupAjaxError);
|
|
||||||
|
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