Skip to:
Content

BuddyPress.org

Changeset 13130


Ignore:
Timestamp:
10/28/2021 01:36:47 PM (3 years ago)
Author:
imath
Message:

Directly fetch post author activities into the Latest Activities block

When used into the Post Editor, it's the expected behavior.

Props vapvarun

Fixes #8593

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-activity/js/blocks/latest-activities.js

    r13001 r13130  
    129129 * WordPress dependencies.
    130130 */
    131 var _wp = wp,
    132     InspectorControls = _wp.blockEditor.InspectorControls,
    133     _wp$components = _wp.components,
    134     Disabled = _wp$components.Disabled,
    135     PanelBody = _wp$components.PanelBody,
    136     RangeControl = _wp$components.RangeControl,
    137     SelectControl = _wp$components.SelectControl,
    138     TextControl = _wp$components.TextControl,
    139     _wp$element = _wp.element,
    140     Fragment = _wp$element.Fragment,
    141     createElement = _wp$element.createElement,
    142     __ = _wp.i18n.__;
     131const {
     132  blockEditor: {
     133    InspectorControls
     134  },
     135  components: {
     136    Disabled,
     137    PanelBody,
     138    RangeControl,
     139    SelectControl,
     140    TextControl
     141  },
     142  element: {
     143    Fragment,
     144    createElement
     145  },
     146  i18n: {
     147    __
     148  }
     149} = wp;
    143150/**
    144151 * BuddyPress dependencies.
    145152 */
    146153
    147 var _bp = bp,
    148     ServerSideRender = _bp.blockComponents.ServerSideRender,
    149     _bp$blockData = _bp.blockData,
    150     currentPostId = _bp$blockData.currentPostId,
    151     activityTypes = _bp$blockData.activityTypes;
    152 
    153 var editDynamicActivitiesBlock = function editDynamicActivitiesBlock(_ref) {
    154   var attributes = _ref.attributes,
    155       setAttributes = _ref.setAttributes;
    156   var postId = attributes.postId,
    157       maxActivities = attributes.maxActivities,
    158       type = attributes.type,
    159       title = attributes.title;
    160   var post = currentPostId();
    161   var types = activityTypes();
     154const {
     155  blockComponents: {
     156    ServerSideRender
     157  },
     158  blockData: {
     159    currentPostId,
     160    activityTypes
     161  }
     162} = bp;
     163
     164const editDynamicActivitiesBlock = ({
     165  attributes,
     166  setAttributes
     167}) => {
     168  const {
     169    postId,
     170    maxActivities,
     171    type,
     172    title
     173  } = attributes;
     174  const post = currentPostId();
     175  const types = activityTypes();
    162176
    163177  if (!postId && post) {
     
    165179      postId: post
    166180    });
     181
     182    if (!attributes.postId) {
     183      attributes.postId = post;
     184    }
    167185  }
    168186
     
    174192    label: __('Title', 'buddypress'),
    175193    value: title,
    176     onChange: function onChange(text) {
     194    onChange: text => {
    177195      setAttributes({
    178196        title: text
     
    182200    label: __('Maximum amount to display', 'buddypress'),
    183201    value: maxActivities,
    184     onChange: function onChange(value) {
    185       return setAttributes({
    186         maxActivities: value
    187       });
    188     },
     202    onChange: value => setAttributes({
     203      maxActivities: value
     204    }),
    189205    min: 1,
    190206    max: 10,
     
    195211    value: type,
    196212    options: types,
    197     onChange: function onChange(option) {
     213    onChange: option => {
    198214      setAttributes({
    199215        type: option
     
    219235 * WordPress dependencies.
    220236 */
    221 var _wp = wp,
    222     createBlock = _wp.blocks.createBlock;
     237const {
     238  blocks: {
     239    createBlock
     240  }
     241} = wp;
    223242/**
    224243 * Transforms Nouveau Activity Widget to Activity Block.
     
    227246 */
    228247
    229 var transforms = {
     248const transforms = {
    230249  from: [{
    231250    type: 'block',
    232251    blocks: ['core/legacy-widget'],
    233     isMatch: function isMatch(_ref) {
    234       var idBase = _ref.idBase,
    235           instance = _ref.instance;
    236 
     252    isMatch: ({
     253      idBase,
     254      instance
     255    }) => {
    237256      if (!(instance !== null && instance !== void 0 && instance.raw)) {
    238257        return false;
     
    241260      return idBase === 'bp_latest_activities';
    242261    },
    243     transform: function transform(_ref2) {
    244       var instance = _ref2.instance;
    245       var regex = /i:\d*;s:\d*:"(.*?)";/gmi;
    246       var types = [];
    247       var matches;
     262    transform: ({
     263      instance
     264    }) => {
     265      const regex = /i:\d*;s:\d*:"(.*?)";/gmi;
     266      let types = [];
     267      let matches;
    248268
    249269      while ((matches = regex.exec(instance.raw.type)) !== null) {
     
    252272        }
    253273
    254         matches.forEach(function (match, groupIndex) {
     274        matches.forEach((match, groupIndex) => {
    255275          if (1 === groupIndex) {
    256276            types.push(match);
     
    281301 * WordPress dependencies.
    282302 */
    283 var _wp = wp,
    284     registerBlockType = _wp.blocks.registerBlockType,
    285     __ = _wp.i18n.__;
     303const {
     304  blocks: {
     305    registerBlockType
     306  },
     307  i18n: {
     308    __
     309  }
     310} = wp;
    286311/**
    287312 * Internal dependencies.
  • trunk/src/js/bp-activity/js/blocks/latest-activities/edit.js

    r13001 r13130  
    4242    if ( ! postId && post ) {
    4343        setAttributes( { postId: post } );
     44        if ( ! attributes.postId ) {
     45            attributes.postId = post;
     46        }
    4447    }
    4548
Note: See TracChangeset for help on using the changeset viewer.