Skip to content

Commit

Permalink
fix: changing notification "type" to "kind" in order to avoid clashin…
Browse files Browse the repository at this point in the history
…g with own laravel "type" property when using database driver
  • Loading branch information
nikuscs committed Jul 31, 2024
1 parent e6af1da commit 9840860
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion config/inertia-flash.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
'timeout' => 5000,
'namespace' => 'flashNotifications',
'read_route' => 'notification.read',
'type' => Flavorly\InertiaFlash\Notification\Enums\NotificationTypeEnum::Flash,
'kind' => Flavorly\InertiaFlash\Notification\Enums\NotificationKindEnum::Flash,
'level' => Flavorly\InertiaFlash\Notification\Enums\NotificationLevelEnum::Info,
'via' => [
//Flavorly\InertiaFlash\Notification\Enums\NotificationViaEnum::Inertia,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

namespace Flavorly\InertiaFlash\Notification\Concerns;

use Flavorly\InertiaFlash\Notification\Enums\NotificationTypeEnum;
use Flavorly\InertiaFlash\Notification\Enums\NotificationKindEnum;

trait HasNotificationDataType
trait HasNotificationDataKind
{
/**
* How the frontend should handle the notification, default is Flash
*/
public NotificationTypeEnum $type = NotificationTypeEnum::Flash;
public NotificationKindEnum $kind = NotificationKindEnum::Flash;

/**
* Sets the notification type
*/
public function type(NotificationTypeEnum $kind): static
public function kind(NotificationKindEnum $kind): static
{
$this->type = $kind;
$this->kind = $kind;

return $this;
}
Expand All @@ -26,7 +26,7 @@ public function type(NotificationTypeEnum $kind): static
*/
public function flash(): static
{
$this->type = NotificationTypeEnum::Flash;
$this->kind = NotificationKindEnum::Flash;

return $this;
}
Expand All @@ -36,7 +36,7 @@ public function flash(): static
*/
public function dialog(): static
{
$this->type = NotificationTypeEnum::Dialog;
$this->kind = NotificationKindEnum::Dialog;

return $this;
}
Expand All @@ -46,7 +46,7 @@ public function dialog(): static
*/
public function toast(): static
{
$this->type = NotificationTypeEnum::Toast;
$this->kind = NotificationKindEnum::Toast;

return $this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Flavorly\InertiaFlash\Notification\Enums;

enum NotificationTypeEnum: string
enum NotificationKindEnum: string
{
case Toast = 'toast';
case Flash = 'flash';
Expand Down
10 changes: 5 additions & 5 deletions src/Notification/FlashNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use Flavorly\InertiaFlash\Notification\Concerns\HasContentBlocks;
use Flavorly\InertiaFlash\Notification\Concerns\HasIcon;
use Flavorly\InertiaFlash\Notification\Concerns\HasNotificationActions;
use Flavorly\InertiaFlash\Notification\Concerns\HasNotificationDataKind;
use Flavorly\InertiaFlash\Notification\Concerns\HasNotificationDataLevel;
use Flavorly\InertiaFlash\Notification\Concerns\HasNotificationDataType;
use Flavorly\InertiaFlash\Notification\Concerns\HasNotificationDataViaChannel;
use Flavorly\InertiaFlash\Notification\Concerns\HasNotificationDispatcher;
use Flavorly\InertiaFlash\Notification\Concerns\HasReadableNotifications;
Expand All @@ -15,8 +15,8 @@
use Flavorly\InertiaFlash\Notification\Data\NotificationIconData;
use Flavorly\InertiaFlash\Notification\Data\NotificationReadableData;
use Flavorly\InertiaFlash\Notification\Data\NotificationTimestampsData;
use Flavorly\InertiaFlash\Notification\Enums\NotificationKindEnum;
use Flavorly\InertiaFlash\Notification\Enums\NotificationLevelEnum;
use Flavorly\InertiaFlash\Notification\Enums\NotificationTypeEnum;
use Illuminate\Notifications\DatabaseNotification;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Expand All @@ -27,8 +27,8 @@ class FlashNotification extends Data
use HasContentBlocks;
use HasIcon;
use HasNotificationActions;
use HasNotificationDataKind;
use HasNotificationDataLevel;
use HasNotificationDataType;
use HasNotificationDataViaChannel;
use HasNotificationDispatcher;
use HasReadableNotifications;
Expand Down Expand Up @@ -98,7 +98,7 @@ protected function ensureDefaults(): void
// @phpstan-ignore-next-line
$this->level(config('inertia-flash.notifications.defaults.level', NotificationLevelEnum::Info));
// @phpstan-ignore-next-line
$this->type(config('inertia-flash.notifications.defaults.type', NotificationTypeEnum::Flash));
$this->kind(config('inertia-flash.notifications.defaults.kind', NotificationKindEnum::Flash));
}

/**
Expand Down Expand Up @@ -197,7 +197,7 @@ public static function fromModel(DatabaseNotification $notification): self
$data->actions = NotificationActionData::collect($notification->data->get('actions', []), Collection::class);
$data->icon = NotificationIconData::from($notification->data->get('icon', []));
$data->level = NotificationLevelEnum::tryFrom($notification->data->get('level', NotificationLevelEnum::Info)) ?? NotificationLevelEnum::Info;
$data->type = NotificationTypeEnum::tryFrom($notification->data->get('type', NotificationTypeEnum::Flash)) ?? NotificationTypeEnum::Flash;
$data->kind = NotificationKindEnum::tryFrom($notification->data->get('kind', NotificationKindEnum::Flash)) ?? NotificationKindEnum::Flash;
$data->via = collect($notification->data->get('via', []));
$data->readable();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ public function viaQueues(): array
return config('inertia-flash.notifications.queues', []);
}

public function broadcastAs(): string
{
return 'flash-notification';
}

/**
* Get the notification's database type.
*/
Expand Down

0 comments on commit 9840860

Please sign in to comment.