Add hooks for all requests

This commit is contained in:
Vencislav Atanasov 2024-09-18 21:50:23 +03:00
parent ff715b610b
commit c6e1ed6ef1
8 changed files with 36 additions and 15 deletions

View File

@ -1,14 +1,17 @@
import useConferences from './hooks/useConferences.js'; import useConferences from './hooks/useConferences.js';
import { useState } from 'react'; import { useMemo, useState } from 'react';
import Schedule from './Schedule.jsx'; import Schedule from './Schedule.jsx';
import { dateSorter } from './utils.js';
export default function ScheduleLoader() { export default function ScheduleLoader() {
const { const {
conferences, data,
error, error,
isLoading, isLoading,
} = useConferences(); } = useConferences();
const conferences = useMemo(() => Array.isArray(data) ? data.sort(dateSorter('start_date')) : data, [data]);
const [ conferenceId, setConferenceId ] = useState(); const [ conferenceId, setConferenceId ] = useState();
return (<> return (<>

View File

@ -1,17 +1,5 @@
import useCfpRequest from './useCfpRequest.js'; import useCfpRequest from './useCfpRequest.js';
import { useMemo } from 'react';
import { dateSorter } from '../utils.js';
export default function useConferences() { export default function useConferences() {
const { return useCfpRequest();
data,
...rest
} = useCfpRequest();
const conferences = useMemo(() => Array.isArray(data) ? data.sort(dateSorter('start_date')) : data, [data]);
return {
conferences,
...rest,
};
} }

View File

@ -0,0 +1,5 @@
import useCfpRequest from './useCfpRequest.js';
export default function useEventTypes(conferenceId) {
return useCfpRequest(`${conferenceId}/event_types.json`);
}

5
src/hooks/useEvents.js Normal file
View File

@ -0,0 +1,5 @@
import useCfpRequest from './useCfpRequest.js';
export default function useEvents(conferenceId) {
return useCfpRequest(`${conferenceId}/events.json`);
}

5
src/hooks/useHalls.js Normal file
View File

@ -0,0 +1,5 @@
import useCfpRequest from './useCfpRequest.js';
export default function useHalls(conferenceId) {
return useCfpRequest(`${conferenceId}/halls.json`);
}

5
src/hooks/useSlots.js Normal file
View File

@ -0,0 +1,5 @@
import useCfpRequest from './useCfpRequest.js';
export default function useSlots(conferenceId) {
return useCfpRequest(`${conferenceId}/slots.json`);
}

5
src/hooks/useSpeakers.js Normal file
View File

@ -0,0 +1,5 @@
import useCfpRequest from './useCfpRequest.js';
export default function useSpeakers(conferenceId) {
return useCfpRequest(`${conferenceId}/speakers.json`);
}

5
src/hooks/useTracks.js Normal file
View File

@ -0,0 +1,5 @@
import useCfpRequest from './useCfpRequest.js';
export default function useTracks(conferenceId) {
return useCfpRequest(`${conferenceId}/tracks.json`);
}