/** * WordPress dependencies */ import { useDispatch, useSelect } from '@safe-wordpress/data'; import { useCallback } from '@safe-wordpress/element'; /** * External dependencies */ import type { Maybe, Uuid, BufferSettings } from '@nelio-content/types'; /** * Internal dependencies */ import { store as NC_SOCIAL_EDITOR } from '../store'; import type { State } from '../store/types'; export const useBufferSettings = (): State[ 'attributes' ][ 'bufferSettingsByProfile' ] => useSelect( ( select ) => select( NC_SOCIAL_EDITOR ).getBufferSettings(), [] ); export const useBufferSettingsInProfile = ( profileId: Maybe< Uuid > ): [ Maybe< BufferSettings >, ( settings: BufferSettings ) => void ] => { const settings = useSelect( ( select ) => { if ( ! profileId ) { return undefined; } const editor = select( NC_SOCIAL_EDITOR ); return editor.getBufferSettingsInProfile( profileId ); }, [ profileId ] ); const { setBufferSettingsInProfile } = useDispatch( NC_SOCIAL_EDITOR ); const setSettings = useCallback( ( updatedSettings: BufferSettings ) => { if ( ! profileId ) { return; } void setBufferSettingsInProfile( profileId, updatedSettings ); }, [ profileId, setBufferSettingsInProfile ] ); return [ settings, setSettings ]; };