PluginProbe ʕ •ᴥ•ʔ
Post Views Counter / 1.5.1
Post Views Counter v1.5.1
1.7.13 1.7.12 1.7.11 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.2.0 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.2 1.3.2.1 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.7.0 1.7.1 1.7.10 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9
post-views-counter / blocks / post-views / src / edit.js
post-views-counter / blocks / post-views / src Last commit date
block.json 1 year ago edit.js 1 year ago index.js 1 year ago
edit.js
51 lines
1 import { Notice, Spinner, PanelBody, TextControl, SelectControl } from '@wordpress/components';
2 import { __ } from '@wordpress/i18n';
3 import { InspectorControls, useBlockProps } from '@wordpress/block-editor';
4 import ServerSideRender from '@wordpress/server-side-render';
5
6 export default function Edit( { attributes, setAttributes } ) {
7 // attributes
8 const { postID, period } = attributes;
9
10 // spinner
11 const spinner = () => {
12 return <Spinner />;
13 }
14
15 const error = ( value ) => {
16 return <Notice status="error">{ __( 'Something went wrong. Try again or refresh the page.', 'post-views-counter' ) }</Notice>;
17 }
18
19 return (
20 <>
21 <InspectorControls>
22 <PanelBody title={ __( 'Settings', 'post-views-counter' ) }>
23 <TextControl
24 __nextHasNoMarginBottom
25 label={ __( 'Post ID', 'post-views-counter' ) }
26 value={ postID }
27 onChange={ ( value ) => setAttributes( { postID: Number( value ) } ) }
28 help={ __( 'Enter 0 to use current visited post.', 'post-views-counter' ) }
29 />
30 <SelectControl
31 __nextHasNoMarginBottom
32 disabled={ pvcBlockEditorData.periods.length === 1 }
33 label={ __( 'Views period', 'post-views-counter' ) }
34 value={ period }
35 options={ pvcBlockEditorData.periods }
36 onChange={ ( value ) => setAttributes( { period: value } ) }
37 />
38 </PanelBody>
39 </InspectorControls>
40 <div { ...useBlockProps() }>
41 <ServerSideRender
42 httpMethod="POST"
43 block="post-views-counter/post-views"
44 attributes={ attributes }
45 LoadingResponsePlaceholder={ spinner }
46 ErrorResponsePlaceholder={ error }
47 />
48 </div>
49 </>
50 )
51 }