61 lines
1.3 KiB
PHP
61 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire;
|
|
|
|
use App\Models\Article;
|
|
use App\Models\Setting;
|
|
use App\Jobs\ArticleDiscoveryJob;
|
|
use Livewire\Component;
|
|
use Livewire\WithPagination;
|
|
|
|
class Articles extends Component
|
|
{
|
|
use WithPagination;
|
|
|
|
public bool $isRefreshing = false;
|
|
|
|
public function approve(int $articleId): void
|
|
{
|
|
$article = Article::findOrFail($articleId);
|
|
$article->approve();
|
|
|
|
$this->dispatch('article-updated');
|
|
}
|
|
|
|
public function reject(int $articleId): void
|
|
{
|
|
$article = Article::findOrFail($articleId);
|
|
$article->reject();
|
|
|
|
$this->dispatch('article-updated');
|
|
}
|
|
|
|
public function refresh(): void
|
|
{
|
|
$this->isRefreshing = true;
|
|
|
|
ArticleDiscoveryJob::dispatch();
|
|
|
|
// Reset after 10 seconds
|
|
$this->dispatch('refresh-complete')->self();
|
|
}
|
|
|
|
public function refreshComplete(): void
|
|
{
|
|
$this->isRefreshing = false;
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
$articles = Article::with(['feed', 'articlePublication'])
|
|
->orderBy('created_at', 'desc')
|
|
->paginate(15);
|
|
|
|
$approvalsEnabled = Setting::isPublishingApprovalsEnabled();
|
|
|
|
return view('livewire.articles', [
|
|
'articles' => $articles,
|
|
'approvalsEnabled' => $approvalsEnabled,
|
|
])->layout('layouts.app');
|
|
}
|
|
}
|