From 5eba4ab2ec04b7ecf60aba7271f9f99fa3dc83ff Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Mon, 30 Sep 2019 22:54:31 +0100 Subject: [PATCH 01/15] use shared state subscriber for preferences_set and preferences_get --- package-lock.json | 4 ++-- package.json | 2 +- src/index.js | 36 ++++++++++++++++++------------------ 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/package-lock.json b/package-lock.json index 57c6435..1d0eb6f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5640,8 +5640,8 @@ } }, "lbry-redux": { - "version": "github:lbryio/lbry-redux#7ec72a737bcd336f000c5f5085891643110298c3", - "from": "github:lbryio/lbry-redux#7ec72a737bcd336f000c5f5085891643110298c3", + "version": "github:lbryio/lbry-redux#23bcde0539a27fb19bf3a7d87683279194e02046", + "from": "github:lbryio/lbry-redux#23bcde0539a27fb19bf3a7d87683279194e02046", "requires": { "proxy-polyfill": "0.1.6", "reselect": "^3.0.0", diff --git a/package.json b/package.json index 40155f1..dba18fb 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "base-64": "^0.1.0", "@expo/vector-icons": "^8.1.0", "gfycat-style-urls": "^1.0.3", - "lbry-redux": "lbryio/lbry-redux#7ec72a737bcd336f000c5f5085891643110298c3", + "lbry-redux": "lbryio/lbry-redux#23bcde0539a27fb19bf3a7d87683279194e02046", "lbryinc": "lbryio/lbryinc#67bb3e215be3f13605c5e3f9f2b0e2fb880724cf", "lodash": ">=4.17.11", "merge": ">=1.2.1", diff --git a/src/index.js b/src/index.js index 4013fe2..252f85c 100644 --- a/src/index.js +++ b/src/index.js @@ -13,6 +13,7 @@ import { searchReducer, tagsReducer, walletReducer, + sharedStateSubscriber, } from 'lbry-redux'; import { Lbryio, @@ -83,7 +84,7 @@ const compressor = createCompressor(); const authFilter = createFilter('auth', ['authToken']); const contentFilter = createFilter('content', ['positions']); const saveClaimsFilter = createFilter('claims', ['claimsByUri']); -const subscriptionsFilter = createFilter('subscriptions', ['enabledChannelNotifications', 'subscriptions']); +const subscriptionsFilter = createFilter('subscriptions', ['enabledChannelNotifications', 'subscriptions', 'latest']); const settingsFilter = createFilter('settings', ['clientSettings']); const tagsFilter = createFilter('tags', ['followedTags']); const walletFilter = createFilter('wallet', ['receiveAddress']); @@ -147,25 +148,24 @@ const persistor = persistStore(store, persistOptions, err => { }); window.persistor = persistor; -let currentPayload; -store.subscribe(() => { - const state = store.getState(); - const subscriptions = state.subscriptions.subscriptions.map(({ uri }) => uri); - const tags = state.tags.followedTags; - - const newPayload = { - version: '0.1', - shared: { - subscriptions, - tags, +const sharedStateCache = {}; +const sharedStateFilters = { + tags: { source: 'tags', property: 'followedTags' }, + subscriptions: { + source: 'subscriptions', + property: 'subscriptions', + transform: function(value) { + return value.map(({ uri }) => uri); }, - }; + }, +}; - if (!isEqual(newPayload, currentPayload)) { - currentPayload = newPayload; - if (Lbryio.authToken) { - Lbryio.call('user_settings', 'set', { settings: JSON.stringify(newPayload) }); - } +store.subscribe(() => { + try { + const state = store.getState(); + sharedStateSubscriber(state, sharedStateFilters, sharedStateCache); + } catch (e) { + // handle gracefully? } }); -- 2.45.2 From f42cbb90a063eec91f0ccb2489a67703b3a8be42 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Wed, 2 Oct 2019 10:29:08 +0100 Subject: [PATCH 02/15] use doPreferenceGet for retrieving saved user state --- src/component/AppNavigator.js | 6 +++--- src/index.js | 8 ++++++-- src/page/splash/view.js | 7 ++++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/component/AppNavigator.js b/src/component/AppNavigator.js index a5fb642..2d68083 100644 --- a/src/component/AppNavigator.js +++ b/src/component/AppNavigator.js @@ -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)); }); }; diff --git a/src/index.js b/src/index.js index 252f85c..cea3631 100644 --- a/src/index.js +++ b/src/index.js @@ -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? } diff --git a/src/page/splash/view.js b/src/page/splash/view.js index 2a2a5c6..3eecfdc 100644 --- a/src/page/splash/view.js +++ b/src/page/splash/view.js @@ -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); }); }; -- 2.45.2 From 03b321c742c7c0671ffdff366391c9c23c109258 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Fri, 11 Oct 2019 15:10:54 +0100 Subject: [PATCH 03/15] add share button --- src/page/file/view.js | 37 +++++++++++++++++++++++++++++++------ src/styles/filePage.js | 18 ++++++++++++++++++ 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/src/page/file/view.js b/src/page/file/view.js index 5600e8a..c6ccdd3 100644 --- a/src/page/file/view.js +++ b/src/page/file/view.js @@ -508,6 +508,20 @@ class FilePage extends React.PureComponent { this.setState({ fileViewLogged: true }); }; + // TODO: Move this to lbry-redux + formatLbryUrlForWeb = url => { + return url.replace('lbry://', '/').replace(/#/g, ':'); + }; + + handleSharePress = () => { + const { claim, notify } = this.props; + if (claim) { + const { canonical_url: canonicalUrl, short_url: shortUrl, permanent_url: permanentUrl } = claim; + const url = 'https://beta.lbry.tv/' + this.formatLbryUrlForWeb(canonicalUrl || (shortUrl || permanentUrl)); + NativeModules.UtilityModule.shareUrl(url); + } + }; + handleSendTip = () => { const { claim, balance, navigation, notify, sendTip } = this.props; const { uri } = navigation.state.params; @@ -933,6 +947,22 @@ class FilePage extends React.PureComponent { + + + + + Share + + + Linking.openURL(`https://lbry.com/dmca/${claim.claim_id}`)} + > + + Report + + + {channelName && ( @@ -969,12 +999,7 @@ class FilePage extends React.PureComponent { onPress={this.onSaveFilePressed} /> )} -