Skip to content

Commit 030155a

Browse files
author
Adriána Kohanová
committed
#485 Put tooltips on undo/redo buttons that show the action being undone/redone
1 parent 14e0a1f commit 030155a

File tree

5 files changed

+34
-4
lines changed

5 files changed

+34
-4
lines changed

js/components/preview/viewerControls/index.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44

55
import React, { memo, useState, useContext, useEffect, useCallback } from 'react';
6-
import { useDispatch } from 'react-redux';
6+
import { useDispatch, useSelector } from 'react-redux';
77
import { Button } from '../../common/Inputs/Button';
88
import { Settings, Mouse, PersonalVideo, Undo, Redo } from '@material-ui/icons';
99
import { ButtonGroup, Grid, makeStyles, Tooltip } from '@material-ui/core';
@@ -44,6 +44,7 @@ export const ViewerControls = memo(({}) => {
4444
const [redoTooltip, setRedoTooltip] = useState('Redo');
4545
const [canUndo, setCanUndo] = useState(true);
4646
const [canRedo, setCanRedo] = useState(false);
47+
const isActionTracking = useSelector(state => state.trackingReducers.isActionTracking);
4748

4849
const openDrawer = key => {
4950
//close all and open selected by key
@@ -85,12 +86,16 @@ export const ViewerControls = memo(({}) => {
8586
});
8687

8788
useEffect(() => {
89+
if (isActionTracking === false) {
90+
setUndoTooltip(dispatch(getUndoActionText()));
91+
setRedoTooltip(dispatch(getRedoActionText()));
92+
}
8893
window.addEventListener('keydown', handleUserKeyPress);
8994

9095
return () => {
9196
window.removeEventListener('keydown', handleUserKeyPress);
9297
};
93-
}, [handleUserKeyPress]);
98+
}, [handleUserKeyPress, dispatch, isActionTracking]);
9499

95100
return (
96101
<>

js/reducers/tracking/actions.js

+7
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ export const setIsActionsRestoring = function(isActionRestoring, isActionRestore
106106
};
107107
};
108108

109+
export const setIsActionTracking = function(isActionTracking) {
110+
return {
111+
type: constants.SET_IS_ACTION_TRACKING,
112+
isActionTracking: isActionTracking
113+
};
114+
};
115+
109116
export const resetTrackingState = function() {
110117
return {
111118
type: constants.RESET_TRACKING_STATE

js/reducers/tracking/constants.js

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const constants = {
1515
SET_PROJECT_ACTIONS_LIST: prefix + 'SET_PROJECT_ACTIONS_LIST',
1616
SET_IS_ACTIONS_SAVING: prefix + 'SET_IS_ACTIONS_SAVING',
1717
SET_IS_ACTIONS_RESTORING: prefix + 'SET_IS_ACTIONS_RESTORING',
18+
SET_IS_ACTION_TRACKING: prefix + 'SET_IS_ACTION_TRACKING',
1819
RESET_TRACKING_STATE: prefix + 'RESET_TRACKING_STATE',
1920
SET_TRACKING_IMAGE_SOURCE: prefix + 'SET_TRACKING_IMAGE_SOURCE',
2021
SET_SNAPSOT_IMAGE_ACTIONS_LIST: prefix + 'SET_SNAPSOT_IMAGE_ACTIONS_LIST'

js/reducers/tracking/dispatchActions.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ import {
7979
setIsActionsSaving,
8080
setIsActionsRestoring,
8181
appendToUndoRedoActionList,
82-
resetTrackingState
82+
resetTrackingState,
83+
setIsActionTracking
8384
} from './actions';
8485
import {
8586
setSelectedAll,
@@ -1146,7 +1147,17 @@ const getNextUndoAction = () => (dispatch, getState) => {
11461147

11471148
const getNextRedoAction = () => (dispatch, getState) => {
11481149
const state = getState();
1150+
const actionUndoList = state.undoableTrackingReducers.future;
1151+
11491152
let action = { text: '' };
1153+
let actionss = actionUndoList && actionUndoList[0];
1154+
1155+
let actions = actionss && actionss.undo_redo_actions_list;
1156+
if (actions) {
1157+
let actionsLenght = actions.length;
1158+
actionsLenght = actionsLenght > 0 ? actionsLenght - 1 : actionsLenght;
1159+
action = actions[actionsLenght];
1160+
}
11501161

11511162
return action;
11521163
};
@@ -1755,6 +1766,7 @@ export const getRedoActionText = () => (dispatch, getState) => {
17551766
export const appendAndSendTrackingActions = trackAction => (dispatch, getState) => {
17561767
const state = getState();
17571768
const isUndoRedoAction = state.trackingReducers.isUndoRedoAction;
1769+
dispatch(setIsActionTracking(true));
17581770

17591771
if (trackAction && trackAction !== null) {
17601772
dispatch(appendToActionList(trackAction, isUndoRedoAction));
@@ -1764,7 +1776,7 @@ export const appendAndSendTrackingActions = trackAction => (dispatch, getState)
17641776
dispatch(appendToUndoRedoActionList(trackAction));
17651777
}
17661778
}
1767-
1779+
dispatch(setIsActionTracking(false));
17681780
dispatch(checkSendTrackingActions());
17691781
};
17701782

js/reducers/tracking/trackingReducers.js

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const INITIAL_STATE = {
1616
snapshotActionImageList: [],
1717
isActionRestoring: false,
1818
isActionRestored: false,
19+
isActionTracking: false,
1920
trackingImageSource: ''
2021
};
2122

@@ -96,6 +97,10 @@ export function trackingReducers(state = INITIAL_STATE, action = {}) {
9697
isActionRestoring: action.isActionRestoring,
9798
isActionRestored: action.isActionRestored
9899
});
100+
case constants.SET_IS_ACTION_TRACKING:
101+
return Object.assign({}, state, {
102+
isActionTracking: action.isActionTracking
103+
});
99104

100105
case constants.SET_TRACKING_IMAGE_SOURCE:
101106
return Object.assign({}, state, {

0 commit comments

Comments
 (0)