From c0886737c4eda23772e84c9d4a3ec6b13c6eb725 Mon Sep 17 00:00:00 2001 From: Paulo Castellano Date: Mon, 26 Jan 2026 15:18:35 -0300 Subject: [PATCH] feat: add labels and hashtags to posts - Add many-to-many relationship between posts and workspace labels - Add label selector in post edit page with autosave - Display labels in posts list - Add hashtags modal with search for appending hashtags to post content - Fix sidebar active state for posts edit page - Fix AvatarImage null src warning in SocialAccountsGrid - Fix new post state by using Inertia::location for full page reload - Hide close button on CommandDialog by default --- app/Http/Controllers/PostController.php | 17 +- app/Http/Requests/UpdatePostRequest.php | 2 + app/Models/Post.php | 6 + app/Models/WorkspaceLabel.php | 6 + ...3538_create_post_workspace_label_table.php | 28 +++ lang/en/posts.php | 6 + lang/pt-br/posts.php | 6 + resources/js/components/AppSidebar.vue | 4 + .../js/components/SocialAccountsGrid.vue | 2 +- .../js/components/posts/HashtagsModal.vue | 67 +++++++ .../components/ui/command/CommandDialog.vue | 4 +- resources/js/composables/useActiveUrl.ts | 11 +- resources/js/pages/posts/Edit.vue | 86 ++++++++- resources/js/pages/posts/Index.vue | 29 ++- tests/Feature/PostControllerTest.php | 167 ++++++++++++++++++ 15 files changed, 423 insertions(+), 18 deletions(-) create mode 100644 database/migrations/2026_01_26_173538_create_post_workspace_label_table.php create mode 100644 resources/js/components/posts/HashtagsModal.vue diff --git a/app/Http/Controllers/PostController.php b/app/Http/Controllers/PostController.php index fe3ea727..7cb80ccf 100644 --- a/app/Http/Controllers/PostController.php +++ b/app/Http/Controllers/PostController.php @@ -30,7 +30,7 @@ public function index(Request $request, ?string $status = null): Response|Redire $query = $workspace->posts() ->with(['postPlatforms' => function ($query) { $query->where('enabled', true)->with('socialAccount'); - }, 'user']); + }, 'user', 'labels']); // Apply status filter if provided if ($status) { @@ -97,7 +97,7 @@ public function calendar(Request $request): Response|RedirectResponse ]); } - public function store(Request $request): RedirectResponse + public function store(Request $request): RedirectResponse|\Symfony\Component\HttpFoundation\Response { $workspace = $request->user()->currentWorkspace; @@ -141,7 +141,7 @@ public function store(Request $request): RedirectResponse ]); } - return redirect()->route('posts.edit', $post); + return Inertia::location(route('posts.edit', $post)); } public function edit(Request $request, Post $post): Response|RedirectResponse @@ -158,8 +158,10 @@ public function edit(Request $request, Post $post): Response|RedirectResponse abort(404); } - $post->load(['postPlatforms.socialAccount', 'postPlatforms.media']); + $post->load(['postPlatforms.socialAccount', 'postPlatforms.media', 'labels']); $socialAccounts = $workspace->socialAccounts; + $labels = $workspace->labels; + $hashtags = $workspace->hashtags; $platformConfigs = $socialAccounts->mapWithKeys(function ($account) { $platform = $account->platform; @@ -191,6 +193,8 @@ public function edit(Request $request, Post $post): Response|RedirectResponse 'socialAccounts' => $socialAccounts, 'platformConfigs' => $platformConfigs, 'pinterestBoards' => $pinterestBoards, + 'labels' => $labels, + 'hashtags' => $hashtags, ]); } @@ -228,6 +232,11 @@ public function update(UpdatePostRequest $request, Post $post): RedirectResponse 'scheduled_at' => $scheduledAt, ]); + // Sync labels + if ($request->has('label_ids')) { + $post->labels()->sync($request->input('label_ids', [])); + } + // Get selected platform IDs $selectedPlatformIds = collect($request->input('platforms', []))->pluck('id')->toArray(); diff --git a/app/Http/Requests/UpdatePostRequest.php b/app/Http/Requests/UpdatePostRequest.php index 65618e92..af0278f3 100644 --- a/app/Http/Requests/UpdatePostRequest.php +++ b/app/Http/Requests/UpdatePostRequest.php @@ -19,6 +19,8 @@ public function rules(): array 'platforms' => ['sometimes', 'array'], 'platforms.*.id' => ['required', 'uuid', 'exists:post_platforms,id'], 'platforms.*.content' => ['nullable', 'string', 'max:5000'], + 'label_ids' => ['sometimes', 'array'], + 'label_ids.*' => ['uuid', 'exists:workspace_labels,id'], ]; } diff --git a/app/Models/Post.php b/app/Models/Post.php index d7a9fac8..bcf89158 100644 --- a/app/Models/Post.php +++ b/app/Models/Post.php @@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasMany; class Post extends Model @@ -49,6 +50,11 @@ public function postPlatforms(): HasMany return $this->hasMany(PostPlatform::class); } + public function labels(): BelongsToMany + { + return $this->belongsToMany(WorkspaceLabel::class); + } + public function scopeScheduled(Builder $query): Builder { return $query->where('status', PostStatus::Scheduled); diff --git a/app/Models/WorkspaceLabel.php b/app/Models/WorkspaceLabel.php index 20f1323a..1a74ea88 100644 --- a/app/Models/WorkspaceLabel.php +++ b/app/Models/WorkspaceLabel.php @@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\SoftDeletes; class WorkspaceLabel extends Model @@ -23,4 +24,9 @@ public function workspace(): BelongsTo { return $this->belongsTo(Workspace::class); } + + public function posts(): BelongsToMany + { + return $this->belongsToMany(Post::class); + } } diff --git a/database/migrations/2026_01_26_173538_create_post_workspace_label_table.php b/database/migrations/2026_01_26_173538_create_post_workspace_label_table.php new file mode 100644 index 00000000..23c43293 --- /dev/null +++ b/database/migrations/2026_01_26_173538_create_post_workspace_label_table.php @@ -0,0 +1,28 @@ +foreignUuid('post_id')->constrained()->cascadeOnDelete(); + $table->foreignUuid('workspace_label_id')->constrained()->cascadeOnDelete(); + $table->primary(['post_id', 'workspace_label_id']); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('post_workspace_label'); + } +}; diff --git a/lang/en/posts.php b/lang/en/posts.php index 6eafe3cd..98c5880a 100644 --- a/lang/en/posts.php +++ b/lang/en/posts.php @@ -56,6 +56,7 @@ 'view_title' => 'View Post', 'manage_platforms' => 'Manage platforms', 'sync' => 'Sync', + 'labels' => 'Labels', 'schedule' => 'Schedule', 'publish' => 'Publish', 'saving' => 'Saving...', @@ -99,6 +100,11 @@ 'description' => 'Choose which platforms to publish this post to.', ], + 'hashtags_modal' => [ + 'search' => 'Search hashtags...', + 'no_results' => 'No hashtags found.', + ], + 'validation' => [ 'select_board' => 'Select a board', 'images_not_supported' => 'Images not supported', diff --git a/lang/pt-br/posts.php b/lang/pt-br/posts.php index a35988e5..d2f4214f 100644 --- a/lang/pt-br/posts.php +++ b/lang/pt-br/posts.php @@ -56,6 +56,7 @@ 'view_title' => 'Visualizar Post', 'manage_platforms' => 'Gerenciar plataformas', 'sync' => 'Sincronizar', + 'labels' => 'Etiquetas', 'schedule' => 'Agendar', 'publish' => 'Publicar', 'saving' => 'Salvando...', @@ -99,6 +100,11 @@ 'description' => 'Escolha em quais plataformas publicar este post.', ], + 'hashtags_modal' => [ + 'search' => 'Buscar hashtags...', + 'no_results' => 'Nenhuma hashtag encontrada.', + ], + 'validation' => [ 'select_board' => 'Selecione uma pasta', 'images_not_supported' => 'Imagens não suportadas', diff --git a/resources/js/components/AppSidebar.vue b/resources/js/components/AppSidebar.vue index 8e831a66..1ca17e10 100644 --- a/resources/js/components/AppSidebar.vue +++ b/resources/js/components/AppSidebar.vue @@ -194,6 +194,10 @@ function createWorkspace() { } function isActive(href: string): boolean { + // For /posts, also match /posts/{id}/edit + if (href === '/posts') { + return page.url === '/posts' || page.url.startsWith('/posts/') && page.url.includes('/edit'); + } // Exact match or match with query string return page.url === href || page.url.startsWith(href + '?'); } diff --git a/resources/js/components/SocialAccountsGrid.vue b/resources/js/components/SocialAccountsGrid.vue index 068e1c7a..7c8ebf71 100644 --- a/resources/js/components/SocialAccountsGrid.vue +++ b/resources/js/components/SocialAccountsGrid.vue @@ -183,7 +183,7 @@ const isDisconnected = (account: SocialAccount | null): boolean => {
- + {{ platform.account.display_name?.charAt(0) }} diff --git a/resources/js/components/posts/HashtagsModal.vue b/resources/js/components/posts/HashtagsModal.vue new file mode 100644 index 00000000..51f3a4c9 --- /dev/null +++ b/resources/js/components/posts/HashtagsModal.vue @@ -0,0 +1,67 @@ + + + \ No newline at end of file diff --git a/resources/js/components/ui/command/CommandDialog.vue b/resources/js/components/ui/command/CommandDialog.vue index 74397360..a60d135f 100644 --- a/resources/js/components/ui/command/CommandDialog.vue +++ b/resources/js/components/ui/command/CommandDialog.vue @@ -7,9 +7,11 @@ import Command from "./Command.vue" const props = withDefaults(defineProps(), { title: "Command Palette", description: "Search for a command to run...", + showCloseButton: false, }) const emits = defineEmits() @@ -18,7 +20,7 @@ const forwarded = useForwardPropsEmits(props, emits)