Skip to content

Commit a4122b6

Browse files
Mingzemergify[bot]
andauthored
feat(highlight): Reset isPromoting when toggle mode (#581)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent f63df92 commit a4122b6

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/store/highlight/__tests__/reducer-test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import state from '../__mocks__/highlightState';
33
import { Annotation, NewAnnotation } from '../../../@types';
44
import { createAnnotationAction } from '../../annotations';
55
import { mockContainerRect, mockRange } from '../__mocks__/data';
6+
import { Mode, toggleAnnotationModeAction } from '../../common';
67
import { resetCreatorAction } from '../../creator';
78
import { setIsPromotingAction, setSelectionAction, setIsSelectingAction } from '../actions';
89

@@ -55,4 +56,12 @@ describe('store/highlight/reducer', () => {
5556
expect(newState.isPromoting).toEqual(false);
5657
});
5758
});
59+
60+
describe('toggleAnnotationMode', () => {
61+
test('should reset isPromoting when toggle mode', () => {
62+
const newState = reducer({ ...state, isPromoting: true }, toggleAnnotationModeAction(Mode.HIGHLIGHT));
63+
64+
expect(newState.isPromoting).toEqual(false);
65+
});
66+
});
5867
});

src/store/highlight/reducer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { createAnnotationAction } from '../annotations';
33
import { HighlightState } from './types';
44
import { resetCreatorAction } from '../creator';
55
import { setIsPromotingAction, setIsSelectingAction, setSelectionAction } from './actions';
6+
import { toggleAnnotationModeAction } from '../common';
67

78
export const initialState = {
89
isPromoting: false,
@@ -29,5 +30,8 @@ export default createReducer<HighlightState>(initialState, builder =>
2930
})
3031
.addCase(resetCreatorAction, state => {
3132
state.isPromoting = false;
33+
})
34+
.addCase(toggleAnnotationModeAction, state => {
35+
state.isPromoting = false;
3236
}),
3337
);

0 commit comments

Comments
 (0)