Skip to content

FIX: issuses with fast consecutive clicks on delete/restore buttons #32743

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export default class PostMenuDeleteButton extends Component {
}

get disabled() {
return !this.activeAction;
return !this.activeAction || this.args.post.isDeleting || this.args.post.isRecovering;
}

get #activeMode() {
Expand Down
63 changes: 42 additions & 21 deletions app/assets/javascripts/discourse/app/models/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ export default class Post extends RestModel {
@trackedPostProperty user_custom_fields;
@trackedPostProperty has_post_localizations;
@trackedPostProperty post_localizations;
@trackedPostProperty isDeleting = false;
@trackedPostProperty isRecovering = false;

@alias("can_edit") canEdit; // for compatibility with existing code
@equal("trust_level", 0) new_user;
Expand Down Expand Up @@ -476,7 +478,13 @@ export default class Post extends RestModel {
}

// Recover a deleted post
recover() {
async recover() {
if (this.isRecovering) {
return;
}

this.set("isRecovering", true);

const initProperties = this.getProperties(
"deleted_at",
"deleted_by",
Expand All @@ -491,22 +499,27 @@ export default class Post extends RestModel {
can_delete: false,
});

return ajax(`/posts/${this.id}/recover`, {
type: "PUT",
})
.then((data) => {
this.setProperties({
cooked: data.cooked,
raw: data.raw,
user_deleted: false,
can_delete: true,
version: data.version,
});
})
.catch((error) => {
popupAjaxError(error);
this.setProperties(initProperties);
try {
const data = await ajax(`/posts/${this.id}/recover`, {
type: "PUT",
});

this.setProperties({
cooked: data.cooked,
raw: data.raw,
user_deleted: false,
can_delete: true,
version: data.version,
});

return data;
} catch (error) {
popupAjaxError(error);
this.setProperties(initProperties);
throw error;
} finally {
this.set("isRecovering", false);
}
}

/**
Expand Down Expand Up @@ -567,15 +580,23 @@ export default class Post extends RestModel {
}
}

destroy(deletedBy, opts) {
return this.setDeletedState(deletedBy).then(() => {
return ajax("/posts/" + this.id, {
async destroy(deletedBy, opts) {
if (this.isDeleting) {
return;
}

this.set("isDeleting", true);

try {
await this.setDeletedState(deletedBy);
return await ajax("/posts/" + this.id, {
data: { context: window.location.pathname, ...opts },
type: "DELETE",
});
});
} finally {
this.set("isDeleting", false);
}
}

/**
* Updates a post from another's attributes. This will normally happen when a post is loading but
* is already found in an identity map.
Expand Down