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

[RNMobile] Simplify media insertion flow Part 1 - redux changes #29546

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
6742b75
created actions for adding and clearing last inserted block event.
jd-alexander Mar 4, 2021
fc8d9b4
added reducer for determining new state based on the action
jd-alexander Mar 4, 2021
fb115ae
added selector to query the state for the last block inserted
jd-alexander Mar 4, 2021
e3fefb6
Merge branch 'trunk' into rnmobile/simplify_image_insertion_flow-redu…
jd-alexander Mar 16, 2021
ee4d502
[RNMobile] Simplify media insertion flow Part 2 - media upload (#29547)
jd-alexander Mar 16, 2021
cb31236
Added release notes for auto-opening.
jd-alexander Mar 17, 2021
3aa051f
Merge branch 'trunk' into rnmobile/simplify_image_insertion_flow-redu…
jd-alexander Mar 17, 2021
b12215f
Merge branch 'trunk' into rnmobile/simplify_image_insertion_flow-redu…
jd-alexander Mar 19, 2021
d865c2b
[RNMobile] Refactor simplify media flow redux store changes (#30123)
jd-alexander Mar 31, 2021
3654e91
Merge branch 'trunk' into rnmobile/simplify_image_insertion_flow-redu…
jd-alexander Mar 31, 2021
4135172
added wasBlockJustInserted prop needed after merge with trunk.
jd-alexander Mar 31, 2021
92ee6f0
Merge branch 'trunk' into rnmobile/simplify_image_insertion_flow-redu…
jd-alexander Apr 7, 2021
d22738f
Merge branch 'trunk' into rnmobile/simplify_image_insertion_flow-redu…
jd-alexander Apr 19, 2021
bb98f4c
removed updateSelection from reducer so it's updated at all times.
jd-alexander Apr 19, 2021
1941ae8
Merge branch 'trunk' into rnmobile/simplify_image_insertion_flow-redu…
jd-alexander Apr 20, 2021
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
25 changes: 25 additions & 0 deletions packages/editor/src/store/actions.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,28 @@ export function togglePostTitleSelection( isSelected = true ) {
export function* autosave() {
RNReactNativeGutenbergBridge.editorDidAutosave();
}

/**
* Returns an action object to track the last block that was inserted.
*
* @param {Object} clientId The client id of the block.
*
* @return {Object} Action object.
*/
export function addLastBlockInserted( clientId ) {
return {
type: 'ADD_LAST_BLOCK_INSERTED',
clientId,
};
}

/**
* Returns an action object to clear the last block that was inserted.
*
* @return {Object} Action object.
*/
export function clearLastBlockInserted() {
return {
type: 'CLEAR_LAST_BLOCK_INSERTED',
};
}
20 changes: 20 additions & 0 deletions packages/editor/src/store/reducer.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,25 @@ export function notices( state = [], action ) {
return state;
}

/**
* Reducer returning the block insertion event list state.
*
* @param {Object} state Current state.
* @param {Object} action Dispatched action.
*
* @return {Object} Updated state.
*/
export function lastBlockInserted( state = {}, action ) {
switch ( action.type ) {
case 'ADD_LAST_BLOCK_INSERTED':
return { ...state, clientId: action.clientId };

case 'CLEAR_LAST_BLOCK_INSERTED':
return {};
}
return state;
}
jd-alexander marked this conversation as resolved.
Show resolved Hide resolved

export default combineReducers( {
postId,
postType,
Expand All @@ -93,4 +112,5 @@ export default combineReducers( {
editorSettings,
clipboard,
notices,
lastBlockInserted,
} );
11 changes: 11 additions & 0 deletions packages/editor/src/store/selectors.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,14 @@ export const isEditedPostAutosaveable = createRegistrySelector(
return false;
}
);

/**
* Tells if the block with the passed clientId was just inserted.
*
* @param {Object} state Global application state.
* @param {Object} clientId client id of the block.
* @return {boolean} If the client id exists within the lastBlockInserted state then the block was just inserted.
*/
export function wasBlockJustInserted( state, clientId ) {
return state.lastBlockInserted.clientId === clientId;
}
28 changes: 26 additions & 2 deletions packages/editor/src/store/test/actions.native.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
/**
* Internal dependencies
*/
import { togglePostTitleSelection } from '../actions';
import {
togglePostTitleSelection,
addLastBlockInserted,
clearLastBlockInserted,
} from '../actions';

describe( 'Editor actions', () => {
describe( 'actions native', () => {
describe( 'togglePostTitleSelection', () => {
it( 'should return the TOGGLE_POST_TITLE_SELECTION action', () => {
const result = togglePostTitleSelection( true );
Expand All @@ -13,4 +17,24 @@ describe( 'Editor actions', () => {
} );
} );
} );

describe( 'addLastBlockInserted', () => {
it( 'should return the ADD_LAST_BLOCK_INSERTED action', () => {
const expectedClientId = 1;
const result = addLastBlockInserted( expectedClientId );
expect( result ).toEqual( {
type: 'ADD_LAST_BLOCK_INSERTED',
clientId: expectedClientId,
} );
} );
} );

describe( 'clearLastBlockInserted', () => {
it( 'should return the CLEAR_LAST_BLOCK_INSERTED action', () => {
const result = clearLastBlockInserted();
expect( result ).toEqual( {
type: 'CLEAR_LAST_BLOCK_INSERTED',
} );
} );
} );
} );
25 changes: 24 additions & 1 deletion packages/editor/src/store/test/reducer.native.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Internal dependencies
*/
import { postTitle } from '../reducer';
import { postTitle, lastBlockInserted } from '../reducer';

describe( 'state native', () => {
describe( 'postTitle', () => {
Expand Down Expand Up @@ -32,5 +32,28 @@ describe( 'state native', () => {
).toBe( true );
} );
} );

describe( 'lastBlockInserted()', () => {
it( 'should return client id of last block inserted', () => {
const expectedClientId = 1;
const action = {
type: 'ADD_LAST_BLOCK_INSERTED',
clientId: expectedClientId,
};

expect(
lastBlockInserted( { clientId: expectedClientId }, action )
.clientId
).toBe( expectedClientId );
} );

it( 'should return empty state if last block has been cleared', () => {
const action = {
type: 'CLEAR_LAST_BLOCK_INSERTED',
};

expect( lastBlockInserted( {}, action ) ).toStrictEqual( {} );
} );
} );
} );
} );
31 changes: 30 additions & 1 deletion packages/editor/src/store/test/selectors.native.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Internal dependencies
*/
import { isPostTitleSelected } from '../selectors';
import { isPostTitleSelected, wasBlockJustInserted } from '../selectors';

describe( 'selectors native', () => {
describe( 'isPostTitleSelected', () => {
Expand All @@ -25,4 +25,33 @@ describe( 'selectors native', () => {
expect( isPostTitleSelected( state ) ).toBe( false );
} );
} );

describe( 'wasBlockJustInserted', () => {
it( 'should return true if the client id passed to wasBlockJustInserted is found within the state', () => {
const expectedClientId = 1;
const state = {
lastBlockInserted: {
clientId: expectedClientId,
},
};

expect( wasBlockJustInserted( state, expectedClientId ) ).toBe(
true
);
} );

it( 'should return false if the client id passed to wasBlockJustInserted is not found within the state', () => {
const expectedClientId = 1;
const unexpectedClientId = 0;
const state = {
lastBlockInserted: {
clientId: unexpectedClientId,
},
};

expect( wasBlockJustInserted( state, expectedClientId ) ).toBe(
false
);
} );
} );
} );