From 7d4aa3da83b22cb139830009a7b1af9bc0276b37 Mon Sep 17 00:00:00 2001 From: myrmidex Date: Thu, 14 Aug 2025 21:16:39 +0200 Subject: [PATCH] Add onboarding complete setting --- .../Api/V1/OnboardingController.php | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/backend/app/Http/Controllers/Api/V1/OnboardingController.php b/backend/app/Http/Controllers/Api/V1/OnboardingController.php index e21df5c..f39c83c 100644 --- a/backend/app/Http/Controllers/Api/V1/OnboardingController.php +++ b/backend/app/Http/Controllers/Api/V1/OnboardingController.php @@ -37,11 +37,15 @@ public function status(): JsonResponse $hasChannel = PlatformChannel::where('is_active', true)->exists(); $hasRoute = Route::where('is_active', true)->exists(); - // Check if onboarding was explicitly skipped + // Check if onboarding was explicitly skipped or completed $onboardingSkipped = Setting::where('key', 'onboarding_skipped')->value('value') === 'true'; + $onboardingCompleted = Setting::where('key', 'onboarding_completed')->exists(); - // User needs onboarding if they don't have the required components AND haven't skipped it - $needsOnboarding = (!$hasPlatformAccount || !$hasFeed || !$hasChannel || !$hasRoute) && !$onboardingSkipped; + // User needs onboarding if: + // 1. They haven't completed or skipped onboarding AND + // 2. They don't have all required components + $hasAllComponents = $hasPlatformAccount && $hasFeed && $hasChannel && $hasRoute; + $needsOnboarding = !$onboardingCompleted && !$onboardingSkipped && !$hasAllComponents; // Determine current step $currentStep = null; @@ -65,6 +69,8 @@ public function status(): JsonResponse 'has_channel' => $hasChannel, 'has_route' => $hasRoute, 'onboarding_skipped' => $onboardingSkipped, + 'onboarding_completed' => $onboardingCompleted, + 'missing_components' => !$hasAllComponents && $onboardingCompleted, ], 'Onboarding status retrieved successfully.'); } @@ -322,6 +328,10 @@ public function createRoute(Request $request): JsonResponse 'is_active' => true, ]); + // Trigger article discovery when the first route is created during onboarding + // This ensures articles start being fetched immediately after setup + ArticleDiscoveryJob::dispatch(); + return $this->sendResponse( new RouteResource($route->load(['feed', 'platformChannel'])), 'Route created successfully.' @@ -333,7 +343,11 @@ public function createRoute(Request $request): JsonResponse */ public function complete(): JsonResponse { - ArticleDiscoveryJob::dispatch(); + // Track that onboarding has been completed with a timestamp + Setting::updateOrCreate( + ['key' => 'onboarding_completed'], + ['value' => now()->toIso8601String()] + ); return $this->sendResponse( ['completed' => true], @@ -363,10 +377,12 @@ public function skip(): JsonResponse public function resetSkip(): JsonResponse { Setting::where('key', 'onboarding_skipped')->delete(); + // Also reset completion status to allow re-onboarding + Setting::where('key', 'onboarding_completed')->delete(); return $this->sendResponse( ['reset' => true], - 'Onboarding skip status reset successfully.' + 'Onboarding status reset successfully.' ); } }