Skip to content
This repository has been archived by the owner on Oct 1, 2021. It is now read-only.

Commit

Permalink
refactor: show announcement changes in notification component (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
leMaur authored Jul 28, 2021
1 parent 16cc201 commit 5e29a69
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
8 changes: 4 additions & 4 deletions resources/views/components/manage-notifications.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ class="box-border flex items-center justify-center w-5 h-5 text-white rounded cu
</div>
<div class="leading-5 text-theme-secondary-600">
<div class="flex flex-col sm:block">
<span>{{ $notification->data['content'] }}</span>
@isset($notification->data['action'])
<a href="{{ $notification->data['action']['url'] }}" class="font-semibold link">{{ $notification->data['action']['title'] }}</a>
@endisset
<span>{{ $notification->content() }}</span>
@if($notification->hasAction())
<a href="{{ $notification->link() }}" class="font-semibold link">{{ $notification->title() }}</a>
@endif
</div>
</div>
</div>
Expand Down
8 changes: 4 additions & 4 deletions resources/views/navbar-notifications.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@

<div class="flex flex-col justify-between md:space-x-3 md:flex-row">
<span class="notification-truncate">
{{ $notification->data['content'] }}
{{ $notification->content() }}
</span>

<div class="flex flex-row space-x-4">
@isset($notification->data['action'])
@if($notification->hasAction())
<span class="mt-1 font-semibold whitespace-nowrap link md:mt-0">
<a href="{{ $notification->data['action']['url'] }}">{{ $notification->data['action']['title'] }}</a>
<a href="{{ $notification->link() }}">{{ $notification->title() }}</a>
</span>
@endisset
@endif

<span class="block mt-1 text-sm md:hidden text-theme-secondary-400">
{{ $notification->created_at_local->diffForHumans() }}
Expand Down
27 changes: 27 additions & 0 deletions src/Models/DatabaseNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use ARKEcosystem\Fortify\Models\Concerns\HasLocalizedTimestamps;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Notifications\DatabaseNotification as BaseNotification;
use Illuminate\Support\Arr;
Expand Down Expand Up @@ -62,4 +63,30 @@ public function relatableLogo(): MorphTo
abstract public function name(): string;

abstract public function logo(): string;

public function title(): ?string
{
/* @phpstan-ignore-next-line */
return data_get($this->relatable, 'title')
?? data_get($this->data, 'action.title');
}

public function content(): ?string
{
/* @phpstan-ignore-next-line */
return data_get($this->relatable, 'body')
?? data_get($this->data, 'content');
}

public function link(): ?string
{
/* @phpstan-ignore-next-line */
return data_get($this->relatable, 'link')
?? data_get($this->data, 'action.url');
}

public function hasAction(): bool
{
return (bool) data_get($this->data, 'action');
}
}

0 comments on commit 5e29a69

Please sign in to comment.