// Copyright (C) 2020-2022 Intel Corporation // // SPDX-License-Identifier: MIT import React, { useState, useEffect, useCallback } from 'react'; import { Row, Col } from 'antd/lib/grid'; import Icon, { LinkOutlined, DeleteOutlined } from '@ant-design/icons'; import Slider from 'antd/lib/slider'; import InputNumber from 'antd/lib/input-number'; import Input from 'antd/lib/input'; import Text from 'antd/lib/typography/Text'; import { RestoreIcon } from 'icons'; import CVATTooltip from 'components/common/cvat-tooltip'; import { clamp } from 'utils/math'; import modal from 'antd/lib/modal'; interface Props { startFrame: number; stopFrame: number; playing: boolean; frameNumber: number; frameFilename: string; frameDeleted: boolean; deleteFrameShortcut: string; focusFrameInputShortcut: string; inputFrameRef: React.RefObject; onSliderChange(value: number): void; onInputChange(value: number): void; onURLIconClick(): void; onDeleteFrame(): void; onRestoreFrame(): void; switchNavigationBlocked(blocked: boolean): void; } function PlayerNavigation(props: Props): JSX.Element { const { startFrame, stopFrame, playing, frameNumber, frameFilename, frameDeleted, deleteFrameShortcut, focusFrameInputShortcut, inputFrameRef, onSliderChange, onInputChange, onURLIconClick, onDeleteFrame, onRestoreFrame, switchNavigationBlocked, } = props; const [frameInputValue, setFrameInputValue] = useState(frameNumber); useEffect(() => { if (frameNumber !== frameInputValue) { setFrameInputValue(frameNumber); } }, [frameNumber]); const showDeleteFrameDialog = useCallback(() => { if (!playing) { switchNavigationBlocked(true); modal.confirm({ title: `Do you want to delete frame #${frameNumber}?`, content: 'The frame will not be visible in navigation and exported datasets, but it still can be restored with all the annotations.', className: 'cvat-modal-delete-frame', okText: 'Delete', okType: 'danger', onOk: () => { switchNavigationBlocked(false); onDeleteFrame(); }, afterClose: () => { switchNavigationBlocked(false); }, }); } }, [playing, frameNumber]); return ( <> {frameFilename} { (!frameDeleted) ? ( ) : ( )} { if (typeof value !== 'undefined' && value !== null) { setFrameInputValue(Math.floor(clamp(+value, startFrame, stopFrame))); } }} onBlur={() => { onInputChange(frameInputValue); }} onPressEnter={() => { onInputChange(frameInputValue); }} /> ); } export default React.memo(PlayerNavigation);