*/ #[Locked] public array $newIds = []; /** * @return list */ #[Computed] public function notifications(): array { return app(NotificationQueries::class)->recentFor((int) auth()->id(), $this->since()); } #[Computed] public function unseenCount(): int { return app(NotificationQueries::class)->unseenCount((int) auth()->id(), $this->since()); } public function open(MarkNotificationsSeen $markSeen): void { $unseen = array_values(array_map( fn (NotificationSummary $notification): int => $notification->id, array_filter($this->notifications, fn (NotificationSummary $notification): bool => ! $notification->seen), )); if ($unseen === []) { return; } $this->newIds = array_values(array_unique([...$this->newIds, ...$unseen])); $markSeen->execute((int) auth()->id()); unset($this->notifications, $this->unseenCount); } public function text(NotificationSummary $notification): string { return match ($notification->type) { NotificationType::TaskStartsSoon => __('notifications.types.task_starts_soon', [ 'task' => (string) $notification->params['task_title'], 'number' => (string) $notification->params['job_number'], 'job' => (string) $notification->params['job_name'], 'date' => $this->formatDay((string) $notification->params['starts_on']), ]), NotificationType::TaskAssigned => __('notifications.types.task_assigned.'.$notification->params['role'], [ 'task' => (string) $notification->params['task_title'], 'number' => (string) $notification->params['job_number'], 'job' => (string) $notification->params['job_name'], ]), NotificationType::JobAssigned => __('notifications.types.job_assigned', [ 'number' => (string) $notification->params['job_number'], 'job' => (string) $notification->params['job_name'], 'roles' => $this->roleList((string) $notification->params['roles']), ]), NotificationType::MaintenanceDue => __('notifications.types.maintenance_due.'.$notification->params['level'], [ 'machine' => (string) $notification->params['machine'], 'item' => (string) $notification->params['item'], ]), }; } public function url(NotificationSummary $notification): string { return match ($notification->type) { NotificationType::TaskStartsSoon, NotificationType::TaskAssigned => route('jobs.show', (int) $notification->params['job_id']).'#task-'.$notification->params['task_id'], NotificationType::JobAssigned => route('jobs.show', (int) $notification->params['job_id']), NotificationType::MaintenanceDue => route('machines.show', (int) $notification->params['machine_id']).'#maintenance-heading', }; } /** * "vastuuhenkilöksi ja jäseneksi" from "responsible,member". */ private function roleList(string $roles): string { $names = array_map(fn (string $role): string => __('notifications.job_roles.'.$role), array_filter(explode(',', $roles))); $last = array_pop($names); return $names === [] ? (string) $last : implode(', ', $names).' '.__('notifications.and').' '.$last; } /** * "25.11.2026 klo 14.05" from "2026-11-25 14:05". */ public function formatTime(string $moment): string { $time = CarbonImmutable::createFromFormat('Y-m-d H:i', $moment); return __('notifications.at', ['date' => $time->format('j.n.Y'), 'time' => $time->format('H.i')]); } /** * "ma 30.11.2026" from "2026-11-30". */ private function formatDay(string $date): string { $day = CarbonImmutable::createFromFormat('Y-m-d', $date); return __('holidays.weekdays.'.$day->dayOfWeekIso).' '.$day->format('j.n.Y'); } private function since(): DateTimeImmutable { return CarbonImmutable::now()->subDays(NotifyTasksStartingSoon::KEEP_DAYS)->toDateTimeImmutable(); } }; ?> {{-- A disclosure like the profile menu (not role="menu"): the bell's name stays "Ilmoitukset", and the number of unseen notifications is visible text that the button refers to with aria-describedby. Opening the panel marks them seen. Escape, a click outside and moving focus out close it. --}}
@php($count = $this->unseenCount) {{ trans_choice('notifications.unseen', $count, ['count' => $count]) }}
{{-- Not a heading: the header comes before the page's h1. --}}

{{ __('notifications.recent') }}

@if ($this->notifications === [])

{{ __('notifications.empty') }}

@else @endif