Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
allanmcarvalho committed May 22, 2023
1 parent 63c7686 commit f4a9f65
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/Facades/Flash.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @method static \Laravue\Flash\FlashMessage assertHasFlashType(FlashTypes $flashTypes)
* @method static \Laravue\Flash\FlashMessage assertMessageContain(string $message)
* @method static \Laravue\Flash\FlashMessage assertMessageEqual(string $message)
* @method static \Laravue\Flash\Flash withTitle(string $title)
* @method static \Laravue\Flash\FlashMessage default(string $message, string|false $faIcon = false)
* @method static \Laravue\Flash\FlashMessage success(string $message, string $faIcon = 'circle-check')
* @method static \Laravue\Flash\FlashMessage info(string $message, string $faIcon = 'circle-info')
Expand Down
28 changes: 23 additions & 5 deletions src/Flash/Flash.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,41 @@ class Flash

protected SessionManager|Store $session;

protected string|false $title;

public function __construct(SessionManager|Store $session)
{
$this->session = $session;
if ($this->session->get(self::SESSION_KEY) === null) {
$this->session->put(self::SESSION_KEY, []);
}
$this->title = false;
Inertia::share('flash_messages', function () {
return \Laravue\Facades\Flash::toArray();
});
}

public function withTitle(string $title): static
{
$this->title = $title;

return $this;
}

protected function consumeTitle(): string|false
{
$title = $this->title;
$this->title = false;

return $title;
}

/**
* @return \Laravue\Flash\FlashMessage
*/
public function default(string $message, ?string $faIcon = null): FlashMessage
{
$message = new FlashMessage($message, FlashTypes::DEFAULT, $faIcon);
$message = new FlashMessage($message, FlashTypes::DEFAULT, $faIcon, $this->consumeTitle());
$this->session->push(self::SESSION_KEY, $message);

return $message;
Expand All @@ -48,7 +66,7 @@ public function default(string $message, ?string $faIcon = null): FlashMessage
*/
public function success(string $message, string $faIcon = 'circle-check'): FlashMessage
{
$message = new FlashMessage($message, FlashTypes::SUCCESS, $faIcon);
$message = new FlashMessage($message, FlashTypes::SUCCESS, $faIcon, $this->consumeTitle());
$this->session->push(self::SESSION_KEY, $message);

return $message;
Expand All @@ -59,7 +77,7 @@ public function success(string $message, string $faIcon = 'circle-check'): Flash
*/
public function info(string $message, string $faIcon = 'circle-info'): FlashMessage
{
$message = new FlashMessage($message, FlashTypes::INFO, $faIcon);
$message = new FlashMessage($message, FlashTypes::INFO, $faIcon, $this->consumeTitle());
$this->session->push(self::SESSION_KEY, $message);

return $message;
Expand All @@ -70,7 +88,7 @@ public function info(string $message, string $faIcon = 'circle-info'): FlashMess
*/
public function warning(string $message, string $faIcon = 'triangle-exclamation'): FlashMessage
{
$message = new FlashMessage($message, FlashTypes::WARNING, $faIcon);
$message = new FlashMessage($message, FlashTypes::WARNING, $faIcon, $this->consumeTitle());
$this->session->push(self::SESSION_KEY, $message);

return $message;
Expand All @@ -81,7 +99,7 @@ public function warning(string $message, string $faIcon = 'triangle-exclamation'
*/
public function error(string $message, string $faIcon = 'diamond-exclamation'): FlashMessage
{
$message = new FlashMessage($message, FlashTypes::ERROR, $faIcon);
$message = new FlashMessage($message, FlashTypes::ERROR, $faIcon, $this->consumeTitle());
$this->session->push(self::SESSION_KEY, $message);

return $message;
Expand Down
4 changes: 3 additions & 1 deletion src/Flash/FlashMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,22 @@ class FlashMessage

protected bool $rtl = false;

protected string|false $title = false;
protected string|false $title;

protected string $message;

public function __construct(
string $message,
FlashTypes $type,
?string $faIcon,
string|false $title = false
) {
$this->message = $message;
$this->type = $type;
if (! empty($faIcon)) {
$this->setFaIcon($faIcon);
}
$this->title = $title;
}

/**
Expand Down

0 comments on commit f4a9f65

Please sign in to comment.