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 { AppState, BackHandler, Linking, NativeModules, TextInput, ToastAndroid } from 'react-native';
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 {
Lbryio,
doGetSync,
@ -308,8 +308,8 @@ class AppWithNavigationState extends React.Component {
getUserSettings = () => {
const { dispatch } = this.props;
Lbryio.call('user_settings', 'get').then(settings => {
dispatch(doPopulateSharedUserState(settings));
doPreferenceGet('shared', null, null, preference => {
dispatch(doPopulateSharedUserState(preference));
});
};

View file

@ -148,7 +148,11 @@ const persistor = persistStore(store, persistOptions, err => {
});
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 = {
tags: { source: 'tags', property: 'followedTags' },
subscriptions: {
@ -163,7 +167,7 @@ const sharedStateFilters = {
store.subscribe(() => {
try {
const state = store.getState();
sharedStateSubscriber(state, sharedStateFilters, sharedStateCache);
sharedStateSubscriber(state, sharedStateFilters, '0.1');
} catch (e) {
// handle gracefully?
}

View file

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