From a9e90aa9b2085aac6111cd003d47dc0ecf5aa48f Mon Sep 17 00:00:00 2001 From: Benjamin Elo Date: Wed, 17 Jul 2019 02:57:20 -0700 Subject: [PATCH] Receive navigation events and persist them Summary: After setting up the navigation event emitter on the android side, we must now receive them on the client side and persist them in the Redux store. Reviewed By: passy Differential Revision: D16280944 fbshipit-source-id: 3dc4c5c6add41388469c801700974eb0ccd9a56b --- src/plugins/navigation/index.js | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/plugins/navigation/index.js b/src/plugins/navigation/index.js index c8bad0749..dd88a153a 100644 --- a/src/plugins/navigation/index.js +++ b/src/plugins/navigation/index.js @@ -13,8 +13,13 @@ type State = {||}; type Data = {||}; +type NavigationEvent = {| + date: Date, + uri: ?String, +|}; + type PersistedState = {| - data: Array, + navigationEvents: [NavigationEvent], |}; export default class extends FlipperPlugin { @@ -24,18 +29,28 @@ export default class extends FlipperPlugin { static keyboardActions = ['clear']; static defaultPersistedState: PersistedState = { - data: [], + navigationEvents: [], }; static persistedStateReducer = ( persistedState: PersistedState, method: string, - data: Data, + payload: Object, ): $Shape => { - return { - ...persistedState, - data: persistedState.data.concat([data]), - }; + switch (method) { + case 'nav_event': + return { + ...persistedState, + navigationEvents: [ + ...persistedState.navigationEvents, + {uri: payload.uri, date: new Date()}, + ], + }; + default: + return { + ...persistedState, + }; + } }; onKeyboardAction = (action: string) => {