Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Feb 7, 2025
1 parent c8a2324 commit b0646aa
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function load_wpcom_dashboard_widgets() {
foreach ( $layout['secondary'] as $item ) {
if ( is_array( $item ) ) {
$tasks = $item;
break;
}
}
}
Expand Down Expand Up @@ -120,13 +121,6 @@ function enqueue_wpcom_dashboard_widgets( $args = array() ) {
'hasCustomDomain' => wpcom_site_has_feature( 'custom-domain' ),
'siteId' => get_current_blog_id(),
'tasks' => $args['tasks'],
'siteSuggestions' => Client::wpcom_json_api_request_as_blog(
'/sites/' . get_current_blog_id() . '/home/layout',
'v2',
array(),
null,
'wpcom'
),
)
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import apiFetch from '@wordpress/api-fetch';
import { useEffect, useState } from '@wordpress/element';
import { useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import TaskDomainUpsell from './tasks/home-task-domain-upsell';

Expand All @@ -9,27 +8,8 @@ const taskMap = {
'home-task-domain-upsell': TaskDomainUpsell,
};

export default ( { siteId } ) => {
const [ response, setResponse ] = useState( [] );
export default ( { tasks } ) => {
const [ index, setIndex ] = useState( 0 );

useEffect( () => {
const path = `/wpcom/v2/sites/${ siteId }/home/layout`;
apiFetch( { path } ).then( setResponse );
}, [ siteId ] );

if ( ! Array.isArray( response?.secondary ) ) {
return null;
}

// The secondary array countains strings that refer to cards, except for the
// tasks which is an array.
const tasks = response.secondary.find( item => Array.isArray( item ) );

if ( ! tasks ) {
return <p>{ __( 'No suggestions.', 'jetpack-mu-wpcom' ) }</p>;
}

const task = tasks[ index ];
const TaskComponent = taskMap[ task ];

Expand All @@ -52,38 +32,7 @@ export default ( { siteId } ) => {
{ __( 'Next →', 'jetpack-mu-wpcom' ) }
</button>
</p>
{ TaskComponent ? (
<TaskComponent />
) : (
<p style={ { minHeight: '180px' } }>To do: { task }</p>
) }
{ /* { createPortal(
<span className="wpcom_general_tasks_widget_buttons">
<button
className="button button-link"
onClick={ event => {
event.preventDefault();
event.stopPropagation();
setIndex( index - 1 );
} }
disabled={ index === 0 }
>
{ __( '← Previous', 'jetpack-mu-wpcom' ) }
</button>
<button
className="button button-link"
onClick={ event => {
event.preventDefault();
event.stopPropagation();
setIndex( index + 1 );
} }
disabled={ index === tasks.length - 1 }
>
{ __( 'Next →', 'jetpack-mu-wpcom' ) }
</button>
</span>,
document.querySelector( '#wpcom_general_tasks_widget .wpcom_general_tasks_widget_title' )
) } */ }
{ TaskComponent ? <TaskComponent /> : <p style={ { minHeight: '180px' } }>[{ task }]</p> }
</>
);
};

0 comments on commit b0646aa

Please sign in to comment.