From dc9015619e31f7dda9e2ed55345a3538046b7558 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Tue, 6 Aug 2024 17:16:54 +0200 Subject: [PATCH 1/2] Sidebar item: set the proper layout --- .../src/components/sidebar-dataviews/dataview-item.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/edit-site/src/components/sidebar-dataviews/dataview-item.js b/packages/edit-site/src/components/sidebar-dataviews/dataview-item.js index 0b5f93546875e..1e12d6706d81b 100644 --- a/packages/edit-site/src/components/sidebar-dataviews/dataview-item.js +++ b/packages/edit-site/src/components/sidebar-dataviews/dataview-item.js @@ -29,7 +29,7 @@ export default function DataViewItem( { suffix, } ) { const { - params: { postType, layout }, + params: { postType }, } = useLocation(); const iconToUse = @@ -41,7 +41,7 @@ export default function DataViewItem( { } const linkInfo = useLink( { postType, - layout, + layout: type, activeView, isCustom: isCustom ? 'true' : undefined, } ); From 23ea90590280316455813fb4a6acd005832a861a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Tue, 6 Aug 2024 17:28:11 +0200 Subject: [PATCH 2/2] Use layout parameter when loading the default/custom view --- .../src/components/post-list/index.js | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/packages/edit-site/src/components/post-list/index.js b/packages/edit-site/src/components/post-list/index.js index 74bbee0524617..35ecaaa8424fd 100644 --- a/packages/edit-site/src/components/post-list/index.js +++ b/packages/edit-site/src/components/post-list/index.js @@ -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( @@ -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' ) { @@ -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 ]; }