Skip to content

Commit 9d8057b

Browse files
Mingzemergify[bot]
andauthored
fix(highlight): Reset selection when creator status changes (#612)
* fix(highlight): Reset selection when creator status changes * fix(highlight): Address comments Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 032cbe7 commit 9d8057b

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,15 @@ import { Annotation, NewAnnotation } from '../../../@types';
44
import { createAnnotationAction } from '../../annotations';
55
import { mockContainerRect, mockRange } from '../__mocks__/data';
66
import { Mode, toggleAnnotationModeAction } from '../../common';
7-
import { resetCreatorAction } from '../../creator';
7+
import { CreatorStatus, resetCreatorAction, setStatusAction } from '../../creator';
88
import { setIsPromotingAction, setSelectionAction, setIsSelectingAction } from '../actions';
99

1010
describe('store/highlight/reducer', () => {
1111
describe('setIsPromoting', () => {
12-
test.each`
13-
payload | isPromoting | selection
14-
${true} | ${true} | ${null}
15-
${false} | ${false} | ${state.selection}
16-
`('should set isPromoting and selection in state', ({ isPromoting, payload, selection }) => {
12+
test.each([true, false])('should set isPromoting in state as %s', payload => {
1713
const newState = reducer(state, setIsPromotingAction(payload));
1814

19-
expect(newState.isPromoting).toEqual(isPromoting);
20-
expect(newState.selection).toEqual(selection);
15+
expect(newState.isPromoting).toEqual(payload);
2116
});
2217
});
2318

@@ -64,4 +59,12 @@ describe('store/highlight/reducer', () => {
6459
expect(newState.isPromoting).toEqual(false);
6560
});
6661
});
62+
63+
describe('setStatusAction', () => {
64+
test('should reset selection when creator status changes', () => {
65+
const newState = reducer(state, setStatusAction(CreatorStatus.started));
66+
67+
expect(newState.selection).toEqual(null);
68+
});
69+
});
6770
});

src/store/highlight/reducer.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createReducer } from '@reduxjs/toolkit';
22
import { createAnnotationAction } from '../annotations';
33
import { HighlightState } from './types';
4-
import { resetCreatorAction } from '../creator';
4+
import { resetCreatorAction, setStatusAction } from '../creator';
55
import { setIsPromotingAction, setIsSelectingAction, setSelectionAction } from './actions';
66
import { toggleAnnotationModeAction } from '../common';
77

@@ -15,9 +15,6 @@ export default createReducer<HighlightState>(initialState, builder =>
1515
builder
1616
.addCase(setIsPromotingAction, (state, { payload }) => {
1717
state.isPromoting = payload;
18-
if (payload) {
19-
state.selection = null;
20-
}
2118
})
2219
.addCase(setIsSelectingAction, (state, { payload }) => {
2320
state.isSelecting = payload;
@@ -33,5 +30,8 @@ export default createReducer<HighlightState>(initialState, builder =>
3330
})
3431
.addCase(toggleAnnotationModeAction, state => {
3532
state.isPromoting = false;
33+
})
34+
.addCase(setStatusAction, state => {
35+
state.selection = null;
3636
}),
3737
);

0 commit comments

Comments
 (0)