Hook for loading the schedule

This commit is contained in:
Vencislav Atanasov 2024-09-18 22:27:07 +03:00
parent 77c88b2075
commit 38e52b25d8
2 changed files with 92 additions and 40 deletions

View File

@ -1,52 +1,46 @@
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import useEvents from './hooks/useEvents.js'; import useSchedule from './hooks/useSchedule.js';
import useSpeakers from './hooks/useSpeakers.js';
import useTracks from './hooks/useTracks.js';
import useEventTypes from './hooks/useEventTypes.js';
import useHalls from './hooks/useHalls.js';
import useSlots from './hooks/useSlots.js';
export default function Schedule({ export default function Schedule({
conferenceId, conferenceId,
}) { }) {
const { const {
data: events, events,
} = useEvents(conferenceId); speakers,
tracks,
const { eventTypes,
data: speakers, halls,
} = useSpeakers(conferenceId); slots,
isLoading,
const { } = useSchedule(conferenceId);
data: tracks,
} = useTracks(conferenceId);
const {
data: eventTypes,
} = useEventTypes(conferenceId);
const {
data: halls,
} = useHalls(conferenceId);
const {
data: slots,
} = useSlots(conferenceId);
return (<> return (<>
<div>conference id: {conferenceId}</div> <div>conference id: {conferenceId}</div>
<div>events:</div> {isLoading && <p>Loading...</p>}
<div>{JSON.stringify(events)}</div> {events && <>
<div>speakers:</div> <div>events:</div>
<div>{JSON.stringify(speakers)}</div> <div>{JSON.stringify(events)}</div>
<div>tracks:</div> </>}
<div>{JSON.stringify(tracks)}</div> {speakers && <>
<div>event types:</div> <div>speakers:</div>
<div>{JSON.stringify(eventTypes)}</div> <div>{JSON.stringify(speakers)}</div>
<div>halls:</div> </>}
<div>{JSON.stringify(halls)}</div> {tracks && <>
<div>slots:</div> <div>tracks:</div>
<div>{JSON.stringify(slots)}</div> <div>{JSON.stringify(tracks)}</div>
</>}
{eventTypes && <>
<div>event types:</div>
<div>{JSON.stringify(eventTypes)}</div>
</>}
{halls && <>
<div>halls:</div>
<div>{JSON.stringify(halls)}</div>
</>}
{slots && <>
<div>slots:</div>
<div>{JSON.stringify(slots)}</div>
</>}
</>); </>);
} }

58
src/hooks/useSchedule.js Normal file
View File

@ -0,0 +1,58 @@
import useEvents from './useEvents.js';
import useSpeakers from './useSpeakers.js';
import useTracks from './useTracks.js';
import useEventTypes from './useEventTypes.js';
import useHalls from './useHalls.js';
import useSlots from './useSlots.js';
export default function useSchedule(conferenceId) {
const {
data: events,
isLoading: eventsLoading,
isValidating: eventsValidating,
} = useEvents(conferenceId);
const {
data: speakers,
isLoading: speakersLoading,
isValidating: speakersValidating,
} = useSpeakers(conferenceId);
const {
data: tracks,
isLoading: tracksLoading,
isValidating: tracksValidating,
} = useTracks(conferenceId);
const {
data: eventTypes,
isLoading: eventTypesLoading,
isValidating: eventTypesValidating,
} = useEventTypes(conferenceId);
const {
data: halls,
isLoading: hallsLoading,
isValidating: hallsValidating,
} = useHalls(conferenceId);
const {
data: slots,
isLoading: slotsLoading,
isValidating: slotsValidating,
} = useSlots(conferenceId);
const isLoading = eventsLoading || speakersLoading || tracksLoading || eventTypesLoading || hallsLoading || slotsLoading;
const isValidating = eventsValidating || speakersValidating || tracksValidating || eventTypesValidating || hallsValidating || slotsValidating;
return {
events,
speakers,
tracks,
eventTypes,
halls,
slots,
isLoading,
isValidating,
};
}