@@ -25,11 +25,16 @@ export const useQuiz = (user, onQuizComplete = () => { }, eventId = 'global', de
2525 if ( APP_CONFIG . enableEvents && eventId && eventId !== APP_CONFIG . defaultEventId ) {
2626 const fetchEventData = async ( ) => {
2727 try {
28- const eventDoc = await getDoc (
29- doc ( db , 'artifacts' , ARTIFACT_ID , 'public' , 'data' , 'events' , eventId )
30- ) ;
28+ const [ eventDoc , rootDoc ] = await Promise . all ( [
29+ getDoc ( doc ( db , 'artifacts' , ARTIFACT_ID , 'public' , 'data' , 'events' , eventId ) ) ,
30+ getDoc ( doc ( db , 'artifacts' , ARTIFACT_ID , 'public' , 'data' ) )
31+ ] ) ;
3132 if ( eventDoc . exists ( ) ) {
32- setEventData ( { id : eventDoc . id , ...eventDoc . data ( ) } ) ;
33+ setEventData ( {
34+ id : eventDoc . id ,
35+ ...eventDoc . data ( ) ,
36+ vibeCodeActive : rootDoc . exists ( ) ? ( rootDoc . data ( ) ?. vibeCodeActive ?? false ) : false
37+ } ) ;
3338 }
3439 } catch ( error ) {
3540 console . error ( "Error fetching event data:" , error ) ;
@@ -43,7 +48,11 @@ export const useQuiz = (user, onQuizComplete = () => { }, eventId = 'global', de
4348 doc ( db , 'artifacts' , ARTIFACT_ID , 'public' , 'data' )
4449 ) ;
4550 if ( mpDoc . exists ( ) ) {
46- setEventData ( { id : null , marketplaces : mpDoc . data ( ) ?. marketplaces || [ ] } ) ;
51+ setEventData ( {
52+ id : null ,
53+ marketplaces : mpDoc . data ( ) ?. marketplaces || [ ] ,
54+ vibeCodeActive : mpDoc . data ( ) ?. vibeCodeActive ?? false
55+ } ) ;
4756 } else {
4857 console . log ( "No vouchers found" ) ;
4958 }
@@ -88,15 +97,36 @@ export const useQuiz = (user, onQuizComplete = () => { }, eventId = 'global', de
8897 let fetchedEventData = eventData ;
8998 if ( existingData . eventId && ! eventData ) {
9099 try {
91- const eventDoc = await getDoc (
92- doc ( db , 'artifacts' , ARTIFACT_ID , 'public' , 'data' , 'events' , existingData . eventId )
93- ) ;
100+ const [ eventDoc , rootDoc ] = await Promise . all ( [
101+ getDoc ( doc ( db , 'artifacts' , ARTIFACT_ID , 'public' , 'data' , 'events' , existingData . eventId ) ) ,
102+ getDoc ( doc ( db , 'artifacts' , ARTIFACT_ID , 'public' , 'data' ) )
103+ ] ) ;
104+ const vibeCodeActive = rootDoc . exists ( ) ? ( rootDoc . data ( ) ?. vibeCodeActive ?? false ) : false ;
94105 if ( eventDoc . exists ( ) ) {
95- fetchedEventData = eventDoc . data ( ) ;
106+ fetchedEventData = { ...eventDoc . data ( ) , vibeCodeActive } ;
107+ } else {
108+ fetchedEventData = {
109+ id : null ,
110+ marketplaces : rootDoc . exists ( ) ? ( rootDoc . data ( ) ?. marketplaces || [ ] ) : [ ] ,
111+ vibeCodeActive
112+ } ;
96113 }
97114 } catch ( error ) {
98115 console . error ( "Error fetching event data for existing result:" , error ) ;
99116 }
117+ } else if ( ! eventData ) {
118+ try {
119+ const rootDoc = await getDoc ( doc ( db , 'artifacts' , ARTIFACT_ID , 'public' , 'data' ) ) ;
120+ if ( rootDoc . exists ( ) ) {
121+ fetchedEventData = {
122+ id : null ,
123+ marketplaces : rootDoc . data ( ) ?. marketplaces || [ ] ,
124+ vibeCodeActive : rootDoc . data ( ) ?. vibeCodeActive ?? false
125+ } ;
126+ }
127+ } catch ( error ) {
128+ console . error ( "Error fetching root data for existing result:" , error ) ;
129+ }
100130 }
101131
102132 onQuizComplete ( {
0 commit comments