Skip to content

Commit

Permalink
Remove snackbar location change.
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdharmesh committed Jan 13, 2025
1 parent 4c0282f commit 4082203
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/js/settings/components/classifai-settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ export const ServiceNavigation = () => {
* @return {React.ReactElement} The Snackbar component.
*/
export const SnackbarNotifications = () => {
const { removeNotice } = useDispatch( noticeStore );
const { removeNotice, removeNotices } = useDispatch( noticeStore );
const location = useLocation();

const { notices } = useSelect( ( select ) => {
const allNotices = select( noticeStore ).getNotices();
Expand All @@ -140,6 +141,16 @@ export const SnackbarNotifications = () => {
};
}, [] );

useEffect( () => {
// Remove existing snackbar notices on location change.
if ( removeNotices ) {
removeNotices( notices.map( ( { id } ) => id ) );
} else if ( removeNotice ) {
notices.forEach( ( { id } ) => removeNotice( id ) );
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [ location, removeNotice, removeNotices ] );

return (
<SnackbarList
className="classifai-settings-snackbar-notices"
Expand Down

0 comments on commit 4082203

Please sign in to comment.