PluginProbe ʕ •ᴥ•ʔ
Starter Sites & Templates by Neve / trunk
Starter Sites & Templates by Neve vtrunk
1.4.0 1.3.0 1.2.29 1.2.28 1.2.6 1.2.7 1.2.8 1.2.9 trunk 1.0.10 1.0.11 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 1.1.20 1.1.21 1.1.22 1.1.23 1.1.24 1.1.25 1.1.26 1.1.27 1.1.28 1.1.29 1.1.3 1.1.30 1.1.31 1.1.32 1.1.33 1.1.34 1.1.35 1.1.36 1.1.37 1.1.38 1.1.39 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.3 1.2.4 1.2.5
templates-patterns-collection / beaver / src / components / export.js
templates-patterns-collection / beaver / src / components Last commit date
content.js 5 years ago export.js 5 years ago filters.js 5 years ago header.js 1 year ago list-item.js 5 years ago pagination.js 5 years ago preview.js 1 year ago templates-content.js 5 years ago
export.js
185 lines
1 /* eslint-disable no-undef */
2 import { v4 as uuidv4 } from 'uuid';
3
4 import { Button, Icon, ToggleControl } from '@wordpress/components';
5 import { useDispatch } from '@wordpress/data';
6 import { useState, useEffect } from '@wordpress/element';
7 import { cloudUpload, rotateRight } from '@wordpress/icons';
8
9 import { fetchLibrary } from './../data/templates-cloud/index';
10
11 const Export = () => {
12 const { updateCurrentTab } = useDispatch( 'tpc/beaver' );
13
14 const [ isLoading, setLoading ] = useState( false );
15
16 const [ templateSync, setTemplateSync ] = useState(
17 Boolean( window.tiTpc.postMeta._ti_tpc_template_sync )
18 );
19
20 const [ screenshotURL, setScreenshotURL ] = useState(
21 window.tiTpc.postMeta._ti_tpc_screenshot_url
22 );
23
24 const [ siteSlug, setSiteSlug ] = useState(
25 window.tiTpc.postMeta._ti_tpc_site_slug
26 );
27
28 const [ isPublished, setPublished ] = useState(
29 'yes' === window.tiTpc.postMeta._ti_tpc_published ? true : false
30 );
31
32 useEffect( () => {
33 window.tiTpc.postMeta._ti_tpc_template_sync = templateSync;
34 window.tiTpc.postMeta._ti_tpc_screenshot_url = screenshotURL;
35 window.tiTpc.postMeta._ti_tpc_site_slug = siteSlug;
36 window.tiTpc.postMeta._ti_tpc_published = isPublished ? 'yes' : 'no';
37 }, [ templateSync, screenshotURL, siteSlug, isPublished ] );
38
39 const onSave = () => {
40 setLoading( true );
41
42 FLBuilder.ajax(
43 {
44 action: 'ti_export_page_template',
45 is_sync: Number( templateSync ),
46 },
47 ( response ) => {
48 setLoading( false );
49
50 if ( undefined !== response.success && ! response.success ) {
51 return FLBuilder.alert(
52 `<h1>${ window.tiTpc.exporter.exportFailed }</h1> ${ response.data }`
53 );
54 }
55
56 localStorage.setItem( 'tpcCacheBuster', uuidv4() );
57 fetchLibrary();
58 updateCurrentTab( 'library' );
59 }
60 );
61 };
62
63 const publishPage = () => {
64 setLoading( true );
65
66 FLBuilder.ajax(
67 {
68 action: 'ti_publish_template',
69 slug: siteSlug,
70 screenshot: screenshotURL,
71 premade: ! isPublished ? 'yes' : 'no',
72 },
73 ( response ) => {
74 setLoading( false );
75
76 if ( undefined !== response.success && ! response.success ) {
77 return FLBuilder.alert(
78 `<h1>${ window.tiTpc.exporter.exportFailed }</h1> ${ response.data }`
79 );
80 }
81
82 setPublished( ! isPublished );
83 localStorage.setItem( 'tpcCacheBuster', uuidv4() );
84 }
85 );
86 };
87
88 return (
89 <div className="tpc-modal-content">
90 <div className="tpc-modal-content-export">
91 <div className="tpc-modal-content-export-icon">
92 <Icon icon={ cloudUpload } />
93 </div>
94
95 <div className="tpc-modal-content-export-title">
96 { window.tiTpc.library.export.title }
97 </div>
98
99 <div className="tpc-modal-content-export-field">
100 <input
101 className="tpc-modal-content-export-field-input"
102 value={
103 window.tiTpc.pageTitle ||
104 window.tiTpc.exporter.textPlaceholder
105 }
106 disabled
107 />
108
109 <Button
110 className="tpc-modal-content-export-field-submit"
111 disabled={ isLoading }
112 icon={ isLoading ? rotateRight : '' }
113 onClick={ onSave }
114 >
115 { window.tiTpc.library.export.save }
116 </Button>
117 </div>
118
119 <div className="tpc-modal-content-export-field">
120 <ToggleControl
121 label={ window.tiTpc.exporter.toggleLabel }
122 checked={ templateSync }
123 onChange={ () => setTemplateSync( ! templateSync ) }
124 />
125 </div>
126
127 { window.tiTpc.canPredefine && (
128 <>
129 <div className="tpc-modal-content-export-field">
130 <label
131 htmlFor="tpc-template-screenshot"
132 className="tpc-modal-content-export-field-input-label"
133 >
134 { window.tiTpc.library.export.labelScreenshot }
135 </label>
136
137 <input
138 className="tpc-modal-content-export-field-input"
139 id="tpc-template-screenshot"
140 value={ screenshotURL }
141 onChange={ ( e ) =>
142 setScreenshotURL( e.target.value )
143 }
144 />
145 </div>
146
147 <div className="tpc-modal-content-export-field">
148 <label
149 htmlFor="tpc-template-slug"
150 className="tpc-modal-content-export-field-input-label"
151 >
152 { window.tiTpc.library.export.labelSlug }
153 </label>
154
155 <input
156 className="tpc-modal-content-export-field-input"
157 id="tpc-template-slug"
158 value={ siteSlug }
159 onChange={ ( e ) =>
160 setSiteSlug( e.target.value )
161 }
162 />
163 </div>
164
165 <div className="tpc-modal-content-export-field">
166 <Button
167 className="tpc-modal-content-export-field-submit"
168 disabled={ isLoading }
169 icon={ isLoading ? rotateRight : '' }
170 onClick={ publishPage }
171 >
172 { isPublished
173 ? window.tiTpc.library.export.unpublish
174 : window.tiTpc.library.export.publish }
175 </Button>
176 </div>
177 </>
178 ) }
179 </div>
180 </div>
181 );
182 };
183
184 export default Export;
185