From a7226ec1071416d29673a30fa4c55dc3a18c659e Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Fri, 21 Feb 2020 19:03:37 +0800 Subject: [PATCH] move buttons and refactor --- src/SegmentList.jsx | 82 ++++++++++++++++++++++++++++++++++++++++++--- src/renderer.jsx | 79 +++++-------------------------------------- 2 files changed, 86 insertions(+), 75 deletions(-) diff --git a/src/SegmentList.jsx b/src/SegmentList.jsx index ca9b16d..4c06fc9 100644 --- a/src/SegmentList.jsx +++ b/src/SegmentList.jsx @@ -1,13 +1,16 @@ import React, { memo, Fragment } from 'react'; import prettyMs from 'pretty-ms'; -import { FaSave } from 'react-icons/fa'; +import { FaSave, FaPlus, FaMinus, FaTag } from 'react-icons/fa'; import { motion } from 'framer-motion'; +import Swal from 'sweetalert2'; -import { saveColor, timelineBackground } from './colors'; +import { saveColor } from './colors'; const SegmentList = memo(({ formatTimecode, cutSegments, getFrameCount, getSegColors, onSegClick, currentSegIndex, invertCutSegments, + updateCurrentSegOrder, addCutSegment, removeCutSegment, + setCurrentSegmentName, currentCutSeg, }) => { if (!cutSegments && invertCutSegments) { return
Make sure you have no overlapping segments.
; @@ -17,6 +20,42 @@ const SegmentList = memo(({ return
No segments to export.
; } + const { + segActiveBgColor: currentSegActiveBgColor, + segBorderColor: currentSegBorderColor, + } = getSegColors(currentCutSeg); + + async function onLabelSegmentPress() { + const { value } = await Swal.fire({ + showCancelButton: true, + title: 'Label current segment', + inputValue: currentCutSeg.name, + input: 'text', + }); + + if (value != null) setCurrentSegmentName(value); + } + + async function onReorderSegsPress() { + if (cutSegments.length < 2) return; + const { value } = await Swal.fire({ + title: `Change order of segment ${currentSegIndex + 1}`, + text: `Please enter a number from 1 to ${cutSegments.length} to be the new order for the current segment`, + input: 'text', + inputValue: currentSegIndex + 1, + showCancelButton: true, + inputValidator: (v) => { + const parsed = parseInt(v, 10); + return Number.isNaN(parsed) || parsed > cutSegments.length || parsed < 1 ? 'Invalid number entered' : undefined; + }, + }); + + if (value) { + const newOrder = parseInt(value, 10); + updateCurrentSegOrder(newOrder - 1); + } + } + return (
@@ -54,19 +93,54 @@ const SegmentList = memo(({ {renderNumber()} {formatTimecode(seg.start)} - {formatTimecode(seg.end)}
+
{seg.name}
Duration {prettyMs(durationMs)}
({Math.floor(durationMs)} ms, {getFrameCount(duration)} frames)
-
{seg.name}
); })} -
+
+ + + + +
+ {currentSegIndex + 1} +
+ + +
+ +
Total time:
{formatTimecode(cutSegments.reduce((acc, { start, end }) => (end - start) + acc, 0))}
diff --git a/src/renderer.jsx b/src/renderer.jsx index 02d4806..938afd0 100644 --- a/src/renderer.jsx +++ b/src/renderer.jsx @@ -1,6 +1,6 @@ import React, { memo, useEffect, useState, useCallback, useRef, Fragment, useMemo } from 'react'; import { IoIosHelpCircle, IoIosCamera } from 'react-icons/io'; -import { FaPlus, FaMinus, FaHandPointRight, FaHandPointLeft, FaTrashAlt, FaVolumeMute, FaVolumeUp, FaYinYang, FaFileExport, FaTag } from 'react-icons/fa'; +import { FaHandPointRight, FaHandPointLeft, FaTrashAlt, FaVolumeMute, FaVolumeUp, FaYinYang, FaFileExport } from 'react-icons/fa'; import { MdRotate90DegreesCcw, MdCallSplit, MdCallMerge } from 'react-icons/md'; import { FiScissors } from 'react-icons/fi'; import { AnimatePresence, motion } from 'framer-motion'; @@ -571,26 +571,6 @@ const App = memo(() => { setCutSegments(cutSegmentsNew); }, [currentSegIndexSafe, cutSegments, setCutSegments]); - async function onReorderSegsPress() { - if (cutSegments.length < 2) return; - const { value } = await Swal.fire({ - title: 'Change the order for the current segment', - text: `Please enter a number from 1 to ${cutSegments.length}`, - input: 'text', - inputValue: currentSegIndexSafe + 1, - showCancelButton: true, - inputValidator: (v) => { - const parsed = parseInt(v, 10); - return Number.isNaN(parsed) || parsed > cutSegments.length || parsed < 1 ? 'Invalid number entered' : undefined; - }, - }); - - if (value) { - const newOrder = parseInt(value, 10); - updateCurrentSegOrder(newOrder - 1); - } - } - const jumpCutStart = () => seekAbs(currentApparentCutSeg.start); const jumpCutEnd = () => seekAbs(currentApparentCutSeg.end); @@ -1445,17 +1425,6 @@ const App = memo(() => { return () => window.removeEventListener('keydown', keyScrollPreventer); }, []); - async function onLabelSegmentPress() { - const { value } = await Swal.fire({ - showCancelButton: true, - title: 'Label current segment', - inputValue: currentCutSeg.name, - input: 'text', - }); - - if (value != null) setCurrentSegmentName(value); - } - function renderSetCutpointButton(side) { const start = side === 'start'; const Icon = start ? FaHandPointLeft : FaHandPointRight; @@ -1472,10 +1441,6 @@ const App = memo(() => { } const getSegButtonStyle = ({ segActiveBgColor, segBorderColor }) => ({ background: segActiveBgColor, border: `2px solid ${segBorderColor}`, borderRadius: 6, color: 'white', fontSize: 14, textAlign: 'center', lineHeight: '11px', fontWeight: 'bold' }); - const curSegButtonStyle = getSegButtonStyle({ - segActiveBgColor: currentSegActiveBgColor, - segBorderColor: currentSegBorderColor, - }); function renderJumpCutpointButton(direction) { const newIndex = currentSegIndexSafe + direction; @@ -1683,12 +1648,17 @@ const App = memo(() => { >
@@ -1832,39 +1802,6 @@ const App = memo(() => {
{renderInvertCutButton()} - - - - -
- {currentSegIndexSafe + 1} -
- - -