Add ids and relations to the API responses, add completion flag to data loading hook
This commit is contained in:
parent
2e83ef89b4
commit
1dd3ff9292
|
@ -4,45 +4,65 @@ import useTracks from './useTracks.js';
|
||||||
import useEventTypes from './useEventTypes.js';
|
import useEventTypes from './useEventTypes.js';
|
||||||
import useHalls from './useHalls.js';
|
import useHalls from './useHalls.js';
|
||||||
import useSlots from './useSlots.js';
|
import useSlots from './useSlots.js';
|
||||||
import { calculateProgress } from '../utils.js';
|
import { addIdAndRelations, calculateProgress } from '../utils.js';
|
||||||
|
import { useMemo } from 'react';
|
||||||
|
|
||||||
export default function useSchedule(conferenceId) {
|
export default function useSchedule(conferenceId) {
|
||||||
const {
|
const {
|
||||||
data: events,
|
data: speakersResponse,
|
||||||
isLoading: eventsLoading,
|
|
||||||
isValidating: eventsValidating,
|
|
||||||
} = useEvents(conferenceId);
|
|
||||||
|
|
||||||
const {
|
|
||||||
data: speakers,
|
|
||||||
isLoading: speakersLoading,
|
isLoading: speakersLoading,
|
||||||
isValidating: speakersValidating,
|
isValidating: speakersValidating,
|
||||||
} = useSpeakers(conferenceId);
|
} = useSpeakers(conferenceId);
|
||||||
|
|
||||||
|
const speakers = useMemo(() => addIdAndRelations(speakersResponse || []), [speakersResponse]);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: tracks,
|
data: tracksResponse,
|
||||||
isLoading: tracksLoading,
|
isLoading: tracksLoading,
|
||||||
isValidating: tracksValidating,
|
isValidating: tracksValidating,
|
||||||
} = useTracks(conferenceId);
|
} = useTracks(conferenceId);
|
||||||
|
|
||||||
|
const tracks = useMemo(() => addIdAndRelations(tracksResponse || []), [tracksResponse]);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: eventTypes,
|
data: eventTypesResponse,
|
||||||
isLoading: eventTypesLoading,
|
isLoading: eventTypesLoading,
|
||||||
isValidating: eventTypesValidating,
|
isValidating: eventTypesValidating,
|
||||||
} = useEventTypes(conferenceId);
|
} = useEventTypes(conferenceId);
|
||||||
|
|
||||||
|
const eventTypes = useMemo(() => addIdAndRelations(eventTypesResponse || []), [eventTypesResponse]);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: halls,
|
data: hallsResponse,
|
||||||
isLoading: hallsLoading,
|
isLoading: hallsLoading,
|
||||||
isValidating: hallsValidating,
|
isValidating: hallsValidating,
|
||||||
} = useHalls(conferenceId);
|
} = useHalls(conferenceId);
|
||||||
|
|
||||||
|
const halls = useMemo(() => addIdAndRelations(hallsResponse || []), [hallsResponse]);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: slots,
|
data: eventsResponse,
|
||||||
|
isLoading: eventsLoading,
|
||||||
|
isValidating: eventsValidating,
|
||||||
|
} = useEvents(conferenceId);
|
||||||
|
|
||||||
|
const events = useMemo(() => addIdAndRelations(eventsResponse || [], [
|
||||||
|
['event_type', eventTypes, 'event_type_id'],
|
||||||
|
['track', tracks, 'track_id'],
|
||||||
|
['participant_users', speakers, 'participant_user_ids'],
|
||||||
|
]), [eventsResponse, eventTypes, tracks, speakers]);
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: slotsResponse,
|
||||||
isLoading: slotsLoading,
|
isLoading: slotsLoading,
|
||||||
isValidating: slotsValidating,
|
isValidating: slotsValidating,
|
||||||
} = useSlots(conferenceId);
|
} = useSlots(conferenceId);
|
||||||
|
|
||||||
|
const slots = useMemo(() => addIdAndRelations(slotsResponse || [], [
|
||||||
|
['hall', halls, 'hall_id'],
|
||||||
|
['event', events, 'event_id'],
|
||||||
|
]), [slotsResponse, halls, events]);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
isStarted: isLoading,
|
isStarted: isLoading,
|
||||||
remainingProgress: loadingProgress,
|
remainingProgress: loadingProgress,
|
||||||
|
@ -53,6 +73,10 @@ export default function useSchedule(conferenceId) {
|
||||||
remainingProgress: validatingProgress,
|
remainingProgress: validatingProgress,
|
||||||
} = calculateProgress(eventsValidating, speakersValidating, tracksValidating, eventTypesValidating, hallsValidating, slotsValidating);
|
} = calculateProgress(eventsValidating, speakersValidating, tracksValidating, eventTypesValidating, hallsValidating, slotsValidating);
|
||||||
|
|
||||||
|
const {
|
||||||
|
isComplete,
|
||||||
|
} = calculateProgress(events, speakers, tracks, eventTypes, halls, slots);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
events,
|
events,
|
||||||
speakers,
|
speakers,
|
||||||
|
@ -64,5 +88,6 @@ export default function useSchedule(conferenceId) {
|
||||||
loadingProgress,
|
loadingProgress,
|
||||||
isValidating,
|
isValidating,
|
||||||
validatingProgress,
|
validatingProgress,
|
||||||
|
isComplete,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue