Skip to content

Commit

Permalink
Add blog icon to the blog home page in LinkControl search results (W…
Browse files Browse the repository at this point in the history
…ordPress#55610)

* replicate the front page functionality for the blog posts

* remove log and cleanup ifs
  • Loading branch information
MaggieCabrera authored Oct 25, 2023
1 parent 377b81d commit 4bc5850
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
14 changes: 12 additions & 2 deletions packages/block-editor/src/components/link-control/search-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
category,
file,
home,
verse,
} from '@wordpress/icons';
import { __unstableStripHTML as stripHTML } from '@wordpress/dom';
import { safeDecodeURI, filterURLForDisplay, getPath } from '@wordpress/url';
Expand All @@ -32,8 +33,13 @@ function SearchItemIcon( { isURL, suggestion } ) {
icon = globe;
} else if ( suggestion.type in ICONS_MAP ) {
icon = ICONS_MAP[ suggestion.type ];
if ( suggestion.type === 'page' && suggestion.isFrontPage ) {
icon = home;
if ( suggestion.type === 'page' ) {
if ( suggestion.isFrontPage ) {
icon = home;
}
if ( suggestion.isBlogHome ) {
icon = verse;
}
}
}

Expand Down Expand Up @@ -139,6 +145,10 @@ function getVisualTypeName( suggestion ) {
return 'front page';
}

if ( suggestion.isBlogHome ) {
return 'blog home';
}

// Rename 'post_tag' to 'tag'. Ideally, the API would return the localised CPT or taxonomy label.
return suggestion.type === 'post_tag' ? 'tag' : suggestion.type;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export default function LinkControlSearchResults( {
searchTerm={ currentInputValue }
shouldShowType={ shouldShowSuggestionsTypes }
isFrontPage={ suggestion?.isFrontPage }
isBlogHome={ suggestion?.isBlogHome }
/>
);
} ) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ const handleEntitySearch = async (
suggestionsQuery,
fetchSearchSuggestions,
withCreateSuggestion,
pageOnFront
pageOnFront,
pageForPosts
) => {
const { isInitialSuggestions } = suggestionsQuery;

Expand All @@ -63,6 +64,9 @@ const handleEntitySearch = async (
if ( Number( result.id ) === pageOnFront ) {
result.isFrontPage = true;
return result;
} else if ( Number( result.id ) === pageForPosts ) {
result.isBlogHome = true;
return result;
}

return result;
Expand Down Expand Up @@ -104,15 +108,19 @@ export default function useSearchHandler(
allowDirectEntry,
withCreateSuggestion
) {
const { fetchSearchSuggestions, pageOnFront } = useSelect( ( select ) => {
const { getSettings } = select( blockEditorStore );

return {
pageOnFront: getSettings().pageOnFront,
fetchSearchSuggestions:
getSettings().__experimentalFetchLinkSuggestions,
};
}, [] );
const { fetchSearchSuggestions, pageOnFront, pageForPosts } = useSelect(
( select ) => {
const { getSettings } = select( blockEditorStore );

return {
pageOnFront: getSettings().pageOnFront,
pageForPosts: getSettings().pageForPosts,
fetchSearchSuggestions:
getSettings().__experimentalFetchLinkSuggestions,
};
},
[]
);

const directEntryHandler = allowDirectEntry
? handleDirectEntry
Expand All @@ -127,13 +135,15 @@ export default function useSearchHandler(
{ ...suggestionsQuery, isInitialSuggestions },
fetchSearchSuggestions,
withCreateSuggestion,
pageOnFront
pageOnFront,
pageForPosts
);
},
[
directEntryHandler,
fetchSearchSuggestions,
pageOnFront,
pageForPosts,
suggestionsQuery,
withCreateSuggestion,
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ function useBlockEditorSettings( settings, hasTemplate ) {
canUseUnfilteredHTML,
userCanCreatePages,
pageOnFront,
pageForPosts,
postType,
userPatternCategories,
} = useSelect( ( select ) => {
Expand All @@ -118,6 +119,7 @@ function useBlockEditorSettings( settings, hasTemplate ) {
hasUploadPermissions: canUser( 'create', 'media' ) ?? true,
userCanCreatePages: canUser( 'create', 'pages' ),
pageOnFront: siteSettings?.page_on_front,
pageForPosts: siteSettings?.page_for_posts,
postType: getCurrentPostType(),
userPatternCategories: getUserPatternCategories(),
};
Expand Down Expand Up @@ -218,6 +220,7 @@ function useBlockEditorSettings( settings, hasTemplate ) {
__experimentalCreatePageEntity: createPageEntity,
__experimentalUserCanCreatePages: userCanCreatePages,
pageOnFront,
pageForPosts,
__experimentalPreferPatternsOnRoot: hasTemplate,
} ),
[
Expand All @@ -233,6 +236,7 @@ function useBlockEditorSettings( settings, hasTemplate ) {
createPageEntity,
userCanCreatePages,
pageOnFront,
pageForPosts,
]
);
}
Expand Down

0 comments on commit 4bc5850

Please sign in to comment.