This commit is contained in:
Aleksander Lis 2026-03-11 13:12:57 +05:30 committed by GitHub
commit 84869ad383
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 60 additions and 1 deletions

View file

@ -11,6 +11,12 @@ class SettingsDropdown extends Component
{
public $showWhatsNewModal = false;
public bool $shouldPollChangelog = false;
public bool $changelogFetchRequested = false;
public int $changelogPollAttempts = 0;
public function getUnreadCountProperty()
{
return Auth::user()->getUnreadChangelogCount();
@ -31,6 +37,53 @@ class SettingsDropdown extends Component
public function openWhatsNewModal()
{
$this->showWhatsNewModal = true;
$this->prefetchChangelog();
}
public function prefetchChangelog()
{
$entries = app(ChangelogService::class)->getEntriesForUser(Auth::user());
if ($entries->isEmpty()) {
if (! $this->changelogFetchRequested) {
$this->changelogFetchRequested = true;
$this->shouldPollChangelog = true;
$this->changelogPollAttempts = 0;
PullChangelog::dispatch();
}
return;
}
$this->dispatch('changelog-entries', entries: $entries->values()->all());
}
public function refreshChangelog()
{
if (! $this->shouldPollChangelog) {
return;
}
$this->changelogPollAttempts++;
if ($this->changelogPollAttempts > 10) {
$this->shouldPollChangelog = false;
$this->changelogFetchRequested = false;
return;
}
$entries = app(ChangelogService::class)->getEntriesForUser(Auth::user());
if ($entries->isEmpty()) {
return;
}
$this->shouldPollChangelog = false;
$this->changelogFetchRequested = false;
$this->changelogPollAttempts = 0;
$this->dispatch('changelog-entries', entries: $entries->values()->all());
cache()->forget('user_unread_changelog_count_'.Auth::id());
$this->dispatch('$refresh');
}
public function closeWhatsNewModal()

View file

@ -8,6 +8,9 @@
this.mounted();
// Load all entries when component initializes
this.allEntries = @js($entries->toArray());
window.addEventListener('changelog-entries', (event) => {
this.allEntries = event.detail.entries ?? [];
});
},
markEntryAsRead(tagName) {
// Update the entry in our local Alpine data
@ -103,7 +106,10 @@
return new Date(b.published_at) - new Date(a.published_at);
});
}
}" @click.outside="dropdownOpen = false">
}" @click.outside="dropdownOpen = false" wire:init="prefetchChangelog">
@if ($shouldPollChangelog)
<span class="hidden" wire:poll.1s="refreshChangelog"></span>
@endif
<!-- Custom Dropdown without arrow -->
<div class="relative">
<button @click="dropdownOpen = !dropdownOpen"