Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove all segments button #1097

Merged
merged 8 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/i18n/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
"delete-button": "Delete",
"delete-restore-tooltip": "Mark or unmark the segment at the current position as to be deleted. Hotkey: {{hotkeyName}}",
"delete-restore-tooltip-aria": "Delete and Restore. Mark or unmark the segment at the current position as to be deleted. Hotkey: {{hotKeyName}}.",
"merge-all-button": "Merge All",
"merge-all-tooltip": "Combine all segments into a single segment.",
"merge-all-tooltip-aria": "Merge All. Combine all segments into a single segment.",
"restore-button": "Restore",
"mergeLeft-button": "Merge Left",
"mergeLeft-tooltip": "Combine the currently active segment with the segment to its left. Hotkey: {{hotkeyName}}",
Expand Down
10 changes: 8 additions & 2 deletions src/main/CuttingActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import React, { SyntheticEvent } from "react";
import { basicButtonStyle, customIconStyle } from '../cssStyles'

import { IconType } from "react-icons";
import { LuScissors, LuChevronLeft, LuChevronRight, LuTrash} from "react-icons/lu";
import { LuScissors, LuChevronLeft, LuChevronRight, LuTrash, LuMoveHorizontal} from "react-icons/lu";
import { ReactComponent as TrashRestore } from '../img/trash-restore.svg';

import { css } from '@emotion/react'

import { useDispatch, useSelector } from 'react-redux';
import {
cut, markAsDeletedOrAlive, selectIsCurrentSegmentAlive, mergeLeft, mergeRight
cut, markAsDeletedOrAlive, selectIsCurrentSegmentAlive, mergeLeft, mergeRight, mergeAll
} from '../redux/videoSlice'
import { GlobalHotKeys, KeySequence, KeyMapOptions } from "react-hotkeys";
import { cuttingKeyMap } from "../globalKeys";
Expand Down Expand Up @@ -91,6 +91,12 @@ const CuttingActions: React.FC = () => {
tooltip={t('cuttingActions.mergeRight-tooltip', { hotkeyName: (cuttingKeyMap[handlers.mergeRight.name] as KeyMapOptions).sequence })}
ariaLabelText={t('cuttingActions.mergeRight-tooltip-aria', { hotkeyName: (cuttingKeyMap[handlers.mergeRight.name] as KeyMapOptions).sequence })}
/>
<div css={verticalLineStyle} />
<CuttingActionsButton Icon={LuMoveHorizontal}
actionName={t("cuttingActions.merge-all-button")} actionHandler={dispatchAction} action={mergeAll}
tooltip={t('cuttingActions.merge-all-tooltip')}
ariaLabelText={t('cuttingActions.merge-all-tooltip-aria')}
/>
{/* <CuttingActionsButton Icon={faQuestion} actionName="Reset changes" action={null}
tooltip="Not implemented"
ariaLabelText="Reset changes. Not implemented"
Expand Down
28 changes: 18 additions & 10 deletions src/redux/videoSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ const videoSlice = createSlice({
mergeSegments(state, state.activeSegmentIndex, state.activeSegmentIndex + 1)
state.hasChanges = true
},
mergeAll: state => {
mergeSegments(state, state.activeSegmentIndex, 0)
mergeSegments(state, state.activeSegmentIndex, state.segments.length - 1)
state.hasChanges = true
},
},
// For Async Requests
extraReducers: builder => {
Expand Down Expand Up @@ -258,22 +263,25 @@ export const parseSegments = (segments: Segment[], duration: number) => {
}

/**
* Helper function for merging two segments
* Helper function for merging segments
*/
const mergeSegments = (state: video, activeSegmentIndex: number, mergeSegmentIndex: number) => {
const mergeSegments = (state: video, startSegmentIndex: number, endSegmentIndex: number) => {
// Check if mergeSegmentIndex is valid
if (mergeSegmentIndex < 0 || mergeSegmentIndex > state.segments.length - 1) {
if (endSegmentIndex < 0 || endSegmentIndex > state.segments.length - 1) {
return
}

// Increase activeSegment length
state.segments[activeSegmentIndex].start = Math.min(
state.segments[activeSegmentIndex].start, state.segments[mergeSegmentIndex].start)
state.segments[activeSegmentIndex].end = Math.max(
state.segments[activeSegmentIndex].end, state.segments[mergeSegmentIndex].end)
state.segments[startSegmentIndex].start = Math.min(
state.segments[startSegmentIndex].start, state.segments[endSegmentIndex].start)
state.segments[startSegmentIndex].end = Math.max(
state.segments[startSegmentIndex].end, state.segments[endSegmentIndex].end)

// Remove the other segment
state.segments.splice(mergeSegmentIndex, 1);
// Remove the end segment and segments between
state.segments.splice(
startSegmentIndex < endSegmentIndex ? startSegmentIndex + 1 : endSegmentIndex,
Math.abs(endSegmentIndex - startSegmentIndex)
);

// Update active segment
updateActiveSegment(state)
Expand Down Expand Up @@ -336,7 +344,7 @@ const setThumbnailHelper = (state: video, id: Track["id"], uri: Track["thumbnail

export const { setTrackEnabled, setIsPlaying, setIsPlayPreview, setCurrentlyAt, setCurrentlyAtInSeconds,
addSegment, setAspectRatio, setHasChanges, setWaveformImages, setThumbnails, setThumbnail, removeThumbnail,
cut, markAsDeletedOrAlive, setSelectedWorkflowIndex, mergeLeft, mergeRight, setPreviewTriggered,
cut, markAsDeletedOrAlive, setSelectedWorkflowIndex, mergeLeft, mergeRight, mergeAll, setPreviewTriggered,
setClickTriggered } = videoSlice.actions

// Export selectors
Expand Down
Loading