feat: add option to display onboarding on homepage and improve modal slide handling
This commit is contained in:
@@ -30,18 +30,7 @@ class Modal extends Component
|
||||
|
||||
$userId = Auth::id();
|
||||
|
||||
// Check if user has seen onboarding before
|
||||
if ($perSession) {
|
||||
// Use cookie for per-session tracking
|
||||
$hasSeenOnboarding = $testMode ? false : \Illuminate\Support\Facades\Cookie::has('onboarding_completed');
|
||||
$this->currentSlide = (int) \Illuminate\Support\Facades\Cookie::get('onboarding_current_slide', 0);
|
||||
} else {
|
||||
// Use database session for persistent tracking
|
||||
$hasSeenOnboarding = $testMode ? false : session()->get("onboarding_seen_{$userId}", false);
|
||||
$this->currentSlide = session()->get("onboarding_current_slide_{$userId}", 0);
|
||||
}
|
||||
|
||||
// Only show if user hasn't seen it and there are slides
|
||||
// Load slides first so we can validate currentSlide
|
||||
try {
|
||||
$this->slides = OnboardingSlide::where('enabled', true)
|
||||
->orderBy('sort', 'asc')
|
||||
@@ -50,9 +39,39 @@ class Modal extends Component
|
||||
} catch (\Exception $e) {
|
||||
// If query fails (e.g., missing columns), don't show modal
|
||||
$this->slides = [];
|
||||
$this->showModal = false;
|
||||
return;
|
||||
}
|
||||
|
||||
$this->showModal = !$hasSeenOnboarding && count($this->slides) > 0 && $this->currentSlide < count($this->slides);
|
||||
// No slides configured, nothing to show
|
||||
if (count($this->slides) === 0) {
|
||||
$this->showModal = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if user has seen onboarding before
|
||||
if ($perSession) {
|
||||
// Use cookie for per-session tracking
|
||||
$hasSeenOnboarding = $testMode ? false : \Illuminate\Support\Facades\Cookie::has('onboarding_completed');
|
||||
$this->currentSlide = (int) \Illuminate\Support\Facades\Cookie::get('onboarding_current_slide', 0);
|
||||
} else {
|
||||
// Use database session for persistent tracking
|
||||
$hasSeenOnboarding = $testMode ? false : session()->get("onboarding_seen_{$userId}", false);
|
||||
$this->currentSlide = (int) session()->get("onboarding_current_slide_{$userId}", 0);
|
||||
}
|
||||
|
||||
// Reset currentSlide if out of bounds (slides may have been deleted/disabled)
|
||||
if ($this->currentSlide >= count($this->slides)) {
|
||||
$this->currentSlide = 0;
|
||||
// Clear the stored progress since it's invalid
|
||||
if ($perSession) {
|
||||
\Illuminate\Support\Facades\Cookie::queue(\Illuminate\Support\Facades\Cookie::forget('onboarding_current_slide'));
|
||||
} else {
|
||||
session()->forget("onboarding_current_slide_{$userId}");
|
||||
}
|
||||
}
|
||||
|
||||
$this->showModal = !$hasSeenOnboarding;
|
||||
}
|
||||
|
||||
public function getShowBackdropProperty()
|
||||
|
||||
Reference in New Issue
Block a user