Add filtering by event type id
This commit is contained in:
parent
b17572da4b
commit
acbe54a325
|
@ -1,7 +1,7 @@
|
||||||
import PropTypes from 'prop-types';
|
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, useState } from 'react';
|
||||||
import useScheduleTable from '../hooks/useScheduleTable.js';
|
import useScheduleTable from '../hooks/useScheduleTable.js';
|
||||||
import Event from './Event.jsx';
|
import Event from './Event.jsx';
|
||||||
import defaultSpeaker from '../assets/default-speaker.png';
|
import defaultSpeaker from '../assets/default-speaker.png';
|
||||||
|
@ -17,6 +17,7 @@ export default function Schedule({
|
||||||
const {
|
const {
|
||||||
speakers,
|
speakers,
|
||||||
tracks,
|
tracks,
|
||||||
|
eventTypes,
|
||||||
halls,
|
halls,
|
||||||
events,
|
events,
|
||||||
slots,
|
slots,
|
||||||
|
@ -25,25 +26,32 @@ export default function Schedule({
|
||||||
isComplete,
|
isComplete,
|
||||||
} = useSchedule(conferenceId);
|
} = useSchedule(conferenceId);
|
||||||
|
|
||||||
|
const [eventTypeId, setEventTypeId] = useState(0);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
header,
|
header,
|
||||||
rows,
|
rows,
|
||||||
} = useScheduleTable({
|
} = useScheduleTable({
|
||||||
tracks,
|
eventTypeId,
|
||||||
halls,
|
halls,
|
||||||
events,
|
events,
|
||||||
slots,
|
slots,
|
||||||
});
|
});
|
||||||
|
|
||||||
return (<>
|
return (<>
|
||||||
|
{isComplete && <select value={eventTypeId} onChange={e => setEventTypeId(parseInt(e.target.value, 10))}>
|
||||||
|
<option value={0}>All event types</option>
|
||||||
|
{Object.values(eventTypes).map(eventType =>
|
||||||
|
<option key={eventType.id} value={eventType.id}>{eventType.name[lang]}</option>)}
|
||||||
|
</select>}
|
||||||
{isLoading && <progress value={loadingProgress}/>}
|
{isLoading && <progress value={loadingProgress}/>}
|
||||||
{isComplete && <div className="schedule">
|
{isComplete && <div className="schedule">
|
||||||
<hr />
|
<hr/>
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<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}>
|
||||||
|
|
|
@ -1,10 +1,17 @@
|
||||||
export default function useScheduleTable({
|
import { useMemo } from 'react';
|
||||||
events = {},
|
|
||||||
halls = {},
|
|
||||||
}) {
|
|
||||||
const header = Object.values(halls);
|
|
||||||
|
|
||||||
const rows = Object.values(events).map(event => ({
|
export default function useScheduleTable({
|
||||||
|
eventTypeId,
|
||||||
|
halls = {},
|
||||||
|
events = {},
|
||||||
|
slots = {},
|
||||||
|
}) {
|
||||||
|
const filteredEvents = useMemo(() => Object.values(events).filter(event => eventTypeId > 0 ? event.event_type_id === eventTypeId : true), [eventTypeId, events]);
|
||||||
|
const filteredEventIds = useMemo(() => new Set(filteredEvents.map(event => event.id)), [filteredEvents]);
|
||||||
|
const filteredHallIds = useMemo(() => new Set(Object.values(slots).filter(slot => filteredEventIds.has(slot.event_id)).map(slot => slot.hall_id)), [filteredEventIds, slots]);
|
||||||
|
const header = useMemo(() => Object.values(halls).filter(hall => filteredHallIds.has(hall.id)), [filteredHallIds, halls]);
|
||||||
|
|
||||||
|
const rows = filteredEvents.map(event => ({
|
||||||
id: event.id,
|
id: event.id,
|
||||||
cells: [{
|
cells: [{
|
||||||
id: 1,
|
id: 1,
|
||||||
|
|
Loading…
Reference in New Issue