Skip to content

Commit 848ff5e

Browse files
Merge pull request #13 from Gerenuk-LTD/dev
Fixes #11
2 parents d95c5a9 + 2f5ca6a commit 848ff5e

File tree

6 files changed

+46
-11
lines changed

6 files changed

+46
-11
lines changed

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ return [
5959
* The Carbon format which should be used to display the UTC timestamp.
6060
*/
6161
'format' => 'd M Hi\Z',
62+
63+
/*
64+
* Whether the component should poll every second to keep the time synced.
65+
*/
66+
'should_poll' => true,
6267
];
6368
```
6469

@@ -81,7 +86,7 @@ class AdminPanelProvider extends PanelProvider
8186
{
8287
return $panel
8388
// ...
84-
->plugin(FilamentUtcDtsPlugin::make());
89+
->plugins([FilamentUtcDtsPlugin::make()]);
8590
}
8691
}
8792
```

config/filament-utc-dts.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
<?php
22

3-
// config for Gerenuk/FilamentUtcDts
43
return [
54
/*
65
* The Carbon format which should be used to display the UTC timestamp.
76
*/
87
'format' => 'd M Hi\Z',
8+
9+
/*
10+
* Whether the component should poll every second to keep the time synced.
11+
*/
12+
'should_poll' => true,
913
];

resources/views/badge.blade.php

-2
This file was deleted.

resources/views/utc-badge.blade.php

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<span @if(config('filament-utc-dts.should_poll', true)) wire:poll.1s="updateTime" @endif
2+
class="sm:flex hidden items-center rounded-lg bg-white dark:bg-white/5 px-3 h-9 text-sm font-medium text-gray-400 dark:text-gray-500 ring-1 ring-gray-950/10 dark:ring-white/20 shadow-sm">
3+
{{ $datestamp }}
4+
</span>

src/FilamentUtcDtsPlugin.php

+5-7
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
use Filament\Contracts\Plugin;
66
use Filament\Panel;
7-
use Illuminate\Support\Carbon;
8-
use Illuminate\Support\Facades\View;
7+
use Gerenuk\FilamentUtcDts\Livewire\UtcBadge;
8+
use Livewire\Livewire;
99

1010
class FilamentUtcDtsPlugin implements Plugin
1111
{
@@ -16,12 +16,10 @@ public function getId(): string
1616

1717
public function register(Panel $panel): void
1818
{
19-
$panel->renderHook('panels::global-search.before', function () {
20-
$timestamp = Carbon::now()->utc()->format(config('filament-utc-dts.format'));
19+
Livewire::component('filament-utc-dts::utc-badge', UtcBadge::class);
2120

22-
return View::make('filament-utc-dts::badge', [
23-
'datestamp' => $timestamp,
24-
]);
21+
$panel->renderHook('panels::global-search.before', function () {
22+
return Livewire::mount('filament-utc-dts::utc-badge');
2523
});
2624
}
2725

src/Livewire/UtcBadge.php

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Gerenuk\FilamentUtcDts\Livewire;
4+
5+
use Illuminate\Support\Carbon;
6+
use Livewire\Component;
7+
8+
class UtcBadge extends Component
9+
{
10+
public string $datestamp;
11+
12+
public function mount(): void
13+
{
14+
$this->updateTime();
15+
}
16+
17+
public function updateTime(): void
18+
{
19+
$this->datestamp = Carbon::now()->utc()->format(config('filament-utc-dts.format', 'd M Hi\Z'));
20+
}
21+
22+
public function render()
23+
{
24+
return view('filament-utc-dts::utc-badge');
25+
}
26+
}

0 commit comments

Comments
 (0)