Skip to content

Commit

Permalink
Use layout parameter when loading the default/custom view
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Aug 6, 2024
1 parent dc90156 commit 23ea905
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions packages/edit-site/src/components/post-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,22 @@ function useView( postType ) {
[ activeView, isCustom ]
);
const [ view, setView ] = useState( () => {
let initialView;
if ( isCustom === 'true' ) {
return (
getCustomView( editedEntityRecord ) ?? {
type: layout ?? LAYOUT_LIST,
}
);
}
return (
getDefaultView( defaultViews, activeView ) ?? {
initialView = getCustomView( editedEntityRecord ) ?? {
type: layout ?? LAYOUT_LIST,
}
);
};
} else {
initialView = getDefaultView( defaultViews, activeView ) ?? {
type: layout ?? LAYOUT_LIST,
};
}

const type = layout ?? initialView.type;
return {
...initialView,
type,
};
} );

const setViewWithUrlUpdate = useCallback(
Expand Down Expand Up @@ -146,8 +150,7 @@ function useView( postType ) {
} ) );
}, [ layout ] );

// When activeView or isCustom URL parameters change,
// reset the view & update the layout URL param to match the view's type.
// When activeView or isCustom URL parameters change, reset the view.
useEffect( () => {
let newView;
if ( isCustom === 'true' ) {
Expand All @@ -157,9 +160,13 @@ function useView( postType ) {
}

if ( newView ) {
setViewWithUrlUpdate( newView );
const type = layout ?? newView.type;
setView( {
...newView,
type,
} );
}
}, [ activeView, isCustom, defaultViews, editedEntityRecord ] );
}, [ activeView, isCustom, layout, defaultViews, editedEntityRecord ] );

return [ view, setViewWithUrlUpdate, setViewWithUrlUpdate ];
}
Expand Down

0 comments on commit 23ea905

Please sign in to comment.