Prepare for event table rendering

This commit is contained in:
Vencislav Atanasov 2024-09-20 23:11:27 +03:00
parent d92a9e807d
commit 6de6958f91
3 changed files with 46 additions and 1 deletions

3
src/Event.jsx Normal file
View File

@ -0,0 +1,3 @@
export default function Event() {
}

View File

@ -2,6 +2,8 @@ import PropTypes from 'prop-types';
import useSchedule from './hooks/useSchedule.js'; import useSchedule from './hooks/useSchedule.js';
import { getSpeakerName, isTrackHidden } from './utils.js'; import { getSpeakerName, isTrackHidden } from './utils.js';
import { Fragment } from 'react'; import { Fragment } from 'react';
import useScheduleTable from './hooks/useScheduleTable.js';
import Event from './Event.jsx';
export default function Schedule({ export default function Schedule({
conferenceId, conferenceId,
@ -12,18 +14,41 @@ export default function Schedule({
speakers, speakers,
tracks, tracks,
halls, halls,
slots,
isLoading, isLoading,
loadingProgress, loadingProgress,
} = useSchedule(conferenceId); } = useSchedule(conferenceId);
const {
header,
rows,
} = useScheduleTable({
events,
halls,
slots,
lang,
});
return (<> return (<>
{isLoading && <>Loading... <progress value={loadingProgress} /></>} {isLoading && <>Loading... <progress value={loadingProgress} /></>}
{halls && <table border="1"> {halls && <table border="1">
<thead> <thead>
<tr> <tr>
{Object.entries(halls).map(([hallId, hall]) => <th key={hallId}>{hall.name[lang]}</th>)} {header.map(hall => <th key={hall.id}>{hall.name}</th>)}
</tr> </tr>
</thead> </thead>
<tbody>
{rows.map(row => <tr key={row.id}>
{row.cells.map(cell => <td key={cell.id} {...cell.attributes}>
<Event {...cell.event} />
</td>)}
</tr>)}
</tbody>
<tfoot>
<tr>
{header.map(hall => <th key={hall.id}>{hall.name}</th>)}
</tr>
</tfoot>
</table>} </table>}
{tracks && Object.entries(tracks).filter(([, track]) => {tracks && Object.entries(tracks).filter(([, track]) =>
!isTrackHidden(track) !isTrackHidden(track)

View File

@ -0,0 +1,17 @@
export default function useScheduleTable({
halls = {},
lang,
}) {
const hallIds = new Set(Object.keys(halls));
const header = Object.entries(halls).filter(([id]) => hallIds.has(id)).map(([id, hall]) => ({
id,
name: hall.name[lang],
}));
const rows = [];
return {
header,
rows,
};
}