Add onboarding complete setting

This commit is contained in:
myrmidex 2025-08-14 21:16:39 +02:00
parent 98fc361ab9
commit 7d4aa3da83

View file

@ -37,11 +37,15 @@ public function status(): JsonResponse
$hasChannel = PlatformChannel::where('is_active', true)->exists(); $hasChannel = PlatformChannel::where('is_active', true)->exists();
$hasRoute = Route::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'; $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 // User needs onboarding if:
$needsOnboarding = (!$hasPlatformAccount || !$hasFeed || !$hasChannel || !$hasRoute) && !$onboardingSkipped; // 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 // Determine current step
$currentStep = null; $currentStep = null;
@ -65,6 +69,8 @@ public function status(): JsonResponse
'has_channel' => $hasChannel, 'has_channel' => $hasChannel,
'has_route' => $hasRoute, 'has_route' => $hasRoute,
'onboarding_skipped' => $onboardingSkipped, 'onboarding_skipped' => $onboardingSkipped,
'onboarding_completed' => $onboardingCompleted,
'missing_components' => !$hasAllComponents && $onboardingCompleted,
], 'Onboarding status retrieved successfully.'); ], 'Onboarding status retrieved successfully.');
} }
@ -322,6 +328,10 @@ public function createRoute(Request $request): JsonResponse
'is_active' => true, '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( return $this->sendResponse(
new RouteResource($route->load(['feed', 'platformChannel'])), new RouteResource($route->load(['feed', 'platformChannel'])),
'Route created successfully.' 'Route created successfully.'
@ -333,7 +343,11 @@ public function createRoute(Request $request): JsonResponse
*/ */
public function complete(): 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( return $this->sendResponse(
['completed' => true], ['completed' => true],
@ -363,10 +377,12 @@ public function skip(): JsonResponse
public function resetSkip(): JsonResponse public function resetSkip(): JsonResponse
{ {
Setting::where('key', 'onboarding_skipped')->delete(); Setting::where('key', 'onboarding_skipped')->delete();
// Also reset completion status to allow re-onboarding
Setting::where('key', 'onboarding_completed')->delete();
return $this->sendResponse( return $this->sendResponse(
['reset' => true], ['reset' => true],
'Onboarding skip status reset successfully.' 'Onboarding status reset successfully.'
); );
} }
} }