| 1 |
import { useEffect, useState, useMemo } from "@wordpress/element"; |
| 2 |
import { useBlockProps } from "@wordpress/block-editor"; |
| 3 |
import InspectorControl from "../../components/inspectorControls/inspectorControls"; |
| 4 |
import { panelBodyRightIcon, panelBodyTitleIcon } from "../../icons/icons"; |
| 5 |
import { EditorWrapper } from "../shared/wrapper"; |
| 6 |
import dynamicCssFn from "./dynamicCss"; |
| 7 |
import Inspector from "./inspect"; |
| 8 |
import Render from "./render"; |
| 9 |
import { useDeviceType } from "../../controls/controls"; |
| 10 |
import { TogglePanelBodyProvider } from "../../context"; |
| 11 |
import { cssDependency } from "../shared/cssDependency"; |
| 12 |
import { compose } from "@wordpress/compose"; |
| 13 |
import addInitialAttr from "../shared/addInitialAttr"; |
| 14 |
|
| 15 |
const TimelineTwoEdit = ({ attributes, setAttributes, isSelected }) => { |
| 16 |
const { blockName, fontListsEditPage, gapBetweenPosts, contentAreaPadding, smallItemHeight, customCss } = |
| 17 |
attributes; |
| 18 |
const blockProps = useBlockProps(); |
| 19 |
const [posts, setPosts] = useState([]); |
| 20 |
const deviceType = useDeviceType(); |
| 21 |
|
| 22 |
useEffect(() => { |
| 23 |
if (!blockName) { |
| 24 |
setAttributes({ |
| 25 |
timelineLayout: "timeline-one-layout-one", |
| 26 |
imageOverlayColor: "default", |
| 27 |
gapBetweenPosts: { |
| 28 |
...gapBetweenPosts, |
| 29 |
device: { ...gapBetweenPosts.device, Desktop: 32 }, |
| 30 |
}, |
| 31 |
imagePosition: "background", |
| 32 |
contentAreaPadding: { |
| 33 |
...contentAreaPadding, |
| 34 |
device: { |
| 35 |
...contentAreaPadding.device, |
| 36 |
Desktop: { |
| 37 |
top: "0", |
| 38 |
right: "20", |
| 39 |
bottom: "20", |
| 40 |
left: "20", |
| 41 |
}, |
| 42 |
}, |
| 43 |
}, |
| 44 |
smallItemHeight: { |
| 45 |
...smallItemHeight, |
| 46 |
device: { |
| 47 |
...smallItemHeight.device, |
| 48 |
Desktop: 372, |
| 49 |
Tablet: 210, |
| 50 |
}, |
| 51 |
}, |
| 52 |
|
| 53 |
contentVerticalPosition: "bottom", |
| 54 |
}); |
| 55 |
} |
| 56 |
}, []); |
| 57 |
|
| 58 |
const blockStyling = useMemo( |
| 59 |
() => dynamicCssFn(attributes, "frontend", deviceType), |
| 60 |
[...cssDependency(attributes), deviceType, attributes] |
| 61 |
); |
| 62 |
|
| 63 |
useEffect(() => { |
| 64 |
setAttributes({ currentScreen: deviceType }); |
| 65 |
}, [deviceType]); |
| 66 |
|
| 67 |
return ( |
| 68 |
<div {...blockProps}> |
| 69 |
<style> |
| 70 |
{fontListsEditPage} |
| 71 |
{blockStyling} |
| 72 |
{customCss} |
| 73 |
</style> |
| 74 |
<TogglePanelBodyProvider> |
| 75 |
<InspectorControl |
| 76 |
TitleIcon={panelBodyTitleIcon} |
| 77 |
RightIcon={panelBodyRightIcon} |
| 78 |
Inspector={Inspector} |
| 79 |
attributes={attributes} |
| 80 |
setAttributes={setAttributes} |
| 81 |
isSelected={isSelected} |
| 82 |
/> |
| 83 |
{/* Render Html here */} |
| 84 |
<EditorWrapper setPosts={setPosts} setAttributes={setAttributes}> |
| 85 |
<Render posts={posts} attributes={attributes} page={"editor"} /> |
| 86 |
</EditorWrapper> |
| 87 |
</TogglePanelBodyProvider> |
| 88 |
</div> |
| 89 |
); |
| 90 |
}; |
| 91 |
|
| 92 |
export default compose(addInitialAttr)(TimelineTwoEdit); |
| 93 |
|