Skip to content

Commit

Permalink
Add 'bluehost-app-nav' context to notification api and component
Browse files Browse the repository at this point in the history
  • Loading branch information
wpalani committed Apr 25, 2024
1 parent 0f90aef commit 80a0e02
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
40 changes: 27 additions & 13 deletions assets/js/components/notifications/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ const Notifications = ({methods, constants, ...props}) => {
)
}).then( ( response ) => {
setAllNotifications(response);
});
}, [] );
});
}, [] );

// on update notifications, context or page calculate active notifications
methods.useEffect(() => {
setActiveNotifications(
filterNotifications(allNotifications)
);
}, [allNotifications, constants.page]);
}, [allNotifications, constants.page]);

/**
* Wrapper method to filter notifications
Expand Down Expand Up @@ -73,7 +73,7 @@ const Notifications = ({methods, constants, ...props}) => {
* @returns Array of filtered notifications - removes expired notifications
*/
const filterByExpiry = (notifications) => {
const now = Date.now();
const now = Math.round(Date.now() / 1000);
// console.log( 'Now: ' + now );
// filter out expired notifications
return methods.filter(notifications,
Expand Down Expand Up @@ -150,19 +150,33 @@ const Notifications = ({methods, constants, ...props}) => {
);
}

return (
<div className={methods.classnames('newfold-notifications-wrapper')}>
{activeNotifications.map(notification => (
if ('bluehost-app-nav' === constants.context && activeNotifications.length > 0) {
return (
<div className={methods.classnames('newfold-nav-notifications-wrapper nfd-mt-4')}>
<Notification
id={notification.id}
key={notification.id}
content={notification.content}
id={activeNotifications[0].id}
key={activeNotifications[0].id}
content={activeNotifications[0].content}
constants={constants}
methods={methods}
/>
))}
</div>
)
</div>
);
} else {
return (
<div className={methods.classnames('newfold-notifications-wrapper')}>
{activeNotifications.map(notification => (
<Notification
id={notification.id}
key={notification.id}
content={notification.content}
constants={constants}
methods={methods}
/>
))}
</div>
);
}

};

Expand Down
1 change: 1 addition & 0 deletions includes/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public function shouldShow( $context, array $contextData ) {
}

case container()->plugin()->id . '-plugin':
case container()->plugin()->id . '-app-nav':
// The current page
$current_page = Arr::get( $contextData, 'page' );

Expand Down
3 changes: 2 additions & 1 deletion includes/NotificationsApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function ( Notification $notification ) {
'validate_callback' => function ( $value ) {
return is_string( $value ) && in_array( $value, array(
container()->plugin()->id . '-plugin',
container()->plugin()->id . '-app-nav',
'wp-admin-notice',
'wp-admin-prime'
), true );
Expand All @@ -61,7 +62,7 @@ function ( Notification $notification ) {
'required' => false,
'validate_callback' => function ( $value, \WP_REST_Request $request ) {
$context = $request->get_param( 'context' );
if ( container()->plugin()->id . '-plugin' === $context || 'wp-admin-notice' === $context ) {
if ( container()->plugin()->id . '-plugin' === $context || container()->plugin()->id . '-app-nav' === $context || 'wp-admin-notice' === $context ) {
return is_string( $value );
}

Expand Down

0 comments on commit 80a0e02

Please sign in to comment.