11import { useState } from 'react' ;
22import classnames from 'classnames' ;
3+ import type { WP_REST_API_Post as WpRestApiPost } from 'wp-types' ; // eslint-disable-line camelcase
4+
35// @ts -expect-error BlockContextProvider not available in types yet.
46import { InnerBlocks , useBlockProps , BlockContextProvider } from '@wordpress/block-editor' ;
5- import { PostPicker } from '@alleyinteractive/block-editor-tools' ;
7+ import { PostPicker , usePostById } from '@alleyinteractive/block-editor-tools' ;
68import { dispatch , select , useSelect } from '@wordpress/data' ;
79import { __ } from '@wordpress/i18n' ;
8- import { Button } from '@wordpress/components' ;
10+ import { Button , Notice } from '@wordpress/components' ;
911import { useCallback } from '@wordpress/element' ;
1012
1113import type { Block } from '../../types/block' ;
1214import NoRender from './norender' ;
1315import SearchFilters from '../../components/SearchFilters' ;
1416import recursivelyFindBlocksByName from '../../services/recursivelyFindBlocksByName' ;
17+ import { postTypeWithFuture } from '../../services/utils' ;
1518
1619import type {
1720 Term ,
@@ -47,6 +50,7 @@ interface PostTypeOrTerm {
4750interface Window {
4851 wpCurateQueryBlock : {
4952 allowedPostTypes : PostTypeOrTerm [ ] ;
53+ includeFuturePosts : boolean ;
5054 } ;
5155}
5256
@@ -73,6 +77,7 @@ export default function Edit({
7377 const {
7478 wpCurateQueryBlock : {
7579 allowedPostTypes = [ ] ,
80+ includeFuturePosts,
7681 } = { } ,
7782 } = ( window as any as Window ) ;
7883
@@ -282,6 +287,13 @@ export default function Edit({
282287
283288 const shouldShowFilter = displayTypes . length !== postTypes . length
284289 || Object . values ( terms ) . some ( ( termList ) => Array . isArray ( termList ) && termList . length > 0 ) ;
290+
291+ const postObj = usePostById (
292+ postId ,
293+ // @ts -ignore This function does work with this argument.
294+ includeFuturePosts ? postTypeWithFuture : null ,
295+ ) as WpRestApiPost | null ;
296+
285297 return (
286298 < div
287299 { ...useBlockProps (
@@ -296,6 +308,15 @@ export default function Edit({
296308 } ,
297309 ) }
298310 >
311+ { typeof postObj === 'object' && postObj !== null && 'status' in postObj && postObj . status === 'future' ? (
312+ < Notice
313+ status = "warning"
314+ isDismissible = { false }
315+ >
316+ { __ ( 'Scheduled' , 'wp-curate' ) }
317+ </ Notice >
318+ ) : null }
319+
299320 < BlockContextProvider value = { { postId } } >
300321 < InnerBlocks />
301322 </ BlockContextProvider >
@@ -314,6 +335,8 @@ export default function Edit({
314335 onUpdate = { updatePost }
315336 onReset = { resetPost }
316337 value = { selected ?? 0 }
338+ // @ts -ignore This function does work with this prop.
339+ getPostType = { includeFuturePosts ? postTypeWithFuture : null }
317340 previewRender = { ( NoRender ) }
318341 className = "wp-curate-post-block__post-picker"
319342 selectText = { __ ( 'Pin a Post' , 'wp-curate' ) }
@@ -326,7 +349,10 @@ export default function Edit({
326349 setFiltered = { setFiltered }
327350 />
328351 ) }
329- params = { params }
352+ params = { {
353+ ...params ,
354+ wp_curate_include_future : includeFuturePosts ,
355+ } }
330356 />
331357 {
332358 // If this post isn't already in the posts list, show a button to pin it.
0 commit comments