Skip to content

Commit a72df78

Browse files
committed
wip
1 parent 650579d commit a72df78

File tree

4 files changed

+45
-45
lines changed

4 files changed

+45
-45
lines changed

Diff for: app/Livewire/NewsFeed.php

+4-8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Filament\Forms\Form;
1515
use Illuminate\Contracts\Database\Eloquent\Builder;
1616
use Illuminate\Pagination\LengthAwarePaginator;
17+
use Livewire\Attributes\Computed;
1718
use Livewire\Component;
1819
use Livewire\WithPagination;
1920

@@ -69,20 +70,15 @@ public function form(Form $form): Form
6970
->statePath('filters');
7071
}
7172

72-
public function render()
73-
{
74-
return view('livewire.news-feed', [
75-
'posts' => $this->getPosts(),
76-
]);
77-
}
78-
7973
public function reload(): void
8074
{
8175
$this->reset('filters');
8276
$this->resetPage();
77+
$this->dispatch('$refresh');
8378
}
8479

85-
protected function getPosts(): LengthAwarePaginator
80+
#[Computed]
81+
protected function posts(): LengthAwarePaginator
8682
{
8783
return Post::query()
8884
->with('author.media', 'electionDay', 'media')

Diff for: app/Livewire/NewsFeedUpdater.php

+4-16
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,14 @@
88

99
class NewsFeedUpdater extends Component
1010
{
11-
public bool $banner = false;
11+
public bool $visible = false;
1212

1313
protected $listeners = [
14-
'echo:newsfeed,AnnouncePost' => 'showBanner',
15-
'reload' => '$refresh',
14+
'echo:newsfeed,UpdateNewsFeed' => 'open',
1615
];
1716

18-
public function showBanner(): void
17+
public function open(): void
1918
{
20-
$this->banner = true;
21-
}
22-
23-
public function render()
24-
{
25-
return view('livewire.news-feed-updater');
26-
}
27-
28-
public function reload(): void
29-
{
30-
$this->dispatch('reload');
31-
$this->banner = false;
19+
$this->visible = true;
3220
}
3321
}

Diff for: resources/views/livewire/news-feed-updater.blade.php

+25-17
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,32 @@
1-
<div class="">
2-
@if ($banner)
3-
<div class="p-4 border-l-4 border-secondary-600 bg-secondary-100">
4-
<div class="flex gap-3">
5-
<x-ri-information-fill class="w-5 h-5 text-secondary-500 shrink-0" />
1+
<div class="sticky top-0 z-10">
2+
<div x-show="visible"
3+
x-cloak
4+
x-data="{
5+
visible: $wire.entangle('visible'),
6+
close() {
7+
this.visible = false;
8+
$wire.$parent.reload();
9+
}
10+
}"
11+
class="p-4 border-l-4 shadow border-secondary-600 bg-secondary-100">
12+
<div class="flex gap-3">
13+
<x-ri-information-fill class="w-5 h-5 text-secondary-500 shrink-0" />
614

7-
<div class="flex flex-wrap flex-1 gap-3 md:justify-between">
8-
<p class="text-sm text-secondary-700">
9-
{{ __('app.newsfeed.updated') }}
10-
</p>
15+
<div class="flex flex-wrap flex-1 gap-3 md:justify-between">
16+
<p class="text-sm text-secondary-700">
17+
{{ __('app.newsfeed.updated') }}
18+
</p>
1119

12-
<button wire:click="reload"
13-
class="text-xs font-medium text-secondary-700 whitespace-nowrap hover:text-secondary-600 flex gap-1.5 items-center group">
14-
<span>{{ __('app.newsfeed.refresh') }}</span>
20+
<button x-on:click.prevent="close"
21+
2x-on:click.prevent="$dispatch('refresh-feed')"
22+
class="text-xs font-medium text-secondary-700 whitespace-nowrap hover:text-secondary-600 flex gap-1.5 items-center group">
23+
<span>{{ __('app.newsfeed.refresh') }}</span>
1524

16-
<x-ri-refresh-line
17-
class="w-4 h-4 transition-transform group-hover:rotate-45 group-focus:rotate-45" />
18-
</button>
25+
<x-ri-refresh-line
26+
class="w-4 h-4 transition-transform group-hover:rotate-45 group-focus:rotate-45" />
27+
</button>
1928

20-
</div>
2129
</div>
2230
</div>
23-
@endif
31+
</div>
2432
</div>

Diff for: resources/views/livewire/news-feed.blade.php

+12-4
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,27 @@ class="prose md:prose-lg lg:prose-xl max-w-none prose-headings:font-semibold pro
1515
{{ $this->form }}
1616
</form>
1717

18-
<div class="grid gap-4 mt-10 sm:gap-8">
18+
<div x-on:refresh-feed="$wire.reload()" class="relative grid gap-4 mt-10 sm:gap-8">
1919
<livewire:news-feed-updater />
2020

21-
{{ $posts->links(data: ['scrollTo' => false]) }}
21+
{{ $this->posts->links(data: ['scrollTo' => false]) }}
2222

23-
@forelse ($posts as $post)
23+
@forelse ($this->posts as $post)
2424
<x-news-feed-item :post="$post" />
2525
@empty
2626
<p>{{ __('app.newsfeed.empty') }}</p>
2727
@endforelse
2828

29-
{{ $posts->links(data: ['scrollTo' => '#newsfeed']) }}
29+
{{ $this->posts->links(data: ['scrollTo' => '#newsfeed']) }}
3030
</div>
3131
</div>
3232

33+
@script
34+
<script>
35+
$wire.on('$refresh', () => {
36+
document.querySelector('#newsfeed').scrollIntoView()
37+
});
38+
</script>
39+
@endscript
40+
3341
</section>

0 commit comments

Comments
 (0)