Skip to content
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

fix: deleting a discussion from the profile does not visually remove it #3798

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion framework/core/js/src/forum/components/DiscussionList.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default class DiscussionList extends Component {
{state.getPages().map((pg, pageNum) => {
return pg.items.map((discussion, itemNum) => (
<li key={discussion.id()} data-id={discussion.id()} role="article" aria-setsize="-1" aria-posinset={pageNum * pageSize + itemNum}>
<DiscussionListItem discussion={discussion} params={params} />
<DiscussionListItem discussion={discussion} params={params} state={state} />
</li>
));
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ import Tooltip from '../../common/components/Tooltip';
import type Discussion from '../../common/models/Discussion';
import type Mithril from 'mithril';
import type { DiscussionListParams } from '../states/DiscussionListState';
import DiscussionListState from '../states/DiscussionListState';

export interface IDiscussionListItemAttrs extends ComponentAttrs {
discussion: Discussion;
params: DiscussionListParams;
state?: DiscussionListState;
}

/**
Expand Down
17 changes: 13 additions & 4 deletions framework/core/js/src/forum/utils/DiscussionControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export default {
* @return {ItemList<import('mithril').Children>}
* @protected
*/
destructiveControls(discussion) {
destructiveControls(discussion, context) {
const items = new ItemList();

if (!discussion.isHidden()) {
Expand Down Expand Up @@ -157,7 +157,7 @@ export default {
Button.component(
{
icon: 'fas fa-times',
onclick: this.deleteAction.bind(discussion),
onclick: this.deleteAction.bind(discussion, context),
},
app.translator.trans('core.forum.discussion_controls.delete_forever_button')
)
Expand Down Expand Up @@ -232,17 +232,26 @@ export default {
/**
* Delete the discussion after confirming with the user.
*
* @param {import('../../common/Component').default<any, any>} context The parent component under which the controls menu will be displayed.
*
* @return {Promise<void>}
*/
deleteAction() {
deleteAction(context) {
if (confirm(extractText(app.translator.trans('core.forum.discussion_controls.delete_confirmation')))) {
// If we're currently viewing the discussion that was deleted, go back
// to the previous page.
if (app.viewingDiscussion(this)) {
app.history.back();
}

return this.delete().then(() => app.discussions.removeDiscussion(this));
return this.delete().then(() => {
if (context.attrs?.state) {
// Delete from the local state.
context.attrs.state.removeDiscussion(this);
// And the global state if it isn't the global state.
if (context.attrs.state !== app.discussions) app.discussions.removeDiscussion(this);
}
});
}
},

Expand Down