[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/js/bp-groups/js/blocks/group/ -> edit.js (source)

   1  /**
   2   * WordPress dependencies.
   3   */
   4  const {
   5      blockEditor: {
   6          InspectorControls,
   7          BlockControls,
   8      },
   9      components: {
  10          Placeholder,
  11          Disabled,
  12          PanelBody,
  13          SelectControl,
  14          ToggleControl,
  15          Toolbar,
  16          ToolbarButton,
  17      },
  18      element: {
  19          Fragment,
  20          createElement,
  21      },
  22      i18n: {
  23          __,
  24      },
  25      serverSideRender: ServerSideRender,
  26  } = wp;
  27  
  28  /**
  29   * BuddyPress dependencies.
  30   */
  31  const {
  32      blockComponents: {
  33          AutoCompleter,
  34      },
  35      blockData: {
  36          isActive,
  37      }
  38  } = bp;
  39  
  40  /**
  41   * Internal dependencies.
  42   */
  43  import { AVATAR_SIZES, GROUP_STATI } from './constants';
  44  
  45  const getSlugValue = ( item ) => {
  46      if ( item && item.status && GROUP_STATI[ item.status ] ) {
  47          return GROUP_STATI[ item.status ];
  48      }
  49  
  50      return null;
  51  }
  52  
  53  const editGroupBlock = ( { attributes, setAttributes } ) => {
  54      const isAvatarEnabled = isActive( 'groups', 'avatar' );
  55      const isCoverImageEnabled = isActive( 'groups', 'cover' );
  56      const { avatarSize, displayDescription, displayActionButton, displayCoverImage } = attributes;
  57  
  58      if ( ! attributes.itemID ) {
  59          return (
  60              <Placeholder
  61                  icon="buddicons-groups"
  62                  label={ __( 'BuddyPress Group', 'buddypress' ) }
  63                  instructions={ __( 'Start typing the name of the group you want to feature into this post.', 'buddypress' ) }
  64              >
  65                  <AutoCompleter
  66                      component="groups"
  67                      objectQueryArgs={ { 'show_hidden': false } }
  68                      slugValue={ getSlugValue }
  69                      ariaLabel={ __( 'Group\'s name', 'buddypress' ) }
  70                      placeholder={ __( 'Enter Group\'s name hereā€¦', 'buddypress' ) }
  71                      onSelectItem={ setAttributes }
  72                      useAvatar={ isAvatarEnabled }
  73                  />
  74              </Placeholder>
  75          );
  76      }
  77  
  78      return (
  79          <Fragment>
  80              <BlockControls>
  81                  <Toolbar label={ __( 'Block toolbar', 'buddypress' ) }>
  82                      <ToolbarButton
  83                          icon="edit"
  84                          title={ __( 'Select another group', 'buddypress' ) }
  85                          onClick={ () => {
  86                              setAttributes( { itemID: 0 } );
  87                          } }
  88                      />
  89                  </Toolbar>
  90              </BlockControls>
  91              <InspectorControls>
  92                  <PanelBody title={ __( 'Settings', 'buddypress' ) } initialOpen={ true }>
  93                      <ToggleControl
  94                          label={ __( 'Display Group\'s home button', 'buddypress' ) }
  95                          checked={ !! displayActionButton }
  96                          onChange={ () => {
  97                              setAttributes( { displayActionButton: ! displayActionButton } );
  98                          } }
  99                          help={
 100                              displayActionButton
 101                                  ? __( 'Include a link to the group\'s home page under their name.', 'buddypress' )
 102                                  : __( 'Toggle to display a link to the group\'s home page under their name.', 'buddypress' )
 103                          }
 104                      />
 105  
 106                      <ToggleControl
 107                          label={ __( 'Display group\'s description', 'buddypress' ) }
 108                          checked={ !! displayDescription }
 109                          onChange={ () => {
 110                              setAttributes( { displayDescription: ! displayDescription } );
 111                          } }
 112                          help={
 113                              displayDescription
 114                                  ? __( 'Include the group\'s description under their name.', 'buddypress' )
 115                                  : __( 'Toggle to display the group\'s description under their name.', 'buddypress' )
 116                          }
 117                      />
 118  
 119                      { isAvatarEnabled && (
 120                          <SelectControl
 121                              label={ __( 'Avatar size', 'buddypress' ) }
 122                              value={ avatarSize }
 123                              options={ AVATAR_SIZES }
 124                              help={ __( 'Select "None" to disable the avatar.', 'buddypress' ) }
 125                              onChange={ ( option ) => {
 126                                  setAttributes( { avatarSize: option } );
 127                              } }
 128                          />
 129                      ) }
 130  
 131                      { isCoverImageEnabled && (
 132                          <ToggleControl
 133                              label={ __( 'Display Cover Image', 'buddypress' ) }
 134                              checked={ !! displayCoverImage }
 135                              onChange={ () => {
 136                                  setAttributes( { displayCoverImage: ! displayCoverImage } );
 137                              } }
 138                              help={
 139                                  displayCoverImage
 140                                      ? __( 'Include the group\'s cover image over their name.', 'buddypress' )
 141                                      : __( 'Toggle to display the group\'s cover image over their name.', 'buddypress' )
 142                              }
 143                          />
 144                      ) }
 145                  </PanelBody>
 146              </InspectorControls>
 147              <Disabled>
 148                  <ServerSideRender block="bp/group" attributes={ attributes } />
 149              </Disabled>
 150          </Fragment>
 151      );
 152  };
 153  
 154  export default editGroupBlock;


Generated: Fri May 5 01:01:24 2023 Cross-referenced by PHPXref 0.7.1