import classnames from 'classnames/dedupe'; import { InspectorControls, useBlockProps } from '@wordpress/block-editor'; import { ExternalLink, PanelBody, Placeholder, Spinner, TextControl, ToggleControl, } from '@wordpress/components'; import { useSelect } from '@wordpress/data'; import { applyFilters } from '@wordpress/hooks'; import { __ } from '@wordpress/i18n'; import GapSettings from '../../components/gap-settings'; import RangeControl from '../../components/range-control'; import getIcon from '../../utils/get-icon'; /** * Block Edit Class. * * @param props */ export default function BlockEdit(props) { const { setAttributes, attributes } = props; let { className } = props; const { accessToken, count, columns, gap, gapCustom, showProfileAvatar, profileAvatarSize, showProfileName, showProfileStats, showProfileBio, showProfileWebsite, } = attributes; const { instagramFeed, instagramProfile } = useSelect((select) => { if (!accessToken) { return false; } return { instagramFeed: select('ghostkit/blocks/instagram').getInstagramFeed( { access_token: accessToken, count, } ), instagramProfile: select( 'ghostkit/blocks/instagram' ).getInstagramProfile({ access_token: accessToken, }), }; }); const showProfile = attributes.showProfile && (showProfileName || showProfileAvatar || showProfileBio || showProfileWebsite || showProfileStats); className = classnames( 'ghostkit-instagram', gap && `ghostkit-instagram-gap-${gap}`, columns && `ghostkit-instagram-columns-${columns}`, className ); className = applyFilters('ghostkit.editor.className', className, props); const blockProps = useBlockProps({ className }); return ( <> {accessToken ? ( <> setAttributes({ count: value }) } min={1} max={20} allowCustomMax /> setAttributes({ columns: value }) } min={1} max={8} allowCustomMax /> { setAttributes(data); }} /> setAttributes({ showProfile: val }) } /> {attributes.showProfile ? ( <> setAttributes({ showProfileAvatar: val, }) } /> {showProfileAvatar ? ( setAttributes({ profileAvatarSize: value, }) } min={30} max={150} allowCustomMin allowCustomMax /> ) : null} setAttributes({ showProfileName: val, }) } /> setAttributes({ showProfileStats: val, }) } /> setAttributes({ showProfileBio: val, }) } /> setAttributes({ showProfileWebsite: val, }) } /> ) : null} ) : null} setAttributes({ accessToken: value }) } />

{__( 'A valid Access Token is required to use Instagram feed. How to get token', 'ghostkit' )}{' '} http://instagram.pixelunion.net/

{accessToken && showProfile && instagramProfile && instagramProfile.data ? (
{showProfileAvatar && instagramProfile.data.profile_picture ? (
{instagramProfile.data.full_name}
) : null}
{showProfileName && instagramProfile.data.username ? (
{instagramProfile.data.username}
) : null} {showProfileStats && instagramProfile.data.counts ? (
{instagramProfile.data.counts.media} {' '} {__('Posts', 'ghostkit')}
{ instagramProfile.data.counts .followed_by } {' '} {__('Followers', 'ghostkit')}
{ instagramProfile.data.counts .follows } {' '} {__('Following', 'ghostkit')}
) : null} {showProfileBio && instagramProfile.data.bio ? (

{instagramProfile.data.full_name}

{instagramProfile.data.bio}
) : null} {showProfileWebsite && instagramProfile.data.website ? (
{instagramProfile.data.website}
) : null}
) : null} {accessToken && instagramFeed && instagramFeed.data ? (
{instagramFeed.data.map((item, i) => { const itemName = `instagram-item-${i}`; return (
{item.caption
); })}
) : null} {accessToken && (!instagramFeed || !instagramFeed.data) ? (
) : null} {!accessToken ? ( ) : null}
); }