DEV: Apply optimistic update pattern to badge toggle (#20399)

This commit is contained in:
Keegan George 2023-02-21 15:27:59 -08:00 committed by GitHub
parent c11fd4fdf9
commit c43cb0c571
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 3 deletions

View File

@ -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);
});
} }
} }