Compare commits

...

4 Commits

Author SHA1 Message Date
Vencislav Atanasov 77c88b2075 Render all requests data 2024-09-18 21:57:36 +03:00
Vencislav Atanasov c6e1ed6ef1 Add hooks for all requests 2024-09-18 21:50:23 +03:00
Vencislav Atanasov ff715b610b Conference selection 2024-09-18 21:40:20 +03:00
Vencislav Atanasov cba2439f11 Add prop-types 2024-09-18 21:34:10 +03:00
10 changed files with 99 additions and 15 deletions

View File

@ -10,6 +10,7 @@
"preview": "vite preview"
},
"dependencies": {
"prop-types": "^15.8.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"swr": "^2.2.5"

55
src/Schedule.jsx Normal file
View File

@ -0,0 +1,55 @@
import PropTypes from 'prop-types';
import useEvents from './hooks/useEvents.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({
conferenceId,
}) {
const {
data: events,
} = useEvents(conferenceId);
const {
data: speakers,
} = useSpeakers(conferenceId);
const {
data: tracks,
} = useTracks(conferenceId);
const {
data: eventTypes,
} = useEventTypes(conferenceId);
const {
data: halls,
} = useHalls(conferenceId);
const {
data: slots,
} = useSlots(conferenceId);
return (<>
<div>conference id: {conferenceId}</div>
<div>events:</div>
<div>{JSON.stringify(events)}</div>
<div>speakers:</div>
<div>{JSON.stringify(speakers)}</div>
<div>tracks:</div>
<div>{JSON.stringify(tracks)}</div>
<div>event types:</div>
<div>{JSON.stringify(eventTypes)}</div>
<div>halls:</div>
<div>{JSON.stringify(halls)}</div>
<div>slots:</div>
<div>{JSON.stringify(slots)}</div>
</>);
}
Schedule.propTypes = {
conferenceId: PropTypes.string.isRequired,
};

View File

@ -1,21 +1,31 @@
import useConferences from './hooks/useConferences.js';
import { useMemo, useState } from 'react';
import Schedule from './Schedule.jsx';
import { dateSorter } from './utils.js';
export default function ScheduleLoader() {
const {
conferences,
data,
error,
isLoading,
} = useConferences();
const conferences = useMemo(() => Array.isArray(data) ? data.sort(dateSorter('start_date')) : data, [data]);
const [ conferenceId, setConferenceId ] = useState();
return (<>
{isLoading && <p>Please wait...</p>}
{error && <p>Error: {error}</p>}
{conferences && <>
<label>Select a conference</label>
<select>
<select onChange={e => setConferenceId(e.target.value)}>
{conferences.map(conference => <option key={conference.id}
value={conference.id}>{conference.title}</option>)}
</select>
</>}
{conferenceId && <div>
<Schedule conferenceId={conferenceId} />
</div>}
</>);
}

View File

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

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`);
}