use doPreferenceGet for retrieving saved user state

This commit is contained in:
Akinwale Ariwodola 2019-10-02 10:29:08 +01:00
parent 5eba4ab2ec
commit f42cbb90a0
3 changed files with 13 additions and 8 deletions

View file

@ -29,7 +29,7 @@ import {
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { AppState, BackHandler, Linking, NativeModules, TextInput, ToastAndroid } from 'react-native'; import { AppState, BackHandler, Linking, NativeModules, TextInput, ToastAndroid } from 'react-native';
import { selectDrawerStack } from 'redux/selectors/drawer'; import { selectDrawerStack } from 'redux/selectors/drawer';
import { SETTINGS, doDismissToast, doPopulateSharedUserState, doToast, selectToast } from 'lbry-redux'; import { SETTINGS, doDismissToast, doPopulateSharedUserState, doPreferenceGet, doToast, selectToast } from 'lbry-redux';
import { import {
Lbryio, Lbryio,
doGetSync, doGetSync,
@ -308,8 +308,8 @@ class AppWithNavigationState extends React.Component {
getUserSettings = () => { getUserSettings = () => {
const { dispatch } = this.props; const { dispatch } = this.props;
Lbryio.call('user_settings', 'get').then(settings => { doPreferenceGet('shared', null, null, preference => {
dispatch(doPopulateSharedUserState(settings)); dispatch(doPopulateSharedUserState(preference));
}); });
}; };

View file

@ -148,7 +148,11 @@ const persistor = persistStore(store, persistOptions, err => {
}); });
window.persistor = persistor; window.persistor = persistor;
const sharedStateCache = {}; /**
* source: the reducer name
* property: the property in the reducer-specific state
* transform: optional method to modify the value to be stored
*/
const sharedStateFilters = { const sharedStateFilters = {
tags: { source: 'tags', property: 'followedTags' }, tags: { source: 'tags', property: 'followedTags' },
subscriptions: { subscriptions: {
@ -163,7 +167,7 @@ const sharedStateFilters = {
store.subscribe(() => { store.subscribe(() => {
try { try {
const state = store.getState(); const state = store.getState();
sharedStateSubscriber(state, sharedStateFilters, sharedStateCache); sharedStateSubscriber(state, sharedStateFilters, '0.1');
} catch (e) { } catch (e) {
// handle gracefully? // handle gracefully?
} }

View file

@ -1,5 +1,5 @@
import React from 'react'; import React from 'react';
import { Lbry } from 'lbry-redux'; import { Lbry, doPreferenceGet } from 'lbry-redux';
import { Lbryio } from 'lbryinc'; import { Lbryio } from 'lbryinc';
import { ActivityIndicator, Linking, NativeModules, Platform, Text, View } from 'react-native'; import { ActivityIndicator, Linking, NativeModules, Platform, Text, View } from 'react-native';
import { NavigationActions, StackActions } from 'react-navigation'; import { NavigationActions, StackActions } from 'react-navigation';
@ -113,8 +113,9 @@ class SplashScreen extends React.PureComponent {
getUserSettings = () => { getUserSettings = () => {
const { populateSharedUserState } = this.props; const { populateSharedUserState } = this.props;
Lbryio.call('user_settings', 'get').then(settings => {
populateSharedUserState(settings); doPreferenceGet('shared', null, null, preference => {
populateSharedUserState(preference);
}); });
}; };