From 00f2a607e6fe3bc5959f6f5364870a77d7d61023 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Fri, 10 Jun 2022 11:14:18 +0300 Subject: [PATCH] New apps, version and all notification count and read issue solved. #2yrpaz9 --- app/Http/Livewire/Menu/Notifications.php | 44 ++++++++++++++++--- app/Listeners/Menu/ShowInNotifications.php | 3 +- app/View/Components/Layouts/Admin/Menu.php | 19 +++++--- .../components/layouts/admin/menu.blade.php | 15 ++++--- .../livewire/menu/notifications.blade.php | 12 ++--- 5 files changed, 69 insertions(+), 24 deletions(-) diff --git a/app/Http/Livewire/Menu/Notifications.php b/app/Http/Livewire/Menu/Notifications.php index 5f740294b..6b11c30dc 100644 --- a/app/Http/Livewire/Menu/Notifications.php +++ b/app/Http/Livewire/Menu/Notifications.php @@ -27,12 +27,25 @@ class Notifications extends Component return view('livewire.menu.notifications'); } - public function markRead($notification_id) + public function markRead($type, $notification_id, $message = true) { - $notification = DatabaseNotification::find($notification_id); - $data = $notification->getAttribute('data'); + switch ($type) { + case 'updates': + $this->markUpdateRead($notification_id); + break; + case 'new-apps': + $this->markNewAppRead($notification_id); + break; + default: + $notification = DatabaseNotification::find($notification_id); + $data = $notification->getAttribute('data'); - $notification->markAsRead(); + $notification->markAsRead(); + } + + if (! $message) { + return; + } $type = isset($data['file_name']) ?: trans('general.export'); @@ -44,10 +57,10 @@ class Notifications extends Component public function markReadAll() { - $notifications = user()->unreadNotifications; + $notifications = $this->getNotifications(); foreach ($notifications as $notification) { - $notification->markAsRead(); + $this->markRead($notification->type, $notification->id, false); } $this->dispatchBrowserEvent('mark-read-all', [ @@ -56,6 +69,25 @@ class Notifications extends Component ]); } + public function markUpdateRead($notification_id) + { + // + } + + public function markNewAppRead($notification_id) + { + $notifications = $this->getNotifications(); + + foreach ($notifications as $notification) { + if ($notification->id == $notification_id) { + setting()->set('notifications.' . $notification->notifiable_id . '.' . $notification->data['alias'], '1'); + + setting()->save(); + break; + } + } + } + public function getNotifications(): array { $notifications = new \stdClass(); diff --git a/app/Listeners/Menu/ShowInNotifications.php b/app/Listeners/Menu/ShowInNotifications.php index 38686193b..49d499e47 100644 --- a/app/Listeners/Menu/ShowInNotifications.php +++ b/app/Listeners/Menu/ShowInNotifications.php @@ -65,7 +65,8 @@ class ShowInNotifications $new->notifiable_id = user()->id; $new->data = [ 'title' => $new_app->name, - 'description' => $new_app->alias, + 'description' => '', // $new_app->message, + 'alias' => $new_app->alias, ]; $new->created_at = $new_app->started_at->date; diff --git a/app/View/Components/Layouts/Admin/Menu.php b/app/View/Components/Layouts/Admin/Menu.php index fa627ac67..ff4a91b49 100644 --- a/app/View/Components/Layouts/Admin/Menu.php +++ b/app/View/Components/Layouts/Admin/Menu.php @@ -3,7 +3,7 @@ namespace App\View\Components\Layouts\Admin; use App\Abstracts\View\Component; -use App\Utilities\Versions; +use App\Events\Menu\NotificationsCreated; class Menu extends Component { @@ -21,10 +21,7 @@ class Menu extends Component { $this->companies = $this->getCompanies(); - $version_update = Versions::getUpdates(); - - $this->notification_count = user()->unreadNotifications->count(); - $this->notification_count += count($version_update); + $this->notification_count = $this->getNotificationCount(); return view('components.layouts.admin.menu'); } @@ -39,4 +36,16 @@ class Menu extends Component return $companies; } + + public function getNotificationCount() + { + // Get nofitications + $notifications = new \stdClass(); + $notifications->notifications = []; + $notifications->keyword = ''; + + event(new NotificationsCreated($notifications)); + + return $notifications->notifications->count(); + } } diff --git a/resources/views/components/layouts/admin/menu.blade.php b/resources/views/components/layouts/admin/menu.blade.php index 4b14f840e..1efa0dbc8 100644 --- a/resources/views/components/layouts/admin/menu.blade.php +++ b/resources/views/components/layouts/admin/menu.blade.php @@ -63,15 +63,16 @@ 'flex items-center menu-button justify-center w-8 h-8 mb-2.5 relative cursor-pointer js-menu-toggles', 'animate-vibrate' => $notification_count, ]) - data-menu="notifications-menu"> + data-menu="notifications-menu" + > notifications - - @if ($notification_count) - - {{ $notification_count }} - - @endif + + @if ($notification_count) + + {{ $notification_count }} + + @endif @endcan diff --git a/resources/views/livewire/menu/notifications.blade.php b/resources/views/livewire/menu/notifications.blade.php index 6f6e9c4e5..31249be66 100644 --- a/resources/views/livewire/menu/notifications.blade.php +++ b/resources/views/livewire/menu/notifications.blade.php @@ -8,8 +8,8 @@ @endif @if ($notifications) -
- +
+ @@ -30,9 +30,11 @@
@if ($notification->type != 'updates') - + + + @endif