Compare commits
3 Commits
70b1b36852
...
a3a2ed8c3f
Author | SHA1 | Date |
---|---|---|
Vencislav Atanasov | a3a2ed8c3f | |
Vencislav Atanasov | c3d38a0fae | |
Vencislav Atanasov | 4128e0e68a |
|
@ -48,11 +48,11 @@ export default function Schedule({
|
||||||
{isComplete && <div className="schedule">
|
{isComplete && <div className="schedule">
|
||||||
<hr/>
|
<hr/>
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
{header.length > 0 && <thead>
|
||||||
<tr>
|
<tr>
|
||||||
{header.map(hall => <th key={hall.id}>{hall.name[lang]}</th>)}
|
{header.map(hall => <th key={hall.id}>{hall.name[lang]}</th>)}
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>}
|
||||||
<tbody>
|
<tbody>
|
||||||
{rows.map(row => <tr key={row.id}>
|
{rows.map(row => <tr key={row.id}>
|
||||||
{row.cells.map(cell => <td key={cell.id} {...cell.attributes}>
|
{row.cells.map(cell => <td key={cell.id} {...cell.attributes}>
|
||||||
|
@ -60,11 +60,11 @@ export default function Schedule({
|
||||||
</td>)}
|
</td>)}
|
||||||
</tr>)}
|
</tr>)}
|
||||||
</tbody>
|
</tbody>
|
||||||
<tfoot>
|
{header.length > 0 && <tfoot>
|
||||||
<tr>
|
<tr>
|
||||||
{header.map(hall => <th key={hall.id}>{hall.name[lang]}</th>)}
|
{header.map(hall => <th key={hall.id}>{hall.name[lang]}</th>)}
|
||||||
</tr>
|
</tr>
|
||||||
</tfoot>
|
</tfoot>}
|
||||||
</table>
|
</table>
|
||||||
<div className="separator"/>
|
<div className="separator"/>
|
||||||
<table>
|
<table>
|
||||||
|
|
|
@ -6,10 +6,12 @@ export default function useScheduleTable({
|
||||||
events = {},
|
events = {},
|
||||||
slots = {},
|
slots = {},
|
||||||
}) {
|
}) {
|
||||||
const filteredEvents = useMemo(() => events.filter(event => eventTypeId > 0 ? event.event_type_id === eventTypeId : true), [eventTypeId, events]);
|
return useMemo(() => {
|
||||||
const filteredEventIds = useMemo(() => filteredEvents.map(event => event.id), [filteredEvents]);
|
const filteredEvents = events.filter(event => eventTypeId > 0 ? event.event_type_id === eventTypeId : true);
|
||||||
const filteredHallIds = useMemo(() => new Set(slots.filter(slot => filteredEventIds.includes(slot.event_id)).map(slot => slot.hall_id)), [filteredEventIds, slots]);
|
const filteredEventIds = filteredEvents.map(event => event.id);
|
||||||
const header = useMemo(() => halls.filter(hall => filteredHallIds.has(hall.id)), [filteredHallIds, halls]);
|
const filteredSlots = slots.filter(slot => filteredEventIds.includes(slot.event_id));
|
||||||
|
const filteredHallIds = new Set(filteredSlots.map(slot => slot.hall_id));
|
||||||
|
const header = halls.filter(hall => filteredHallIds.has(hall.id));
|
||||||
|
|
||||||
const rows = filteredEvents.map(event => ({
|
const rows = filteredEvents.map(event => ({
|
||||||
id: event.id,
|
id: event.id,
|
||||||
|
@ -27,4 +29,5 @@ export default function useScheduleTable({
|
||||||
header,
|
header,
|
||||||
rows,
|
rows,
|
||||||
};
|
};
|
||||||
|
}, [eventTypeId, events, halls, slots]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,11 +49,12 @@ export const normalizeResponse = (items = [], relations = []) =>
|
||||||
...item,
|
...item,
|
||||||
...Object.fromEntries(relations.map(([field, collection, idField]) => {
|
...Object.fromEntries(relations.map(([field, collection, idField]) => {
|
||||||
const key = item[idField];
|
const key = item[idField];
|
||||||
const fn = Array.isArray(key) ? 'filter' : 'find';
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
field,
|
field,
|
||||||
collection[fn](item => item.id === key),
|
Array.isArray(key) ?
|
||||||
|
collection.filter(item => key.includes(item.id)) :
|
||||||
|
collection.find(item => item.id === key),
|
||||||
];
|
];
|
||||||
})),
|
})),
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue