diff --git a/src/page-components/pattern-editor/PulseList.module.css b/src/page-components/pattern-editor/PulseList.module.css index 8b7657e..b86a56a 100644 --- a/src/page-components/pattern-editor/PulseList.module.css +++ b/src/page-components/pattern-editor/PulseList.module.css @@ -5,14 +5,17 @@ justify-content: flex-end; align-items: center; gap: calc(var(--spacing) * 2); - } - .attribute_unit { - display: flex; - flex-direction: row; - align-items: center; - gap: calc(var(--spacing)); - label { - font-weight: bold; + .attribute_unit { + display: flex; + flex-direction: row; + align-items: center; + gap: calc(var(--spacing)); + font-size: var(--body-small-font-size); + line-height: var(--body-small-line-height); + font-weight: var(--body-small-font-weight); + label { + font-weight: 500; + } } } .pulses { diff --git a/src/page-components/pattern-editor/PulseList.tsx b/src/page-components/pattern-editor/PulseList.tsx index 51c7adb..232d0f4 100644 --- a/src/page-components/pattern-editor/PulseList.tsx +++ b/src/page-components/pattern-editor/PulseList.tsx @@ -1,39 +1,46 @@ -import { DndContext } from '@dnd-kit/core'; import { Icon } from '@iconify/react/dist/iconify.js'; -import { useAtomValue } from 'jotai'; -import { FC } from 'react'; +import { useAtom, useAtomValue } from 'jotai'; +import { max } from 'lodash-es'; +import { FC, useCallback, useMemo } from 'react'; import { ScrollArea } from '../../components/ScrollArea'; +import { addPulse, deletePulse } from '../../context/pattern-model'; import { CurrentPatternAtom, CurrentPatternDuration, - PulsesInCurrentPatternAtom, + SelectedPulseAtom, + useSavePattern, } from '../../context/Patterns'; +import PulseCard from './PulseCard'; import styles from './PulseList.module.css'; const PulseList: FC = () => { - const pattern = useAtomValue(CurrentPatternAtom); - const pulses = useAtomValue(PulsesInCurrentPatternAtom); + const [pattern, refreshPattern] = useAtom(CurrentPatternAtom); const duration = useAtomValue(CurrentPatternDuration); + const selectedPulse = useAtomValue(SelectedPulseAtom); + const maxPulseOrder = useMemo( + () => max(pattern?.pulses.map((pulse) => pulse.order) ?? []), + [pattern], + ); + const savePattern = useSavePattern(); + + const handleAddPulseAction = useCallback(async () => { + if (!pattern) return; + addPulse(pattern); + await savePattern(pattern); + refreshPattern(); + }, [pattern]); + const handleDeletePulseAction = useCallback(async () => { + if (!pattern || !selectedPulse) return; + deletePulse(pattern, selectedPulse.id); + await savePattern(pattern); + refreshPattern(); + }, [pattern, selectedPulse]); return ( <> -
- - - -
- {pulses.length ?? 0} + {pattern?.pulses.length ?? 0}
@@ -41,13 +48,43 @@ const PulseList: FC = () => { {duration.toFixed(2)} s
+
+ + + +
+
+ + +
- -
- {pulses.length === 0 &&
No key pulses.
} -
-
+
+ {pattern?.pulses.length === 0 ? ( +
No key pulses.
+ ) : ( + <> + {pattern?.pulses.map((pulse) => ( + + ))} + + )} +