Add sort to selected dates list

This commit is contained in:
rui hildt 2020-06-02 16:40:08 +02:00
parent 950e2e3165
commit a97f8dc1c3
2 changed files with 4 additions and 18 deletions

View File

@ -2,9 +2,9 @@ import React from 'react';
import { Divider, Icon, IconButton } from 'rsuite';
export default function SelectedDates({ datesList, eventsList, handleDelete }) {
export default function SelectedDates({ datesList, handleDelete }) {
return (
<div>
<>
<h3>Dates selected</h3>
<ul>
{datesList.map((date) => (
@ -21,6 +21,6 @@ export default function SelectedDates({ datesList, eventsList, handleDelete }) {
</li>
))}
</ul>
</div>
</>
);
}

View File

@ -13,7 +13,7 @@ export default function Schedule() {
useEffect(() => {
// Update selected dates
let updatedDates = eventsToDates(eventsList);
let updatedDates = eventsToDates(eventsList).sort();
setDatesList(updatedDates);
}, [eventsList]);
@ -136,7 +136,6 @@ export default function Schedule() {
<FormGroup>
<SelectedDates
datesList={datesList}
eventsList={eventsList}
handleDelete={handleDelete}
/>
<Button>Confirm dates</Button>
@ -155,16 +154,3 @@ const eventsToDates = (events) => {
});
return dates;
};
// Convert Luxon Datetime objects to events
const datesToEvents = (dates) => {
let events = [];
dates.forEach((date) => {
let event = {
start: date.toFormat('yyyy-MM-dd'),
display: 'background',
};
events.push(event);
});
return events;
};