PluginProbe
Tableberg – Simple Gutenberg Table Block / 1.1.5
Tableberg – Simple Gutenberg Table Block v1.1.5
1.1.5 1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.5 1.0.4 1.0.3 1.0.2 1.0.1 trunk 0.0.2 0.2.1 0.3.2 0.3.3 0.4.1 0.5.0 0.5.1 0.5.2 0.5.3 0.5.4 0.5.5 0.5.6 0.5.7 All 42 releases
tableberg / admin / src / components / BoxContent / BoxContentProvider.jsx

BoxContentProvider.jsx in Tableberg – Simple Gutenberg Table Block 1.1.5, at admin/src/components/BoxContent/BoxContentProvider.jsx

52 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import React, { useEffect, useState } from "react";
2 import BoxContent from "./BoxContent";
3 import ContentNotFoundError from "../../inc/err/ContentNotFoundError";
4
5 const getCData = contentId => {
6 return tablebergAdminMenuData?.[contentId];
7 };
8 /**
9 * Box content provider component.
10 * Any BoxContent component property can be passed to this component. All will be reflected to generated one.
11 * Passing content related property will make this absolutely useless since it will be overwritten by fetched data.
12 *
13 * This component will fetch given data id from store and generate BoxContent component based on it.
14 *
15 * @param {Object} props component properties
16 * @param {string} props.contentId content id
17 * @param {string} [props.size=BoxContentSize.NORMAL] box content size
18 */
19 function BoxContentProvider(props) {
20 const [contentTitle, setTitle] = useState(null);
21 const [mainContent, setContent] = useState(null);
22 const [rest, setRest] = useState({});
23
24 const { contentId, ...dataRest } = props;
25 const cData = getCData(contentId);
26
27 /**
28 * useEffect hook.
29 */
30 useEffect(() => {
31 if (cData) {
32 const { title, content } = cData;
33 setTitle(title);
34 setContent(content);
35 setRest(dataRest);
36 } else {
37 throw new ContentNotFoundError(contentId);
38 }
39 }, []);
40
41 return (
42 <BoxContent {...rest} title={contentTitle} content={mainContent}>
43 {props.children}
44 </BoxContent>
45 );
46 }
47
48 /**
49 * @module BoxContentProvider
50 */
51 export default BoxContentProvider;
52