From 5074b368eef83e2dbb02236c7776f97f17b1806a Mon Sep 17 00:00:00 2001 From: 6ea86b96 <6ea86b96@gmail.com> Date: Fri, 16 Jun 2017 09:48:55 +0700 Subject: [PATCH 1/3] Fix loading state on file card and uri indicator when claim is already available --- ui/js/component/fileCard/view.jsx | 6 ++---- ui/js/component/uriIndicator/view.jsx | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/ui/js/component/fileCard/view.jsx b/ui/js/component/fileCard/view.jsx index 70b8e8132..0cd9d7376 100644 --- a/ui/js/component/fileCard/view.jsx +++ b/ui/js/component/fileCard/view.jsx @@ -47,13 +47,11 @@ class FileCard extends React.PureComponent { const { claim, fileInfo, metadata, isResolvingUri, navigate } = this.props; const uri = lbryuri.normalize(this.props.uri); - const title = !isResolvingUri && metadata && metadata.title - ? metadata.title - : uri; + const title = metadata && metadata.title ? metadata.title : uri; const obscureNsfw = this.props.obscureNsfw && metadata && metadata.nsfw; let description = ""; - if (isResolvingUri) { + if (isResolvingUri && !claim) { description = __("Loading..."); } else if (metadata && metadata.description) { description = metadata.description; diff --git a/ui/js/component/uriIndicator/view.jsx b/ui/js/component/uriIndicator/view.jsx index 92db16629..b69abd591 100644 --- a/ui/js/component/uriIndicator/view.jsx +++ b/ui/js/component/uriIndicator/view.jsx @@ -21,7 +21,7 @@ class UriIndicator extends React.PureComponent { render() { const { claim, uri, isResolvingUri } = this.props; - if (isResolvingUri) { + if (isResolvingUri && !claim) { return Validating...; } From 5595b5b5b2fc34ff95e8f94009337c44c1985afa Mon Sep 17 00:00:00 2001 From: 6ea86b96 <6ea86b96@gmail.com> Date: Fri, 16 Jun 2017 09:51:02 +0700 Subject: [PATCH 2/3] Remove doCancelResolveUri, it deletes claims from the store --- ui/js/actions/content.js | 10 ---------- ui/js/component/fileCard/index.js | 3 +-- ui/js/component/fileCard/view.jsx | 8 -------- ui/js/constants/action_types.js | 1 - ui/js/reducers/claims.js | 9 --------- 5 files changed, 1 insertion(+), 30 deletions(-) diff --git a/ui/js/actions/content.js b/ui/js/actions/content.js index 0d26947fe..652f1ca22 100644 --- a/ui/js/actions/content.js +++ b/ui/js/actions/content.js @@ -44,16 +44,6 @@ export function doResolveUri(uri) { }; } -export function doCancelResolveUri(uri) { - return function(dispatch, getState) { - lbry.cancelResolve({ uri }); - dispatch({ - type: types.RESOLVE_URI_CANCELED, - data: { uri }, - }); - }; -} - export function doFetchFeaturedUris() { return function(dispatch, getState) { const state = getState(); diff --git a/ui/js/component/fileCard/index.js b/ui/js/component/fileCard/index.js index dcf1aad5c..a3c699998 100644 --- a/ui/js/component/fileCard/index.js +++ b/ui/js/component/fileCard/index.js @@ -1,7 +1,7 @@ import React from "react"; import { connect } from "react-redux"; import { doNavigate } from "actions/app"; -import { doResolveUri, doCancelResolveUri } from "actions/content"; +import { doResolveUri } from "actions/content"; import { selectObscureNsfw } from "selectors/app"; import { makeSelectClaimForUri, @@ -31,7 +31,6 @@ const makeSelect = () => { const perform = dispatch => ({ navigate: (path, params) => dispatch(doNavigate(path, params)), resolveUri: uri => dispatch(doResolveUri(uri)), - cancelResolveUri: uri => dispatch(doCancelResolveUri(uri)), }); export default connect(makeSelect, perform)(FileCard); diff --git a/ui/js/component/fileCard/view.jsx b/ui/js/component/fileCard/view.jsx index 0cd9d7376..bf0901035 100644 --- a/ui/js/component/fileCard/view.jsx +++ b/ui/js/component/fileCard/view.jsx @@ -23,14 +23,6 @@ class FileCard extends React.PureComponent { } } - componentWillUnmount() { - const { isResolvingUri, cancelResolveUri, uri } = this.props; - - if (isResolvingUri) { - cancelResolveUri(uri); - } - } - handleMouseOver() { this.setState({ hovered: true, diff --git a/ui/js/constants/action_types.js b/ui/js/constants/action_types.js index 3450c1c1a..e5432b1fb 100644 --- a/ui/js/constants/action_types.js +++ b/ui/js/constants/action_types.js @@ -39,7 +39,6 @@ export const FETCH_FEATURED_CONTENT_COMPLETED = "FETCH_FEATURED_CONTENT_COMPLETED"; export const RESOLVE_URI_STARTED = "RESOLVE_URI_STARTED"; export const RESOLVE_URI_COMPLETED = "RESOLVE_URI_COMPLETED"; -export const RESOLVE_URI_CANCELED = "RESOLVE_URI_CANCELED"; export const FETCH_CHANNEL_CLAIMS_STARTED = "FETCH_CHANNEL_CLAIMS_STARTED"; export const FETCH_CHANNEL_CLAIMS_COMPLETED = "FETCH_CHANNEL_CLAIMS_COMPLETED"; export const FETCH_CLAIM_LIST_MINE_STARTED = "FETCH_CLAIM_LIST_MINE_STARTED"; diff --git a/ui/js/reducers/claims.js b/ui/js/reducers/claims.js index 9cfa92bcb..a237947b6 100644 --- a/ui/js/reducers/claims.js +++ b/ui/js/reducers/claims.js @@ -26,15 +26,6 @@ reducers[types.RESOLVE_URI_COMPLETED] = function(state, action) { }); }; -reducers[types.RESOLVE_URI_CANCELED] = function(state, action) { - const uri = action.data.uri; - const newClaims = Object.assign({}, state.claimsByUri); - delete newClaims[uri]; - return Object.assign({}, state, { - claimsByUri: newClaims, - }); -}; - reducers[types.FETCH_CLAIM_LIST_MINE_STARTED] = function(state, action) { return Object.assign({}, state, { isClaimListMinePending: true, From cf532b4e98e95c7219e889a88a332ab691e82cc7 Mon Sep 17 00:00:00 2001 From: 6ea86b96 <6ea86b96@gmail.com> Date: Fri, 16 Jun 2017 12:43:43 +0700 Subject: [PATCH 3/3] Add a way for users to clear their own cache --- ui/js/actions/app.js | 8 ++++++++ ui/js/page/settings/index.js | 2 ++ ui/js/page/settings/view.jsx | 38 ++++++++++++++++++++++++++++++++++++ ui/js/store.js | 2 +- 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/ui/js/actions/app.js b/ui/js/actions/app.js index 8609e1e3d..d82c51606 100644 --- a/ui/js/actions/app.js +++ b/ui/js/actions/app.js @@ -243,3 +243,11 @@ export function doRemoveSnackBarSnack() { type: types.REMOVE_SNACKBAR_SNACK, }; } + +export function doClearCache() { + return function(dispatch, getState) { + window.cacheStore.purge(); + + return Promise.resolve(); + }; +} diff --git a/ui/js/page/settings/index.js b/ui/js/page/settings/index.js index 6b6096451..96fd8aec1 100644 --- a/ui/js/page/settings/index.js +++ b/ui/js/page/settings/index.js @@ -1,5 +1,6 @@ import React from "react"; import { connect } from "react-redux"; +import { doClearCache } from "actions/app"; import { doSetDaemonSetting } from "actions/settings"; import { selectDaemonSettings } from "selectors/settings"; import SettingsPage from "./view"; @@ -10,6 +11,7 @@ const select = state => ({ const perform = dispatch => ({ setDaemonSetting: (key, value) => dispatch(doSetDaemonSetting(key, value)), + clearCache: () => dispatch(doClearCache()), }); export default connect(select, perform)(SettingsPage); diff --git a/ui/js/page/settings/view.jsx b/ui/js/page/settings/view.jsx index e7987d1ac..9a7d15f6c 100644 --- a/ui/js/page/settings/view.jsx +++ b/ui/js/page/settings/view.jsx @@ -2,6 +2,9 @@ import React from "react"; import { FormField, FormRow } from "component/form.js"; import SubHeader from "component/subHeader"; import lbry from "lbry.js"; +import Link from "component/link"; + +const { remote } = require("electron"); class SettingsPage extends React.PureComponent { constructor(props) { @@ -15,9 +18,23 @@ class SettingsPage extends React.PureComponent { showNsfw: lbry.getClientSetting("showNsfw"), showUnavailable: lbry.getClientSetting("showUnavailable"), language: lbry.getClientSetting("language"), + clearingCache: false, }; } + clearCache() { + this.setState({ + clearingCache: true, + }); + const success = () => { + this.setState({ clearingCache: false }); + window.location.href = `${remote.app.getAppPath()}/dist/index.html`; + }; + const clear = () => this.props.clearCache().then(success.bind(this)); + + setTimeout(clear, 1000, { once: true }); + } + setDaemonSetting(name, value) { this.props.setDaemonSetting(name, value); } @@ -274,6 +291,27 @@ class SettingsPage extends React.PureComponent { /> + +
+
+

{__("Application Cache")}

+
+
+

+ +

+
+
); } diff --git a/ui/js/store.js b/ui/js/store.js index 23796c99e..5f75449de 100644 --- a/ui/js/store.js +++ b/ui/js/store.js @@ -100,6 +100,6 @@ const persistOptions = { debounce: 1000, storage: localForage, }; -persistStore(reduxStore, persistOptions); +window.cacheStore = persistStore(reduxStore, persistOptions); export default reduxStore;