Server IP : 192.158.238.246 / Your IP : 18.118.30.3 Web Server : LiteSpeed System : Linux uniform.iwebfusion.net 4.18.0-553.27.1.lve.1.el8.x86_64 #1 SMP Wed Nov 20 15:58:00 UTC 2024 x86_64 User : jenniferflocom ( 1321) PHP Version : 8.1.32 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /proc/7779/task/7779/cwd/plugins/gutenkit-blocks-addon/src/blocks/post-tab/ |
Upload File : |
import { useBlockProps } from '@wordpress/block-editor'; import Settings from './settings'; import classNames from 'classnames'; import Header from './parts/header'; import Body from './parts/body'; import { useEffect, useState } from '@wordpress/element'; import apiFetch from '@wordpress/api-fetch'; export default function Edit( { attributes, setAttributes, advancedControl } ) { const { GkitStyle } = window.gutenkit.components; const { useDeviceType } = window.gutenkit.helpers; const blockProps = useBlockProps(); const device = useDeviceType(); const wrapperProps = { className: classNames( 'gkit-post-tab', 'post--tab' ), 'data-event': attributes.eventType, }; const [posts, setPosts] = useState([]); useEffect(() => { if(attributes?.selectedCatagories.length === 0) { apiFetch({ path: `/wp/v2/categories?per_page=15` }) .then((response) => { const catagories = response.map((category) => { return { label: category?.name, value: category?.id } }) setPosts(catagories) }) .catch((error) => { console.error(error) }) } else { setPosts(attributes?.selectedCatagories) } }, [attributes?.selectedCatagories]) return ( <> <GkitStyle blocksCSS={ attributes?.blocksCSS } /> <Settings attributes={ attributes } setAttributes={ setAttributes } device={ device } advancedControl={ advancedControl } /> <div { ...blockProps }> <div { ...wrapperProps }> <div className="tab-header"> <div className="tab__list"> { posts.map( ( category, index ) => ( <Header key={ index } category={ category } index={ index } eventType={ attributes.eventType } /> ) ) } </div> </div> <div className="gkit--tab__post__details tab-content"> { posts.map( ( category, index ) => ( <Body key={ index } category={ category } attributes={ attributes } index={ index } /> ) ) } </div> </div> </div> </> ); }