Show published status for articles

This commit is contained in:
myrmidex 2025-08-12 01:31:37 +02:00
parent c77667d263
commit 65fefb9534
3 changed files with 20 additions and 9 deletions

View file

@ -5,13 +5,11 @@
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource; use Illuminate\Http\Resources\Json\JsonResource;
/**
* @property int $id
*/
class ArticleResource extends JsonResource class ArticleResource extends JsonResource
{ {
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array public function toArray(Request $request): array
{ {
return [ return [
@ -27,10 +25,11 @@ public function toArray(Request $request): array
'approved_by' => $this->approved_by, 'approved_by' => $this->approved_by,
'fetched_at' => $this->fetched_at?->toISOString(), 'fetched_at' => $this->fetched_at?->toISOString(),
'validated_at' => $this->validated_at?->toISOString(), 'validated_at' => $this->validated_at?->toISOString(),
'is_published' => $this->relationLoaded('articlePublication') && $this->articlePublication !== null,
'created_at' => $this->created_at->toISOString(), 'created_at' => $this->created_at->toISOString(),
'updated_at' => $this->updated_at->toISOString(), 'updated_at' => $this->updated_at->toISOString(),
'feed' => new FeedResource($this->whenLoaded('feed')), 'feed' => new FeedResource($this->whenLoaded('feed')),
'article_publication' => new ArticlePublicationResource($this->whenLoaded('articlePublication')), 'article_publication' => new ArticlePublicationResource($this->whenLoaded('articlePublication')),
]; ];
} }
} }

View file

@ -41,6 +41,7 @@ export interface Article {
published_at: string | null; published_at: string | null;
author: string | null; author: string | null;
approval_status: 'pending' | 'approved' | 'rejected'; approval_status: 'pending' | 'approved' | 'rejected';
is_published: boolean;
created_at: string; created_at: string;
updated_at: string; updated_at: string;
feed?: Feed; feed?: Feed;

View file

@ -57,8 +57,19 @@ const Articles: React.FC = () => {
refreshMutation.mutate(); refreshMutation.mutate();
}; };
const getStatusBadge = (status: string) => { const getStatusBadge = (article: Article) => {
switch (status) { // Show "Published" status if the article has been published
if (article.is_published) {
return (
<span className="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-blue-100 text-blue-800">
<ExternalLink className="h-3 w-3 mr-1" />
Published
</span>
);
}
// Otherwise show the approval status
switch (article.approval_status) {
case 'approved': case 'approved':
return ( return (
<span className="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-green-100 text-green-800"> <span className="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-green-100 text-green-800">
@ -162,7 +173,7 @@ const Articles: React.FC = () => {
</div> </div>
</div> </div>
<div className="flex items-center space-x-3 ml-4"> <div className="flex items-center space-x-3 ml-4">
{getStatusBadge(article.approval_status)} {getStatusBadge(article)}
{article.url && ( {article.url && (
<a <a
href={article.url} href={article.url}