PluginProbe
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News / 4.0.8
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News v4.0.8
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 2.3.5 2.3.6 2.4.0 2.4.1 2.4.10 2.4.11 2.4.12 2.4.13 2.4.14 2.4.15 2.4.16 2.4.17 2.4.18 2.4.19 2.4.2 2.4.20 2.4.21 All 88 releases
post-carousel / src / blocks / live-filter / edit.js

edit.js in Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News 4.0.8, at src/blocks/live-filter/edit.js

133 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { useEffect, useMemo } from "@wordpress/element";
2 import { InnerBlocks, useBlockProps } from "@wordpress/block-editor";
3 import InspectorControl from "../../components/inspectorControls/inspectorControls";
4 import { panelBodyRightIcon, panelBodyTitleIcon } from "../../icons/icons";
5 import Inspector from "./inspect";
6 import dynamicCssFn from "./dynamicCss";
7 import { jsonStringify } from "../shared/helpFn";
8 import { googleFonts, useDeviceType } from "../../controls/controls";
9 import { dispatch, select, useSelect } from "@wordpress/data";
10 import { compose } from "@wordpress/compose";
11 import addInitialAttr from "../shared/addInitialAttr";
12 import { TogglePanelBodyProvider } from "../../context";
13 import Render from "./Render";
14 import useMetaData from "../../hooks/useMetaData";
15 import useUpdateParentAttributes from "../../hooks/updateParentAttr";
16 const Edit = ({ attributes, setAttributes, clientId, isSelected }) => {
17 const {
18 customCss,
19 uniqueId,
20 fieldAlignment,
21 titleTypography,
22 optionTypography,
23 additionalCssClass,
24 titleGlobalTypography,
25 optionGlobalTypography,
26 layout,
27 blockName,
28 headingTypography,
29 menuTypography,
30 multipleFilterRelation
31 } = attributes;
32
33 useUpdateParentAttributes(
34 clientId,
35 multipleFilterRelation
36 );
37
38 const innerBlocks = select("core/block-editor").getBlocks(clientId);
39 const { allTaxonomies } = useMetaData(attributes, "editSite");
40
41 // Get the count
42 const innerBlocksWidth = innerBlocks.length > 3 ? "sp-width-33" : "";
43
44 const currentDevice = useDeviceType();
45
46 useEffect(() => {
47 setAttributes({
48 innerBlockLength: innerBlocks.length,
49 });
50 }, [innerBlocks.length]);
51
52 const blockProps = useBlockProps({
53 className: additionalCssClass,
54 });
55
56 const parentBlock = useSelect((select) => {
57 return select("core/block-editor").getBlock(clientId);
58 }, []);
59
60 useEffect(() => {
61 if (!isSelected) {
62 return;
63 }
64 parentBlock.innerBlocks.forEach((innerBlock) => {
65 dispatch("core/block-editor").updateBlockAttributes(innerBlock.clientId, {
66 titleGlobalTypography,
67 optionGlobalTypography,
68 });
69 });
70 }, [parentBlock.innerBlocks, isSelected, titleGlobalTypography, optionGlobalTypography]);
71
72 const googleFontLists = [titleTypography, optionTypography, headingTypography, menuTypography];
73
74 useEffect(() => {
75 setAttributes({
76 fontLists: jsonStringify(googleFonts(googleFontLists, "frontend")),
77 });
78 }, googleFontLists);
79
80 const blockStyling = useMemo(
81 () => dynamicCssFn(attributes, "frontend", currentDevice),
82 [attributes, currentDevice]
83 );
84
85 attributes.allTaxonomies = allTaxonomies;
86
87 return (
88 <div {...blockProps}>
89 <TogglePanelBodyProvider blockName={blockName}>
90 <style>
91 {googleFonts(googleFontLists)}
92 {/* {dynamicCss(attributes)} */}
93 {blockStyling}
94 {customCss}
95 </style>
96 <InspectorControl
97 TitleIcon={panelBodyTitleIcon}
98 RightIcon={panelBodyRightIcon}
99 Inspector={Inspector}
100 attributes={attributes}
101 setAttributes={setAttributes}
102 />
103
104 <div
105 id={uniqueId}
106 className={`sp-smart-post-wrapper sp-smart-${fieldAlignment} ${innerBlocksWidth} ${layout}`}
107 >
108 <div className="sp-smart-post-live-filter-parent">
109 {layout === "layoutOne" ? (
110 <InnerBlocks
111 allowedBlocks={[
112 "sp-smart-post-show/taxonomy-filter",
113 "sp-smart-post-show/sort-filter",
114 "sp-smart-post-show/search-filter",
115 "sp-smart-post-show/author-filter",
116 ]}
117 template={[
118 ["sp-smart-post-show/taxonomy-filter"],
119 ["sp-smart-post-show/author-filter"],
120 ]}
121 />
122 ) : (
123 <Render attributes={attributes} />
124 )}
125 </div>
126 </div>
127 </TogglePanelBodyProvider>
128 </div>
129 );
130 };
131
132 export default compose(addInitialAttr)(Edit);
133