Skip to content

Commit

Permalink
A4A Sites: update fields on breakpoint change
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Sep 4, 2024
1 parent ede0092 commit 7600812
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,17 @@ export const SitesDashboardProvider = ( {
filters: buildFilters( { issueTypes } ),
} );

useEffect( () => {
const fields = getFieldsByBreakpoint( isDesktop );
const fieldsForBreakpoint = [ ...fields ].sort().toString();
const existingFields = [ ...( dataViewsState?.fields ?? [] ) ].sort().toString();
// Compare the content of the arrays, not its referrences that will always be different.
// sort() sorts the array in place, so we need to clone them first.
if ( existingFields !== fieldsForBreakpoint ) {
setDataViewsState( ( prevState ) => ( { ...prevState, fields } ) );
}
}, [ isDesktop, dataViewsState?.fields ] );

useEffect( () => {
setInitialSelectedSiteUrl( siteUrlInitialState );
if ( ! siteUrlInitialState ) {
Expand Down

0 comments on commit 7600812

Please sign in to comment.