2024-10-05 14:09:22 -04:00
|
|
|
<?php
|
|
|
|
|
2025-01-30 00:23:55 -05:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2024-10-05 14:09:22 -04:00
|
|
|
namespace App\Livewire\User;
|
|
|
|
|
|
|
|
use App\Models\User;
|
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
use Illuminate\View\View;
|
|
|
|
use Livewire\Attributes\Locked;
|
|
|
|
use Livewire\Attributes\On;
|
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class FollowCards extends Component
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The user account that is being viewed.
|
|
|
|
*/
|
|
|
|
#[Locked]
|
|
|
|
public User $profileUser;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A collection of user IDs that the auth user follows.
|
2025-01-30 20:49:56 -05:00
|
|
|
*
|
|
|
|
* @var Collection<int, int>
|
2024-10-05 14:09:22 -04:00
|
|
|
*/
|
|
|
|
#[Locked]
|
|
|
|
public Collection $authFollowIds;
|
|
|
|
|
2024-10-09 14:15:01 -06:00
|
|
|
/**
|
|
|
|
* Render the component.
|
|
|
|
*/
|
|
|
|
public function render(): View
|
|
|
|
{
|
|
|
|
$this->updateAuthFollowIds();
|
|
|
|
|
|
|
|
return view('livewire.user.follow-cards');
|
|
|
|
}
|
|
|
|
|
2024-10-05 14:09:22 -04:00
|
|
|
/**
|
|
|
|
* Called when the user follows or unfollows a user.
|
|
|
|
*/
|
|
|
|
#[On('user-follow-change')]
|
|
|
|
public function updateAuthFollowIds(): void
|
|
|
|
{
|
|
|
|
// Fetch IDs of all users the authenticated user is following.
|
|
|
|
$this->authFollowIds = collect();
|
|
|
|
$authUser = auth()->user();
|
|
|
|
if ($authUser) {
|
|
|
|
$this->authFollowIds = $authUser->following()->pluck('following_id');
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->dispatch('auth-follow-change');
|
|
|
|
}
|
|
|
|
}
|