/** * Shared editor helpers for the content blocks. */ import { __ } from '@wordpress/i18n'; import { SelectControl } from '@wordpress/components'; import { useSelect } from '@wordpress/data'; import { decodeEntities } from '@wordpress/html-entities'; export function useStations() { return useSelect( ( select: any ) => select( 'core' ).getEntityRecords( 'postType', 'streamsera_station', { per_page: -1, // all records (core-data pages through them) status: 'publish', // Every published item (any author), like the element blocks' pickers. context: 'view', } ), [] ) as any[] | null; } export function usePlayers() { return useSelect( ( select: any ) => select( 'core' ).getEntityRecords( 'postType', 'streamsera_player', { per_page: -1, // all records (core-data pages through them) status: 'publish', // Every published item (any author), like the element blocks' pickers. context: 'view', } ), [] ) as any[] | null; } export function StationSelect( { value, onChange, allowAll = false, firstLabel, }: { value: number; onChange: ( v: number ) => void; allowAll?: boolean; firstLabel?: string; } ) { const stations = useStations(); return ( ( { label: decodeEntities( s.title?.rendered || '' ) || `#${ s.id }`, value: String( s.id ), } ) ), ] } onChange={ ( v ) => onChange( parseInt( v, 10 ) || 0 ) } __nextHasNoMarginBottom /> ); } export function PlayerSelect( { value, onChange, }: { value: number; onChange: ( v: number ) => void; } ) { const players = usePlayers(); return ( ( { label: decodeEntities( p.title?.rendered || '' ) || `#${ p.id }`, value: String( p.id ), } ) ), ] } onChange={ ( v ) => onChange( parseInt( v, 10 ) || 0 ) } __nextHasNoMarginBottom /> ); }