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

Notifications: Refresh admin menu after changing comment status #95443

Merged
merged 7 commits into from
Oct 22, 2024
Merged
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
3 changes: 2 additions & 1 deletion apps/notifications/src/panel/state/notes/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ export const addNotes = ( notes ) => ( {
notes,
} );

export const removeNotes = ( noteIds ) => ( {
export const removeNotes = ( noteIds, isComment = false ) => ( {
type: types.NOTES_REMOVE,
noteIds,
isComment,
} );

export const noteAction = ( action ) => ( noteId ) => ( {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ const setApproveStatus =
( noteId, siteId, commentId, isApproved, type, restClient ) => ( dispatch ) => {
const comment = wpcom().site( siteId ).comment( commentId );

comment.update( { status: isApproved ? 'approved' : 'unapproved' }, () =>
// getNote() updates the redux store with a fresh object from the API
restClient.getNote( noteId )
);

dispatch( approveNote( noteId, isApproved ) );
bumpStat( isApproved ? 'unapprove-comment' : 'approve-comment' );
recordTracksEvent( 'calypso_notification_note_' + ( isApproved ? 'approve' : 'unapprove' ), {
note_type: type,
} );

comment.update( { status: isApproved ? 'approved' : 'unapproved' }, () =>
// getNote() updates the redux store with a fresh object from the API
restClient.getNote( noteId )
);
};

export default setApproveStatus;
6 changes: 4 additions & 2 deletions apps/notifications/src/panel/templates/undo-list-item.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ export class UndoListItem extends Component {
comment.update( data, updateSpamStatus );
} );

this.props.removeNotes( [ this.props.note.id ] );
const isComment = true;
this.props.removeNotes( [ this.props.note.id ], isComment );

component.finishExecution();
};
Expand All @@ -124,7 +125,8 @@ export class UndoListItem extends Component {

this.instance && this.setState( { isVisible: false } );

this.props.removeNotes( [ this.props.note.id ] );
const isComment = true;
this.props.removeNotes( [ this.props.note.id ], isComment );

this.finishExecution();
};
Expand Down
27 changes: 22 additions & 5 deletions client/notifications/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ import { connect } from 'react-redux';
import localStorageHelper from 'store';
import { recordTracksEvent } from 'calypso/lib/analytics/tracks';
import wpcom from 'calypso/lib/wp';
import { requestAdminMenu as requestAdminMenuAction } from 'calypso/state/admin-menu/actions';
import { recordTracksEvent as recordTracksEventAction } from 'calypso/state/analytics/actions';
import { setUnseenCount } from 'calypso/state/notifications/actions';
import { didForceRefresh } from 'calypso/state/notifications-panel/actions';
import { shouldForceRefresh } from 'calypso/state/notifications-panel/selectors';
import getCurrentLocaleSlug from 'calypso/state/selectors/get-current-locale-slug';
import getCurrentLocaleVariant from 'calypso/state/selectors/get-current-locale-variant';
import getSelectedSiteId from 'calypso/state/ui/selectors/get-selected-site-id';

import './style.scss';

Expand Down Expand Up @@ -137,6 +139,18 @@ export class Notifications extends Component {
this.props.checkToggle();
},
],
APPROVE_NOTE: [
() => {
this.props.requestAdminMenu( this.props.selectedSiteId );
},
],
NOTES_REMOVE: [
( _, { isComment } ) => {
if ( isComment ) {
this.props.requestAdminMenu( this.props.selectedSiteId );
}
},
],
};

componentDidMount() {
Expand Down Expand Up @@ -292,10 +306,13 @@ export default connect(
( state ) => ( {
currentLocaleSlug: getCurrentLocaleVariant( state ) || getCurrentLocaleSlug( state ),
forceRefresh: shouldForceRefresh( state ),
selectedSiteId: getSelectedSiteId( state ),
} ),
{
recordTracksEventAction,
setUnseenCount,
didForceRefresh,
}
( dispatch ) => ( {
recordTracksEventAction: ( name, properties ) =>
dispatch( recordTracksEventAction( name, properties ) ),
setUnseenCount: ( count ) => dispatch( setUnseenCount( count ) ),
didForceRefresh: () => dispatch( didForceRefresh() ),
requestAdminMenu: ( siteId ) => dispatch( requestAdminMenuAction( siteId ) ),
} )
)( Notifications );
Loading