-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add recent boards real time functionality on client side. Showing most recent boards connections with their IP in case they are active and last seen field in case they are offline. * Every request updated last seen an IP field for the board * Every session listened from client side updates the same fields each time board sends information
- Loading branch information
1 parent
74862de
commit d2bf972
Showing
7 changed files
with
115 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace App\Http\Livewire; | ||
|
||
use App\Models\Board; | ||
use Illuminate\Support\Collection; | ||
use Illuminate\View\View; | ||
use Livewire\Component; | ||
|
||
/** @property-read Collection<array> $recentBoards*/ | ||
class RecentBoards extends Component | ||
{ | ||
public Collection $recentBoards; | ||
|
||
public function updateRecentBoards(): void | ||
{ | ||
$boards = Board::orderBy('last_seen', 'desc')->limit(4)->get(); | ||
$this->recentBoards = $boards->map(function ($b) { | ||
$active = true; | ||
$last_seen = $b->last_seen ?? false; | ||
if ($last_seen and now()->diffInSeconds($last_seen) > 15) { | ||
$active = false; | ||
} | ||
|
||
return [ | ||
'active' => $active, | ||
'name' => $b->name, | ||
'uuid' => $b->uuid, | ||
'ip' => $b->ip, | ||
'last_seen' => $b->last_seen, | ||
]; | ||
}); | ||
} | ||
|
||
public function mount(): void | ||
{ | ||
$this->recentBoards = collect(); | ||
} | ||
|
||
public function render(): view | ||
{ | ||
$this->updateRecentBoards(); | ||
|
||
return view('livewire.recent-boards', [ | ||
'recentBoards' => $this->recentBoards, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<div class="grid sm:grid-cols-2 gap-6 sm:rounded-lg"> | ||
<div wire:poll="updateRecentBoards" class="hidden"></div> | ||
@forelse($recentBoards as $b) | ||
<div class=" | ||
min-h-[100px] bg-center bg-cover bg-no-repeat rounded-lg p-2 | ||
shadow-[0_0_5px_1px_rgba(255,255,255,0.3)] dark:text-white boardBox | ||
transition-all duration-150 transform hover:scale-105 cursor-pointer | ||
bg-white dark:bg-gray-800 | ||
" | ||
> | ||
<header class="grid grid-cols-6 items-center"> | ||
<p class="col-span-4 text-xl">{{$b['name']}}</p> | ||
<div class="col-span-2 flex justify-end align-middle text-white"> | ||
@if($b['active']) | ||
<span class="text-sm h-fit py-[2px] px-[7px] rounded-lg bg-green-600">Active</span> | ||
@else | ||
<span class="text-sm h-fit py-[2px] px-[7px] rounded-lg bg-red-500">Inactive</span> | ||
@endif | ||
</div> | ||
</header> | ||
<hr class="mt-2"> | ||
<p class="mt-3 text-sm">{{$b['uuid']}}</p> | ||
@if($b['active']) | ||
<p class="mb-2 text-sm">IP: {{$b['ip']}}</p> | ||
@else | ||
<p class="mb-2 text-sm">Last seen: {{$b['last_seen']}}</p> | ||
@endif | ||
</div> | ||
@empty | ||
<div class=" | ||
flex justify-center min-h-[100px] rounded-lg p-2 col-span-2 | ||
shadow-[0_0_5px_1px_rgba(255,255,255,0.3)] dark:text-white | ||
transition-all duration-150 transform hover:scale-105 cursor-pointer | ||
bg-white dark:bg-gray-800 | ||
" | ||
> | ||
<p class="col-span-4 text-xl my-auto">No boards added yet. Go to Boards menu to register</p> | ||
</div> | ||
@endforelse | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters