-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Block editor settings: delay selecting pageOnFront, pageForPosts #57290
base: trunk
Are you sure you want to change the base?
Changes from all commits
99f955b
8d05001
a9813b6
3991a70
ac45b44
80a3e54
cc80345
15f78d9
17857cd
91dc709
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default { | ||
useLinkControlEntitySearch: Symbol( 'useLinkControlEntitySearch' ), | ||
}; |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -1,2 +1,56 @@ | ||||
export { default as __experimentalFetchLinkSuggestions } from './__experimental-fetch-link-suggestions'; | ||||
/** | ||||
* WordPress dependencies | ||||
*/ | ||||
import { useCallback } from '@wordpress/element'; | ||||
import { useSelect } from '@wordpress/data'; | ||||
import { store as blockEditorStore } from '@wordpress/block-editor'; | ||||
|
||||
/** | ||||
* Internal dependencies | ||||
*/ | ||||
import { store as coreStore } from '../'; | ||||
import { default as fetchLinkSuggestions } from './__experimental-fetch-link-suggestions'; | ||||
|
||||
export const __experimentalFetchLinkSuggestions = fetchLinkSuggestions; | ||||
export { default as __experimentalFetchUrlData } from './__experimental-fetch-url-data'; | ||||
|
||||
export function __experimentalUseLinkControlEntitySearch() { | ||||
const settings = useSelect( | ||||
( select ) => select( blockEditorStore ).getSettings(), | ||||
[] | ||||
); | ||||
// The function should either be undefined or a stable function reference | ||||
// throughout the editor lifetime, much like importing a function from a | ||||
// module. | ||||
const { pageOnFront, pageForPosts } = useSelect( ( select ) => { | ||||
const { canUser, getEntityRecord } = select( coreStore ); | ||||
|
||||
const siteSettings = canUser( 'read', 'settings' ) | ||||
? getEntityRecord( 'root', 'site' ) | ||||
: undefined; | ||||
|
||||
return { | ||||
pageOnFront: siteSettings?.page_on_front, | ||||
pageForPosts: siteSettings?.page_for_posts, | ||||
}; | ||||
}, [] ); | ||||
|
||||
return useCallback( | ||||
async ( val, suggestionsQuery ) => { | ||||
return ( | ||||
await fetchLinkSuggestions( val, suggestionsQuery, settings ) | ||||
).map( ( result ) => { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we instead access the original |
||||
if ( Number( result.id ) === pageOnFront ) { | ||||
result.isFrontPage = true; | ||||
return result; | ||||
} else if ( Number( result.id ) === pageForPosts ) { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think we can remove these early |
||||
result.isBlogHome = true; | ||||
return result; | ||||
} | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't think we need these early
Suggested change
|
||||
|
||||
return result; | ||||
} ); | ||||
}, | ||||
[ pageOnFront, pageForPosts, settings ] | ||||
); | ||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be a private API instead of a prefixed one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am working on a plan to move this fetching to become a full selector in Core Data in order to take advantage of caching...etc. So making it private would be good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #57582