From 80a0e024f03a966f854506111d71baeceb5e03a0 Mon Sep 17 00:00:00 2001 From: wpalani Date: Thu, 25 Apr 2024 14:42:57 -0700 Subject: [PATCH] Add 'bluehost-app-nav' context to notification api and component --- assets/js/components/notifications/index.js | 40 ++++++++++++++------- includes/Notification.php | 1 + includes/NotificationsApi.php | 3 +- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/assets/js/components/notifications/index.js b/assets/js/components/notifications/index.js index a0dfe5c..8dd708e 100644 --- a/assets/js/components/notifications/index.js +++ b/assets/js/components/notifications/index.js @@ -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 @@ -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, @@ -150,19 +150,33 @@ const Notifications = ({methods, constants, ...props}) => { ); } - return ( -
- {activeNotifications.map(notification => ( + if ('bluehost-app-nav' === constants.context && activeNotifications.length > 0) { + return ( +
- ))} -
- ) +
+ ); + } else { + return ( +
+ {activeNotifications.map(notification => ( + + ))} +
+ ); + } }; diff --git a/includes/Notification.php b/includes/Notification.php index debdaf5..5cf9caa 100644 --- a/includes/Notification.php +++ b/includes/Notification.php @@ -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' ); diff --git a/includes/NotificationsApi.php b/includes/NotificationsApi.php index 12f5d2c..c61af6e 100644 --- a/includes/NotificationsApi.php +++ b/includes/NotificationsApi.php @@ -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 ); @@ -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 ); }