PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.3.8
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.3.8
4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 All 139 releases
learnpress / assets / src / apps / js / blocks / courses / list-courses / edit.js

edit.js in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.3.8, at assets/src/apps/js/blocks/courses/list-courses/edit.js

179 lines 4.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { __ } from '@wordpress/i18n';
2 import {
3 SelectControl,
4 ToggleControl,
5 PanelBody,
6 RangeControl,
7 TextControl,
8 __experimentalToolsPanel as ToolsPanel,
9 __experimentalToolsPanelItem as ToolsPanelItem,
10 } from '@wordpress/components';
11 import { useBlockProps, InspectorControls, InnerBlocks } from '@wordpress/block-editor';
12
13 const Edit = ( props ) => {
14 const blockProps = useBlockProps();
15 const { attributes, setAttributes, clientId } = props;
16 const { courseQuery } = attributes;
17
18 const QUERY_LOOP_TEMPLATE = [ [ 'learnpress/course-item-template' ] ];
19 const resetAllTaxonomy = () => {
20 setAttributes( {
21 courseQuery: {
22 ...courseQuery,
23 term_id: '',
24 tag_id: '',
25 },
26 } );
27 };
28
29 const orderByData = [
30 { label: 'Newly published', value: 'post_date' },
31 { label: 'Title a-z', value: 'post_title' },
32 { label: 'Title z-a', value: 'post_title_desc' },
33 { label: 'Price high to low', value: 'price' },
34 { label: 'Price low to high', value: 'price_low' },
35 { label: 'Popular', value: 'popular' },
36 { label: 'Average Ratings', value: 'rating' },
37 ];
38 const paginationTypes = [
39 { label: __( 'Number', 'learnpress' ), value: 'number' },
40 { label: __( 'Load more', 'learnpress' ), value: 'load-more' },
41 { label: __( 'Infinite Scroll', 'learnpress' ), value: 'infinite' },
42 ];
43
44 return (
45 <>
46 <InspectorControls>
47 <PanelBody title={ __( 'Query Settings', 'learnpress' ) }>
48 <RangeControl
49 label={ __( 'Posts per page' ) }
50 value={ courseQuery.limit }
51 onChange={ ( limit ) =>
52 setAttributes( {
53 courseQuery: { ...courseQuery, limit },
54 } )
55 }
56 min={ 1 }
57 max={ 20 }
58 />
59 <ToggleControl
60 label={ __( 'Related Course', 'learnpress' ) }
61 checked={ courseQuery.related }
62 onChange={ ( related ) => {
63 if ( related ) {
64 setAttributes( {
65 courseQuery: {
66 ...courseQuery,
67 term_id: '',
68 tag_id: '',
69 pagination: false,
70 order_by: 'post_date',
71 related,
72 },
73 } );
74 } else {
75 setAttributes( {
76 courseQuery: { ...courseQuery, related },
77 } );
78 }
79 } }
80 />
81 <ToggleControl
82 label={ __( 'Enable AJAX', 'learnpress' ) }
83 checked={ courseQuery.load_ajax }
84 onChange={ ( load_ajax ) => {
85 setAttributes( {
86 courseQuery: {
87 ...courseQuery,
88 load_ajax,
89 load_ajax_after: ! load_ajax ? false : courseQuery.load_ajax_after,
90 },
91 } );
92 } }
93 />
94
95 { ! courseQuery.related && (
96 <SelectControl
97 label={ __( 'Order by', 'learnpress' ) }
98 value={ courseQuery.order_by }
99 options={ orderByData }
100 onChange={ ( order_by ) => {
101 setAttributes( {
102 courseQuery: { ...courseQuery, order_by },
103 } );
104 } }
105 />
106 ) }
107
108 { ! courseQuery.related && (
109 <ToggleControl
110 label={ __( 'Pagination', 'learnpress' ) }
111 checked={ courseQuery.pagination }
112 onChange={ ( pagination ) => {
113 setAttributes( {
114 courseQuery: {
115 ...courseQuery,
116 pagination,
117 pagination_type: ! pagination ? 'number' : courseQuery.pagination_type,
118 },
119 } );
120 } }
121 />
122 ) }
123
124 { courseQuery.pagination && (
125 <SelectControl
126 label={ __( 'Pagination Type', 'learnpress' ) }
127 value={ courseQuery.pagination_type }
128 options={ paginationTypes }
129 onChange={ ( pagination_type ) => {
130 setAttributes( {
131 courseQuery: { ...courseQuery, pagination_type },
132 } );
133 } }
134 />
135 ) }
136 </PanelBody>
137 { /* { ! courseQuery.related && (
138 <ToolsPanel label={ __( 'Filter', 'learnpress' ) } resetAll={ resetAllTaxonomy }>
139 <ToolsPanelItem
140 label={ __( 'Taxonomy', 'learnpress' ) }
141 onSelect={ () => resetAllTaxonomy() }
142 hasValue={ () => !! courseQuery.term_id || !! courseQuery.tag_id }
143 onDeselect={ () => resetAllTaxonomy() }
144 >
145 <TextControl
146 label={ __( 'Category', 'learnpress' ) }
147 onChange={ ( term_id ) => {
148 setAttributes( {
149 courseQuery: {
150 ...courseQuery,
151 term_id,
152 },
153 } );
154 } }
155 value={ courseQuery.term_id ?? '' }
156 />
157
158 <TextControl
159 label={ __( 'Tag', 'learnpress' ) }
160 onChange={ ( tag_id ) => {
161 setAttributes( {
162 courseQuery: { ...courseQuery, tag_id },
163 } );
164 } }
165 value={ courseQuery.tag_id ?? '' }
166 />
167 </ToolsPanelItem>
168 </ToolsPanel>
169 ) } */ }
170 </InspectorControls>
171 <div { ...blockProps }>
172 <InnerBlocks template={ QUERY_LOOP_TEMPLATE } />
173 </div>
174 </>
175 );
176 };
177
178 export default Edit;
179