From 45cba3e0d9f1ecbdaff859d76077e572031b9f0f Mon Sep 17 00:00:00 2001 From: Swara Date: Fri, 17 Feb 2023 00:03:39 +0100 Subject: [PATCH] disable read all button if it has no unread messages --- src/Platform/Http/Screens/NotificationScreen.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Platform/Http/Screens/NotificationScreen.php b/src/Platform/Http/Screens/NotificationScreen.php index c6b7af776..078d20388 100644 --- a/src/Platform/Http/Screens/NotificationScreen.php +++ b/src/Platform/Http/Screens/NotificationScreen.php @@ -41,6 +41,11 @@ class NotificationScreen extends Screen */ private $isNotEmpty = false; + /** + * @var bool + */ + private $hasUnread = false; + /** * Query data. * @@ -56,6 +61,9 @@ public function query(Request $request): iterable ->paginate(10); $this->isNotEmpty = $notifications->isNotEmpty(); + + $unreadNotifications = $request->user()->unreadNotifications; + $this->hasUnread = boolval(count($unreadNotifications)); return [ 'notifications' => $notifications, @@ -79,6 +87,7 @@ public function commandBar(): iterable Button::make(__('Mark all as read')) ->icon('eye') ->method('markAllAsRead') + ->disabled(!$this->hasUnread) ->canSee($this->isNotEmpty), ]; }