From 3461a32fa9d0b039a9b845ac4034db37670646e9 Mon Sep 17 00:00:00 2001 From: cv <34649812+cpvalente@users.noreply.github.com> Date: Sat, 24 Apr 2021 21:44:53 +0200 Subject: [PATCH] refract: block type wrapper --- .../src/features/editors/list/EventList.jsx | 84 ++++++------------- .../features/editors/list/EventListItem.jsx | 40 +++++++++ 2 files changed, 64 insertions(+), 60 deletions(-) create mode 100644 client/src/features/editors/list/EventListItem.jsx diff --git a/client/src/features/editors/list/EventList.jsx b/client/src/features/editors/list/EventList.jsx index e43fa7ec2..ac80e612d 100644 --- a/client/src/features/editors/list/EventList.jsx +++ b/client/src/features/editors/list/EventList.jsx @@ -1,11 +1,10 @@ import style from './List.module.css'; -import DelayBlock from './DelayBlock'; -import BlockBlock from './BlockBlock'; -import EventBlock from './EventBlock'; + import { useEffect, useState } from 'react'; import { useSocket } from '../../../app/context/socketContext'; import tinykeys from 'tinykeys'; import Empty from '../../../common/state/Empty'; +import EventListItem from './EventListItem'; export default function EventList(props) { const { events, eventsHandler } = props; @@ -17,33 +16,30 @@ export default function EventList(props) { // Handle keyboard shortcuts useEffect(() => { let unsubscribe = tinykeys(window, { - 'Shift+ArrowDown': () => { + 'Alt+ArrowDown': () => { if (cursor == null) setCursor(0); else if (cursor < events.length - 1) setCursor(cursor + 1); }, - 'Shift+ArrowUp': () => { + 'Alt+ArrowUp': () => { if (cursor == null) setCursor(0); else if (cursor >= 0) setCursor(cursor - 1); }, - '$mod+Shift+ArrowUp': () => { - setCursor(-1); - }, - 'Shift+KeyE': (event) => { + 'Alt+KeyE': (event) => { event.preventDefault(); if (cursor == null) return; eventsHandler('add', { type: 'event', order: cursor + 1 }); }, - 'Shift+KeyD': (event) => { + 'Alt+KeyD': (event) => { event.preventDefault(); if (cursor == null) return; eventsHandler('add', { type: 'delay', order: cursor + 1 }); }, - 'Shift+KeyB': (event) => { + 'Alt+KeyB': (event) => { event.preventDefault(); if (cursor == null) return; eventsHandler('add', { type: 'block', order: cursor + 1 }); }, - 'Shift+KeyN': (event) => { + 'Alt+KeyN': (event) => { event.preventDefault(); if (cursor == null) return; if (events[cursor].type === 'event') setNext(cursor); @@ -78,61 +74,29 @@ export default function EventList(props) { } console.log('EventList: events in event list', events); - console.log('Debug: cursor', cursor); let cumulativeDelay = 0; - let eventCount = -1; - // Torbjorn: is this very dirty code? - // -- map and cumulative delay thing - // -- should i skip the order value and just use the array as order? (checkout dnd) return (
{cursor === -1 &&
} {events.map((e, index) => { - if (e.type === 'event') { - eventCount = eventCount + 1; - return ( - <> - - {index === cursor &&
} - - ); - } else if (e.type === 'block') { - cumulativeDelay = 0; - return ( - <> - - {index === cursor &&
} - - ); - } else if (e.type === 'delay') { - cumulativeDelay = cumulativeDelay + e.duration; - return ( - <> - - {index === cursor &&
} - - ); - } + if (e.type === 'delay') cumulativeDelay += e.duration; + else if (e.type === 'block') cumulativeDelay = 0; + return ( +
+ + {cursor === index &&
} +
+ ); })}
); diff --git a/client/src/features/editors/list/EventListItem.jsx b/client/src/features/editors/list/EventListItem.jsx new file mode 100644 index 000000000..2ba63a8dc --- /dev/null +++ b/client/src/features/editors/list/EventListItem.jsx @@ -0,0 +1,40 @@ +import DelayBlock from './DelayBlock'; +import BlockBlock from './BlockBlock'; +import EventBlock from './EventBlock'; + +export default function EventListItem(props) { + const { + type, + index, + data, + selected, + next, + eventsHandler, + delay, + ...rest + } = props; + + switch (type) { + case 'event': + return ( + + ); + case 'block': + return ( + + ); + case 'delay': + return ( + + ); + default: + break; + } +}