Skip to content

Commit 8a68bf1

Browse files
committed
feat: polling work sessions running and show on top navigation
1 parent 6c9fd29 commit 8a68bf1

File tree

4 files changed

+43
-7
lines changed

4 files changed

+43
-7
lines changed

app/Filament/App/Resources/WorkSessionResource.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,6 @@ public static function getNavigationGroup(): ?string
5858
return __(MenuGroupsEnum::DAILY_WORK->value);
5959
}
6060

61-
public static function getNavigationBadge(): ?string
62-
{
63-
$count = WorkSession::where('is_running', true)->count();
64-
65-
return $count > 0 ? (string)$count : null;
66-
}
67-
6861
public static function form(Form $form): Form
6962
{
7063
return $form

app/Livewire/WorkSessionsTopNav.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace App\Livewire;
4+
5+
use App\Models\WorkSession;
6+
use Livewire\Component;
7+
8+
class WorkSessionsTopNav extends Component
9+
{
10+
public function render()
11+
{
12+
return view('livewire.work-sessions-top-nav', [
13+
'count' =>WorkSession::where('is_running', true)
14+
->count(),
15+
]);
16+
}
17+
}

app/Providers/Filament/AppPanelProvider.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Illuminate\Routing\Middleware\SubstituteBindings;
2323
use Illuminate\Session\Middleware\AuthenticateSession;
2424
use Illuminate\Session\Middleware\StartSession;
25+
use Illuminate\Support\Facades\Blade;
2526
use Illuminate\View\Middleware\ShareErrorsFromSession;
2627

2728
class AppPanelProvider extends PanelProvider
@@ -64,6 +65,10 @@ public function panel(Panel $panel): Panel
6465
6566
</div>'
6667
)
68+
->renderHook(
69+
PanelsRenderHook::GLOBAL_SEARCH_BEFORE,
70+
fn() => Blade::render('@livewire(\'work-sessions-top-nav\')')
71+
)
6772
->maxContentWidth(MaxWidth::Full)
6873
->sidebarCollapsibleOnDesktop()
6974
->discoverResources(in: app_path('Filament/App/Resources'), for: 'App\\Filament\\App\\Resources')
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<div wire:poll.60s
2+
x-tooltip="{
3+
content: '@lang('Work sessions') - @lang('Running')',
4+
theme: $store.theme,
5+
}"
6+
>
7+
<a href="{{ \App\Filament\App\Resources\WorkSessionResource::getUrl() }}">
8+
<span style="--c-50:var(--primary-50);--c-400:var(--primary-400);--c-600:var(--primary-600);"
9+
class="fi-badge flex items-center justify-center gap-x-1 rounded-md text-xs font-medium ring-1 ring-inset px-2 min-w-[theme(spacing.6)] py-1 fi-color-custom bg-custom-50 text-custom-600 ring-custom-600/10 dark:bg-custom-400/10 dark:text-custom-400 dark:ring-custom-400/30 fi-color-primary">
10+
<x-filament::icon
11+
icon={{\App\Filament\App\Resources\WorkSessionResource::getNavigationIcon()}}
12+
class="h-5 w-5 text-gray-500 dark:text-gray-400"
13+
/>
14+
<span class="grid">
15+
<span class="truncate">
16+
{{ $count }}
17+
</span>
18+
</span>
19+
</span>
20+
</a>
21+
</div>

0 commit comments

Comments
 (0)