chore: optimize EventList display

This commit is contained in:
Andreas Hubel 2023-09-23 18:11:09 +02:00
commit f26a67633f

View file

@ -4,7 +4,7 @@ import TableCell from '@material-ui/core/TableCell';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import InfoIcon from '@material-ui/icons/InfoOutlined'; import InfoIcon from '@material-ui/icons/InfoOutlined';
import { actions as calendarActions, eventStruct } from '../redux/modules/calendar'; import { actions as calendarActions, eventStruct } from '../redux/modules/calendar';
import {actions as spaceDataActions, spacedataStruct} from '../redux/modules/spacedata'; import { actions as spaceDataActions, spacedataStruct } from '../redux/modules/spacedata';
import classNames from 'classnames'; import classNames from 'classnames';
import { withStyles } from '@material-ui/core/styles'; import { withStyles } from '@material-ui/core/styles';
import { AutoSizer, Column, Table } from 'react-virtualized'; import { AutoSizer, Column, Table } from 'react-virtualized';
@ -158,9 +158,6 @@ class EventList extends React.Component {
this.props.fetchCalendars(); this.props.fetchCalendars();
} }
formatDate = date => (date.format('DD.MM.YYYY'));
formatTime = date => (date.format('HH:mm'));
render() { render() {
const rows = this.props.events.filter(event => const rows = this.props.events.filter(event =>
@ -171,8 +168,7 @@ class EventList extends React.Component {
).map(event => { ).map(event => {
return { return {
...event, ...event,
start_date: this.formatDate(event.start), start: event.start.format('dd DD. MMM., HH:mm') ?? '',
start_time: this.formatTime(event.start),
summary: event.summary || event.description, summary: event.summary || event.description,
link: event.url && <a href={event.url}> link: event.url && <a href={event.url}>
<InfoIcon style={{ cursor: 'pointer', color: '#fff' }} /> <InfoIcon style={{ cursor: 'pointer', color: '#fff' }} />
@ -180,39 +176,39 @@ class EventList extends React.Component {
} }
}); });
const columns = [
{
width: 160,
label: 'Date',
dataKey: 'start',
},
{
width: 200,
flexGrow: 1,
label: 'Summary',
dataKey: 'summary',
},
{
width: 10,
label: 'Link',
dataKey: 'link',
},
{
width: 250,
label: 'Space',
dataKey: 'space',
align: 'right',
},
];
if ( this.props.spacedata.filter.length ) {
delete columns[3];
}
return ( return (
<WrappedVirtualizedTable <WrappedVirtualizedTable
rowCount={rows.length} rowCount={rows.length}
rowGetter={({ index }) => rows[index]} rowGetter={({ index }) => rows[index]}
columns={[ columns={columns}
{
width: 120,
label: 'Date',
dataKey: 'start_date',
},
{
width: 120,
label: 'Time',
dataKey: 'start_time',
},
{
width: 120,
flexGrow: 1,
label: 'Summary',
dataKey: 'summary',
},
{
width: 120,
flexGrow: 1,
label: 'Carbs (g)',
dataKey: 'space',
},
{
width: 120,
label: 'Protein (g)',
dataKey: 'link',
},
]}
/> />
); );
} }