-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: event details failed to handle super event fetching
LIIKUNTA-514
- Loading branch information
1 parent
c74534e
commit c79fcee
Showing
5 changed files
with
77 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { useLazyQuery } from '@apollo/client'; | ||
import React from 'react'; | ||
import type { EventFieldsFragment, SuperEventResponse } from '../types'; | ||
import { EventDetailsDocument } from '../types'; | ||
import { getEventIdFromUrl } from '../utils'; | ||
|
||
function useSuperEventLazyLoad(event?: EventFieldsFragment) { | ||
const [superEvent, setSuperEvent] = React.useState<SuperEventResponse>({ | ||
data: null, | ||
status: 'pending', | ||
}); | ||
const superEventId = getEventIdFromUrl( | ||
event?.superEvent?.internalId ?? '', | ||
'event' | ||
); | ||
const [ | ||
superEventSearch, | ||
{ data: superEventData, loading: superEventLoading }, | ||
] = useLazyQuery(EventDetailsDocument, {}); | ||
React.useEffect(() => { | ||
if (superEventId) { | ||
superEventSearch({ | ||
variables: { | ||
id: superEventId, | ||
include: ['in_language', 'keywords', 'location', 'audience'], | ||
}, | ||
}); | ||
// Still loading the super event, | ||
if (superEventLoading) { | ||
setSuperEvent({ data: null, status: 'pending' }); | ||
} | ||
// Loaded, so there should be data if there ever was a super event | ||
else if (superEventData) { | ||
setSuperEvent({ | ||
data: superEventData.eventDetails, | ||
status: 'resolved', | ||
}); | ||
} | ||
// No super event | ||
else if (event) { | ||
setSuperEvent({ data: null, status: 'resolved' }); | ||
} | ||
} | ||
// No super event id to fetch with | ||
else { | ||
setSuperEvent({ | ||
data: null, | ||
status: 'resolved', | ||
}); | ||
} | ||
}, [ | ||
event, | ||
superEventId, | ||
superEventData, | ||
superEventSearch, | ||
superEventLoading, | ||
]); | ||
|
||
return { | ||
superEvent, | ||
setSuperEvent, | ||
superEventSearch, | ||
superEventLoading, | ||
}; | ||
} | ||
|
||
export default useSuperEventLazyLoad; |