Light Lantern Flow Refactor - Implementation Complete โ โ
What Was Refactored โ
This document describes the refactor that was implemented to consolidate the Light Lantern flows and eliminate code duplication.
Previous State (Before Refactor) โ
Both Flow 1 and Flow 2 did the same thing (light a lantern) but used completely different code paths:
Flow 1 (Venue Detail) โ
- Lives in
Dashboard.jsxusingviewstate machine - Entry:
handleLightLantern()โ setview='form' - Form:
LightLanternFormembedded directly - Light:
confirmLantern()โ callslightLantern()service โ setview='active' - Success: Separate
view='success'screen beforeview='active'(duplicate!)
Flow 2 (Fire Icon Modal) โ
- Lives in
LightLanternModal.jsxcomponent - Entry:
handleLanternHubLightLantern()โ open modal - Form:
LightLanternForminside modal - Light:
handleFormConfirm()โ callslightLantern()service โ setstep='success' - Success: Built into modal with 50 lines of duplicate UI
Problems โ
| Issue | Impact |
|---|---|
| Duplicated Firebase calls | Hard to maintain, inconsistent error handling |
| Different success screens | User gets different UX depending on entry point |
| Separate state management | bugs in one flow don't fix the other |
| ~200 lines of parallel code | Waste and maintenance burden |
| Modal re-fetches location | Unnecessary API calls |
Implementation (Completed 2026-01-07) โ
1. Created Shared Hook: useLightLantern โ
File: src/hooks/useLightLantern.js
Centralizes the Firebase lighting logic:
const { lightLanternFlow, loading, error } = useLightLantern()
await lightLanternFlow({
userId: currentUser.uid,
venueId: venue.id,
location: { lat, lng },
formData: { mood, interest },
onSuccess: (lantern) => { ... },
onError: (error) => { ... }
})Benefits:
- Single source of truth for lantern creation
- Consistent loading and error states
- Callbacks for both flows to handle success/error
2. Refactored Flow 1 (Dashboard.jsx) โ
Changes to confirmLantern():
- Now uses
useLightLanternhook instead of direct Firebase call - Removed 15 lines of duplicate code
- Error handling moved to hook callback
// Before: 20 lines of Firebase logic
// After: Uses hook, much simpler
await lightLanternFlow({
userId: currentUser.uid,
venueId: selectedVenue.id,
location: userLocation,
formData: data,
onSuccess: (lantern) => {
setView('active')
},
onError: (error) => {
alert('Failed: ' + error.message)
}
})3. Refactored Flow 2 (LightLanternModal.jsx) โ
Changes:
- Now uses
useLightLanternhook - Removed success step from modal (~50 lines deleted)
- Modal simplified to just 2 steps: venue โ form โ close
- Dashboard's
onLanternLitcallback handles navigation toActiveLanternView
Before:
- 3 steps: venue โ form โ success (built into modal)
- 50 lines of success UI duplication
- Complex state:
selectedVenue,formData,litLantern
After:
- 2 steps: venue โ form
- Modal closes on success, no success screen needed
- Simplified state:
selectedVenue,lighting - Uses hook:
const step = selectedVenue ? 'form' : 'venue'
4. Bug Fixes โ
Fixed Flow 1 duplicate success screens:
- Removed intermediate
view='success'state - Goes directly to
ActiveLanternViewafter lighting
Fixed Flow 2 blank screen issue:
- Modal's
onLanternLitcallback now always setsview='active' ActiveLanternViewhandles missingselectedVenuegracefully
Results โ
Code Metrics โ
| Metric | Before | After | Change |
|---|---|---|---|
| Lines in LightLanternModal | 296 | 190 | -106 lines โฌ๏ธ |
| Duplicate Firebase calls | 2 | 1 | -50% ๐ฏ |
| Success screens | 2 different | 1 shared | Unified UX โ |
| Hook-based refactoring | 0% | 100% | DRY principle โ |
Architecture โ
User clicks Light Lantern (anywhere)
โ
Flow 1 (venue detail) OR Flow 2 (fire icon modal)
โ โ
confirmLantern() OR handleFormConfirm()
โ โ
useLightLantern hook
โ
Firebase: lightLantern()
โ
SUCCESS
โ
Dashboard: setView('active')
โ
ActiveLanternView (SAME SUCCESS SCREEN FOR BOTH)Benefits Achieved โ
โ
Single source of truth - Both flows use useLightLantern hook
โ
Code reduction - 106 lines removed from modal, 60+ lines of duplication eliminated
โ
Converged UX - Both flows end at same ActiveLanternView
โ
Easier to maintain - Change lighting logic once, affects both flows instantly
โ
Simpler modal - No success state management, just data collection
โ
Bugs fixed - Blank screen, duplicate success screens, setMyLantern error
โ
Type safety - Consistent parameters across both flows
โ
Scalability - If we add Flow 3, reuse same hook and success screen
Testing Verification โ
Both flows tested and working:
โ
Flow 1: Venue detail โ form โ success screen
โ
Flow 2: Fire icon โ modal โ form โ success screen
โ
Success screen shows correct lantern details
โ
Fire icon "View Details" shows lantern properly
โ
Real-time updates work correctly
Files Modified โ
- src/hooks/useLightLantern.js - NEW
- src/screens/dashboard/Dashboard.jsx - Updated
- src/components/LightLanternModal.jsx - Updated
- src/components/LightLanternForm.jsx - Minor updates
Future Improvements โ
If we add new flows:
- Reuse
useLightLanternhook - Reuse
ActiveLanternViewcomponent - New flows will automatically follow the same pattern
No need to duplicate lighting logic again!