diff --git a/app/Http/Controllers/App/PostController.php b/app/Http/Controllers/App/PostController.php index 752fffae..3460169c 100644 --- a/app/Http/Controllers/App/PostController.php +++ b/app/Http/Controllers/App/PostController.php @@ -12,6 +12,7 @@ use App\Enums\Post\Status as PostStatus; use App\Enums\SocialAccount\Platform; use App\Http\Requests\App\Post\UpdatePostRequest; +use App\Http\Resources\Api\PostResource; use App\Http\Resources\App\PlatformConfigResource; use App\Http\Resources\App\SocialAccountResource; use App\Models\Post; @@ -228,7 +229,7 @@ public function show(Request $request, Post $post): Response|RedirectResponse return Inertia::render('posts/Show', [ 'workspace' => $workspace, - 'post' => $post, + 'post' => (new PostResource($post))->resolve(), ]); } diff --git a/app/Http/Resources/Api/PostPlatformResource.php b/app/Http/Resources/Api/PostPlatformResource.php index ca7712cb..147179e9 100644 --- a/app/Http/Resources/Api/PostPlatformResource.php +++ b/app/Http/Resources/Api/PostPlatformResource.php @@ -20,6 +20,14 @@ public function toArray(Request $request): array 'content_type' => $this->content_type?->value, 'status' => $this->status?->value, 'enabled' => $this->enabled, + 'platform_url' => $this->platform_url, + 'published_at' => $this->published_at?->format('Y-m-d H:i:s'), + 'error_message' => $this->error_message, + // Display fields fall back to snapshots (platform_name/username/avatar) + // so deleted accounts still render correctly in the post history. + 'display_name' => $this->display_name, + 'display_username' => $this->display_username, + 'display_avatar' => $this->display_avatar, 'social_account' => new SocialAccountResource($this->whenLoaded('socialAccount')), ]; } diff --git a/app/Models/Post.php b/app/Models/Post.php index 30aeb4ef..77328c36 100644 --- a/app/Models/Post.php +++ b/app/Models/Post.php @@ -96,7 +96,7 @@ public function scopeDraft(Builder $query): Builder public function scopePublished(Builder $query): Builder { - return $query->where('status', PostStatus::Published); + return $query->whereIn('status', [PostStatus::Published, PostStatus::PartiallyPublished]); } public function scopeFailed(Builder $query): Builder diff --git a/resources/js/pages/posts/Show.vue b/resources/js/pages/posts/Show.vue index dc0e0169..f2424f13 100644 --- a/resources/js/pages/posts/Show.vue +++ b/resources/js/pages/posts/Show.vue @@ -33,9 +33,9 @@ interface SocialAccount { interface PostPlatform { id: string; platform: string; - platform_name: string | null; - platform_username: string | null; - platform_avatar: string | null; + display_name: string; + display_username: string | null; + display_avatar: string | null; content_type: string | null; status: 'pending' | 'publishing' | 'published' | 'failed'; platform_url: string | null; @@ -52,7 +52,7 @@ interface Post { status: string; scheduled_at: string | null; published_at: string | null; - post_platforms: PostPlatform[]; + platforms: PostPlatform[]; labels?: { id: string; name: string; color: string }[]; } @@ -66,7 +66,7 @@ const props = defineProps<{ post: Post; }>(); -const enabledPlatforms = computed(() => props.post.post_platforms.filter((pp) => pp.enabled)); +const enabledPlatforms = computed(() => props.post.platforms.filter((pp) => pp.enabled)); const publishedCount = computed(() => enabledPlatforms.value.filter((pp) => pp.status === 'published').length); const failedCount = computed(() => enabledPlatforms.value.filter((pp) => pp.status === 'failed').length); @@ -79,14 +79,11 @@ const pageTitle = computed(() => { return snippet ? `${trans('posts.show.title')} · ${snippet}${props.post.content.length > 60 ? '…' : ''}` : trans('posts.show.title'); }); -const getDisplayName = (pp: PostPlatform): string => - pp.social_account?.display_name ?? pp.platform_name ?? pp.platform; +const getDisplayName = (pp: PostPlatform): string => pp.display_name ?? pp.platform; -const getDisplayUsername = (pp: PostPlatform): string | null => - pp.social_account?.username ?? pp.platform_username; +const getDisplayUsername = (pp: PostPlatform): string | null => pp.display_username; -const getDisplayAvatar = (pp: PostPlatform): string | null => - pp.social_account?.avatar_url ?? pp.platform_avatar; +const getDisplayAvatar = (pp: PostPlatform): string | null => pp.display_avatar; const formatDateTime = (date: string | null): string => date ? dayjs.utc(date).local().format('D MMM YYYY, HH:mm') : ''; diff --git a/tests/Feature/PostControllerTest.php b/tests/Feature/PostControllerTest.php index 5dad4fda..e664d2a6 100644 --- a/tests/Feature/PostControllerTest.php +++ b/tests/Feature/PostControllerTest.php @@ -653,7 +653,7 @@ $response->assertOk(); $response->assertInertia(fn ($page) => $page ->component('posts/Show', false) - ->has('post.post_platforms', 1) + ->has('post.platforms', 1) ); });