2023-07-28 17:56:04 +02:00
|
|
|
import { SelectControl, RangeControl, PanelBody, TextControl } from '@wordpress/components';
|
2023-08-30 21:14:57 +02:00
|
|
|
import { useState } from '@wordpress/element';
|
2023-07-26 22:05:41 +02:00
|
|
|
import { InspectorControls, useBlockProps } from '@wordpress/block-editor';
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { Followers } from './followers';
|
2023-08-30 21:14:57 +02:00
|
|
|
import { useUserOptions } from '../shared/use-user-options';
|
2023-07-28 17:56:04 +02:00
|
|
|
|
|
|
|
export default function Edit( { attributes, setAttributes } ) {
|
|
|
|
const { order, per_page, selectedUser, title } = attributes;
|
|
|
|
const blockProps = useBlockProps();
|
|
|
|
const [ page, setPage ] = useState( 1 );
|
|
|
|
const orderOptions = [
|
|
|
|
{ label: __( 'New to old', 'activitypub' ), value: 'desc' },
|
|
|
|
{ label: __( 'Old to new', 'activitypub' ), value: 'asc' },
|
|
|
|
];
|
|
|
|
const usersOptions = useUserOptions();
|
2023-07-26 22:05:41 +02:00
|
|
|
const setAttributestAndResetPage = ( key ) => {
|
|
|
|
return ( value ) => {
|
|
|
|
setPage( 1 );
|
|
|
|
setAttributes( { [ key ]: value } );
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div { ...blockProps }>
|
|
|
|
<InspectorControls key="setting">
|
|
|
|
<PanelBody title={ __( 'Followers Options', 'activitypub' ) }>
|
2023-07-28 17:56:04 +02:00
|
|
|
<TextControl
|
|
|
|
label={ __( 'Title', 'activitypub' ) }
|
|
|
|
help={ __( 'Title to display above the list of followers. Blank for none.', 'activitypub' ) }
|
|
|
|
value={ title }
|
|
|
|
onChange={ value => setAttributes( { title: value } ) }
|
|
|
|
/>
|
2023-07-26 22:05:41 +02:00
|
|
|
<SelectControl
|
|
|
|
label= { __( 'Select User', 'activitypub' ) }
|
|
|
|
value={ selectedUser }
|
|
|
|
options={ usersOptions }
|
|
|
|
onChange={ setAttributestAndResetPage( 'selectedUser' ) }
|
|
|
|
/>
|
|
|
|
<SelectControl
|
|
|
|
label={ __( 'Sort', 'activitypub' ) }
|
|
|
|
value={ order }
|
|
|
|
options={ orderOptions }
|
|
|
|
onChange={ setAttributestAndResetPage( 'order' ) }
|
|
|
|
/>
|
|
|
|
<RangeControl
|
|
|
|
label={ __( 'Number of Followers', 'activitypub' ) }
|
|
|
|
value={ per_page }
|
|
|
|
onChange={ setAttributestAndResetPage( 'per_page' ) }
|
|
|
|
min={ 1 }
|
|
|
|
max={ 10 }
|
|
|
|
/>
|
|
|
|
</PanelBody>
|
|
|
|
</InspectorControls>
|
2023-07-28 17:56:04 +02:00
|
|
|
<Followers { ...attributes } page={ page } setPage={ setPage } followLinks={ false } />
|
2023-07-26 22:05:41 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|