From 263e9e86b47c72a2e5ebe43e0420ab628ca7a45c Mon Sep 17 00:00:00 2001 From: cv <34649812+cpvalente@users.noreply.github.com> Date: Fri, 26 Mar 2021 22:22:10 +0100 Subject: [PATCH] list basics - populate list from events - add - remove --- src/features/editors/list/EventList.jsx | 78 +++++++++++++++++---- src/features/editors/list/EventListItem.jsx | 54 ++++++++++---- src/features/editors/list/List.module.css | 7 +- src/features/editors/list/listUtils.js | 2 +- 4 files changed, 110 insertions(+), 31 deletions(-) diff --git a/src/features/editors/list/EventList.jsx b/src/features/editors/list/EventList.jsx index af1e2611b..dc31b808d 100644 --- a/src/features/editors/list/EventList.jsx +++ b/src/features/editors/list/EventList.jsx @@ -4,36 +4,84 @@ import { useContext } from 'react'; import { EventContext } from '../../../app/context/eventContext'; import { EventListContext } from '../../../app/context/eventListContext'; import EventListItem from './EventListItem'; -import { sortByNumber } from './listUtils'; +import { sortByOrderVal } from './listUtils'; import style from './List.module.css'; import DelayBlock from './DelayBlock'; import BlockBlock from './BlockBlock'; +import { createEvent } from '@testing-library/dom'; export default function EventList(props) { - const [events] = useContext(EventListContext); - const [, setEvent] = useContext(EventContext); + const [events, setEvents] = useContext(EventListContext); + const [event, setEvent] = useContext(EventContext); + console.log('in el', events); + + const selected = event?.id || -1; + + const createEvent = (startPosition = 0) => { + // make an event + // TODO: Replace this with global def somewhere + // TODO: handle random ids better + let newEvent = { + id: Math.floor(Math.random()*10000000), + order: startPosition + 1, + title: '', + subtitle: '', + presenter: '', + timerStart: '', + timerEnd: '', + clockStarted: null, + timerDuration: 0, + }; + + // move all items one element down, starting from new position + let newEvents = events.map((e) => { + if (e.order > startPosition) e.order = e.order + 1; + return e; + }); + + // add an event at the beggining + newEvents = [newEvent, ...events]; + + // set to state + setEvents(newEvents); + }; + + const deleteEvent = (position) => { + // ?? SHould i reorder after? + + // remove event from array + let filtered = events.filter((e) => e.id !== position); + + // set to state + setEvents(filtered); + }; return ( <>
- - - } colorScheme='blue' /> + } + colorScheme='blue' + onClick={() => createEvent()} + />
- - - - - - - - - + {sortByOrderVal(events).map((e) => ( + + ))}
); diff --git a/src/features/editors/list/EventListItem.jsx b/src/features/editors/list/EventListItem.jsx index 92319ea5f..e6a9ec473 100644 --- a/src/features/editors/list/EventListItem.jsx +++ b/src/features/editors/list/EventListItem.jsx @@ -19,14 +19,30 @@ export default function EventListItem(props) { const [more, setMore] = useState(false); const [armed, setArmed] = useState(false); + const { data, selected, ...rest } = props; + return ( -
+
setArmed(!armed)} />
- + + + + +
+
+ @@ -37,31 +53,34 @@ export default function EventListItem(props) {
Title - +
Subtitle - +
Presenter - +
@@ -70,11 +89,12 @@ export default function EventListItem(props) {
Title - +
@@ -84,8 +104,18 @@ export default function EventListItem(props) {
- } colorScheme='red' /> - } colorScheme='blue' /> + } + colorScheme='red' + onClick={() => props.deleteEvent(data.id)} + /> + } + colorScheme='blue' + onClick={() => props.createEvent(data.order)} + /> } colorScheme='yellow' /> } colorScheme='purple' />
diff --git a/src/features/editors/list/List.module.css b/src/features/editors/list/List.module.css index e11289de6..c3ad5b549 100644 --- a/src/features/editors/list/List.module.css +++ b/src/features/editors/list/List.module.css @@ -20,7 +20,7 @@ left: 0; width: 100%; display: grid; - grid-template-columns: 2em 5em 1fr auto; + grid-template-columns: auto auto 5em 1fr auto; gap: 0.5em; justify-content: center; align-content: center; @@ -38,8 +38,8 @@ .arm, .armActive { - width: 20px; - height: 20px; + width: 18px; + height: 18px; border-radius: 10px; cursor: pointer; } @@ -96,6 +96,7 @@ color: #888; display: inline-block; width: 6em; + cursor: default; } .detailedTitleUnderlined { diff --git a/src/features/editors/list/listUtils.js b/src/features/editors/list/listUtils.js index 80a766c77..3df879d06 100644 --- a/src/features/editors/list/listUtils.js +++ b/src/features/editors/list/listUtils.js @@ -5,7 +5,7 @@ export const sortByDate = (arr) => { return arr.sort(sorter); }; -export const sortByNumber = (arr) => { +export const sortByOrderVal = (arr) => { const sorter = (a, b) => { return a.order - b.order; };