Skip to content

Commit

Permalink
Add 'Feed Information' sidebar to edit screen for feeds.
Browse files Browse the repository at this point in the history
This sidebar currently contains an editable Feed URL field.

See #1187.
  • Loading branch information
boonebgorges committed Oct 18, 2024
1 parent e248034 commit 3a0c6d4
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 2 deletions.
10 changes: 10 additions & 0 deletions Controllers/Metas.php
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,16 @@ public function structure() {
'level' => array( 'item', 'nomination' ),
'serialize' => true,
),
'feed_url' => [
'name' => 'feed_url',
'title' => __( 'Feed URL', 'pressforward' ),
'definition' => __( 'URL of the feed', 'pressforward' ),
'function' => __( 'Stores the URL of the feed', 'pressforward' ),
'type' => [ 'struc' ],
'use' => [ 'api' ],
'level' => [ 'feed' ],
'serialize' => false,
],
'pf_feed_error_count' => array(
'name' => 'pf_feed_error_count',
'title' => __( 'Feed Errors', 'pressforward' ),
Expand Down
10 changes: 10 additions & 0 deletions Core/Providers/AssetsProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ public function admin_enqueue_styles() {
public function enqueue_block_editor_assets() {
$scripts = [
'pf-block-editor-comments' => 'block-editor-comments',
'pf-block-editor-feeds' => 'block-editor-feeds',
'pf-blocks' => 'blocks',
'pf-nominate-this-block-editor' => 'nominate-this-block-editor',
];
Expand Down Expand Up @@ -431,6 +432,15 @@ public function enqueue_block_editor_assets() {
),
);

wp_add_inline_script(
'pf-block-editor-feeds',
'window.pfBlockEditorFeeds = ' . wp_json_encode(
[
'feedPostType' => pressforward( 'schema.feeds' )->post_type,
]
),
);

$styles = [
'pf-block-editor-comments' => 'block-editor-comments',
'pf-blocks' => 'blocks',
Expand Down
59 changes: 59 additions & 0 deletions assets/src/block-editor-feeds/block-editor-feeds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/* global pfBlockEditorFeeds */

import { registerPlugin } from '@wordpress/plugins'
import { useDispatch, useSelect } from '@wordpress/data'
import { PluginDocumentSettingPanel } from '@wordpress/edit-post'
import { __ } from '@wordpress/i18n'
import { TextControl } from '@wordpress/components'

const BlockEditorFeedsInfobox = ( {} ) => {
const { editPost } = useDispatch( 'core/editor' )

const { feedPostType } = pfBlockEditorFeeds

const {
feedUrl,
postId,
postStatus,
postType
} = useSelect( ( select ) => {
const editedPostId = select( 'core/editor' ).getCurrentPostId()
const editedPostMeta = select( 'core/editor' ).getEditedPostAttribute( 'meta' )

return {
feedUrl: editedPostMeta?.feed_url || '',
postId: editedPostId,
postType: select( 'core/editor' ).getEditedPostAttribute( 'type' ),
}
} )

const isFeed = feedPostType === postType

// Show only on Feed.
if ( ! isFeed ) {
return null
}

return (
<PluginDocumentSettingPanel
icon="controls-forward"
name="pressforward-block-editor-feeds-infobox"
title={ __( 'Feed Information', 'pressforward' ) }
>
<TextControl
label={ __( 'Feed URL', 'pressforward' ) }
value={ feedUrl }
onChange={ ( newValue ) => {
editPost( { meta: { 'feed_url': newValue } } )
} }
/>
</PluginDocumentSettingPanel>
)
}

registerPlugin(
'pressforward-block-editor-feeds-infobox',
{
render: BlockEditorFeedsInfobox,
}
);
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"lint": "run-p lint:js",
"lint:eslint": "eslint --ignore-path .gitignore",
"lint:js": "npm run lint:eslint -- .",
"start": "wp-scripts start assets/src/add-feeds/add-feeds.js assets/src/block-editor-comments/block-editor-comments.js assets/src/blocks/blocks.js assets/src/blocks/blocks-frontend.js assets/src/bootstrap/bootstrap.js assets/src/edit-feeds/edit-feeds.js assets/src/nominate-this/nominate-this.js assets/src/nominate-this-block-editor/nominate-this-block-editor.js assets/src/quick-edit/quick-edit.js assets/src/reader/reader.js assets/src/scroll/scroll.js assets/src/welcome/welcome.js",
"build": "wp-scripts build assets/src/add-feeds/add-feeds.js assets/src/block-editor-comments/block-editor-comments.js assets/src/blocks/blocks.js assets/src/blocks/blocks-frontend.js assets/src/bootstrap/bootstrap.js assets/src/edit-feeds/edit-feeds.js assets/src/nominate-this/nominate-this.js assets/src/nominate-this-block-editor/nominate-this-block-editor.js assets/src/quick-edit/quick-edit.js assets/src/reader/reader.js assets/src/scroll/scroll.js assets/src/welcome/welcome.js"
"start": "wp-scripts start assets/src/add-feeds/add-feeds.js assets/src/block-editor-comments/block-editor-comments.js assets/src/block-editor-feeds/block-editor-feeds.js assets/src/blocks/blocks.js assets/src/blocks/blocks-frontend.js assets/src/bootstrap/bootstrap.js assets/src/edit-feeds/edit-feeds.js assets/src/nominate-this/nominate-this.js assets/src/nominate-this-block-editor/nominate-this-block-editor.js assets/src/quick-edit/quick-edit.js assets/src/reader/reader.js assets/src/scroll/scroll.js assets/src/welcome/welcome.js",
"build": "wp-scripts build assets/src/add-feeds/add-feeds.js assets/src/block-editor-comments/block-editor-comments.js assets/src/block-editor-feeds/block-editor-feeds.js assets/src/blocks/blocks.js assets/src/blocks/blocks-frontend.js assets/src/bootstrap/bootstrap.js assets/src/edit-feeds/edit-feeds.js assets/src/nominate-this/nominate-this.js assets/src/nominate-this-block-editor/nominate-this-block-editor.js assets/src/quick-edit/quick-edit.js assets/src/reader/reader.js assets/src/scroll/scroll.js assets/src/welcome/welcome.js"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit 3a0c6d4

Please sign in to comment.