Skip to content

Commit

Permalink
Copy array for reorder
Browse files Browse the repository at this point in the history
  • Loading branch information
tellthemachines committed May 29, 2023
1 parent 2ba722b commit a151d40
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,22 @@ export default function SidebarNavigationScreenPages() {

const isHomePageBlog = frontPage === postsPage;

if ( ! isHomePageBlog && pages?.length ) {
const homePageIndex = pages.findIndex(
const reorderedPages = pages && [ ...pages ];

if ( ! isHomePageBlog && reorderedPages?.length ) {
const homePageIndex = reorderedPages.findIndex(
( item ) => item.id === frontPage
);
const homePage = pages.splice( homePageIndex, 1 );
pages?.splice( 0, 0, ...homePage );
const homePage = reorderedPages.splice( homePageIndex, 1 );
reorderedPages?.splice( 0, 0, ...homePage );

const postsPageIndex = pages.findIndex(
const postsPageIndex = reorderedPages.findIndex(
( item ) => item.id === postsPage
);

const blogPage = pages.splice( postsPageIndex, 1 );
const blogPage = reorderedPages.splice( postsPageIndex, 1 );

pages.splice( 1, 0, ...blogPage );
reorderedPages.splice( 1, 0, ...blogPage );
}

return (
Expand Down Expand Up @@ -114,7 +116,7 @@ export default function SidebarNavigationScreenPages() {
</Truncate>
</PageItem>
) }
{ pages?.map( ( item ) => {
{ reorderedPages?.map( ( item ) => {
let itemIcon;
switch ( item.id ) {
case frontPage:
Expand Down

0 comments on commit a151d40

Please sign in to comment.