Always refresh claims/file info on downloaded/published pages
This commit is contained in:
parent
84589f1ebb
commit
1063d2fc9d
6 changed files with 376 additions and 393 deletions
|
@ -98,16 +98,9 @@ export function doDeleteFile(outpoint, deleteFromComputer) {
|
|||
|
||||
export function doFetchFileInfosAndPublishedClaims() {
|
||||
return function(dispatch, getState) {
|
||||
const state = getState(),
|
||||
isClaimListMinePending = selectClaimListMineIsPending(state),
|
||||
isFileInfoListPending = selectFileListIsPending(state);
|
||||
const state = getState();
|
||||
|
||||
if (isClaimListMinePending === undefined) {
|
||||
dispatch(doFetchClaimListMine());
|
||||
}
|
||||
|
||||
if (isFileInfoListPending === undefined) {
|
||||
dispatch(doFileList());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ class FileList extends React.PureComponent {
|
|||
});
|
||||
return (
|
||||
<section className="file-list__header">
|
||||
{fetching && <span className="busy-indicator" />}
|
||||
{fetching && <BusyMessage />}
|
||||
<span className="sort-section">
|
||||
{__("Sort by")} {" "}
|
||||
<FormField type="select" onChange={this.handleSortChanged.bind(this)}>
|
||||
|
|
|
@ -19,14 +19,14 @@ class FileTile extends React.PureComponent {
|
|||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.resolve(this.props);
|
||||
const { isResolvingUri, claim, uri, resolveUri } = this.props;
|
||||
|
||||
if (!isResolvingUri && !claim && uri) resolveUri(uri);
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
this.resolve(nextProps);
|
||||
}
|
||||
const { isResolvingUri, claim, uri, resolveUri } = this.props;
|
||||
|
||||
resolve({ isResolvingUri, claim, uri, resolveUri }) {
|
||||
if (!isResolvingUri && claim === undefined && uri) resolveUri(uri);
|
||||
}
|
||||
|
||||
|
|
132
ui/js/lbry.js
132
ui/js/lbry.js
|
@ -1,15 +1,15 @@
|
|||
import lbryio from './lbryio.js';
|
||||
import lighthouse from './lighthouse.js';
|
||||
import jsonrpc from './jsonrpc.js';
|
||||
import lbryuri from './lbryuri.js';
|
||||
import { getLocal, getSession, setSession, setLocal } from './utils.js';
|
||||
import lbryio from "./lbryio.js";
|
||||
import lighthouse from "./lighthouse.js";
|
||||
import jsonrpc from "./jsonrpc.js";
|
||||
import lbryuri from "./lbryuri.js";
|
||||
import { getLocal, getSession, setSession, setLocal } from "./utils.js";
|
||||
|
||||
const { remote, ipcRenderer } = require('electron');
|
||||
const menu = remote.require('./menu/main-menu');
|
||||
const { remote, ipcRenderer } = require("electron");
|
||||
const menu = remote.require("./menu/main-menu");
|
||||
|
||||
let lbry = {
|
||||
isConnected: false,
|
||||
daemonConnectionString: 'http://localhost:5279/lbryapi',
|
||||
daemonConnectionString: "http://localhost:5279/lbryapi",
|
||||
pendingPublishTimeout: 20 * 60 * 1000,
|
||||
defaultClientSettings: {
|
||||
showNsfw: false,
|
||||
|
@ -18,8 +18,8 @@ let lbry = {
|
|||
useCustomLighthouseServers: false,
|
||||
customLighthouseServers: [],
|
||||
showDeveloperMenu: false,
|
||||
language: 'en'
|
||||
}
|
||||
language: "en",
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -33,17 +33,17 @@ function savePendingPublish({ name, channel_name }) {
|
|||
} else {
|
||||
uri = lbryuri.build({ name: name }, false);
|
||||
}
|
||||
const pendingPublishes = getLocal('pendingPublishes') || [];
|
||||
const pendingPublishes = getLocal("pendingPublishes") || [];
|
||||
const newPendingPublish = {
|
||||
name,
|
||||
channel_name,
|
||||
claim_id: 'pending_claim_' + uri,
|
||||
txid: 'pending_' + uri,
|
||||
claim_id: "pending_claim_" + uri,
|
||||
txid: "pending_" + uri,
|
||||
nout: 0,
|
||||
outpoint: 'pending_' + uri + ':0',
|
||||
time: Date.now()
|
||||
outpoint: "pending_" + uri + ":0",
|
||||
time: Date.now(),
|
||||
};
|
||||
setLocal('pendingPublishes', [...pendingPublishes, newPendingPublish]);
|
||||
setLocal("pendingPublishes", [...pendingPublishes, newPendingPublish]);
|
||||
return newPendingPublish;
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ function removePendingPublishIfNeeded({ name, channel_name, outpoint }) {
|
|||
}
|
||||
|
||||
setLocal(
|
||||
'pendingPublishes',
|
||||
"pendingPublishes",
|
||||
lbry.getPendingPublishes().filter(pub => !pubMatches(pub))
|
||||
);
|
||||
}
|
||||
|
@ -71,11 +71,11 @@ function removePendingPublishIfNeeded({ name, channel_name, outpoint }) {
|
|||
* removes them from the list.
|
||||
*/
|
||||
lbry.getPendingPublishes = function() {
|
||||
const pendingPublishes = getLocal('pendingPublishes') || [];
|
||||
const pendingPublishes = getLocal("pendingPublishes") || [];
|
||||
const newPendingPublishes = pendingPublishes.filter(
|
||||
pub => Date.now() - pub.time <= lbry.pendingPublishTimeout
|
||||
);
|
||||
setLocal('pendingPublishes', newPendingPublishes);
|
||||
setLocal("pendingPublishes", newPendingPublishes);
|
||||
return newPendingPublishes;
|
||||
};
|
||||
|
||||
|
@ -101,7 +101,7 @@ function pendingPublishToDummyClaim({
|
|||
outpoint,
|
||||
claim_id,
|
||||
txid,
|
||||
nout
|
||||
nout,
|
||||
}) {
|
||||
return { name, outpoint, claim_id, txid, nout, channel_name };
|
||||
}
|
||||
|
@ -142,14 +142,14 @@ lbry.connect = function() {
|
|||
checkDaemonStarted();
|
||||
}, tryNum < 50 ? 400 : 1000);
|
||||
} else {
|
||||
reject(new Error('Unable to connect to LBRY'));
|
||||
reject(new Error("Unable to connect to LBRY"));
|
||||
}
|
||||
}
|
||||
|
||||
// Check every half second to see if the daemon is accepting connections
|
||||
function checkDaemonStarted() {
|
||||
lbry.call(
|
||||
'status',
|
||||
"status",
|
||||
{},
|
||||
resolve,
|
||||
checkDaemonStartedFailed,
|
||||
|
@ -165,12 +165,12 @@ lbry.connect = function() {
|
|||
};
|
||||
|
||||
lbry.checkAddressIsMine = function(address, callback) {
|
||||
lbry.call('wallet_is_address_mine', { address: address }, callback);
|
||||
lbry.call("wallet_is_address_mine", { address: address }, callback);
|
||||
};
|
||||
|
||||
lbry.sendToAddress = function(amount, address, callback, errorCallback) {
|
||||
lbry.call(
|
||||
'send_amount_to_address',
|
||||
"send_amount_to_address",
|
||||
{ amount: amount, address: address },
|
||||
callback,
|
||||
errorCallback
|
||||
|
@ -191,7 +191,7 @@ lbry.costPromiseCache = {};
|
|||
lbry.getCostInfo = function(uri) {
|
||||
if (lbry.costPromiseCache[uri] === undefined) {
|
||||
lbry.costPromiseCache[uri] = new Promise((resolve, reject) => {
|
||||
const COST_INFO_CACHE_KEY = 'cost_info_cache';
|
||||
const COST_INFO_CACHE_KEY = "cost_info_cache";
|
||||
let costInfoCache = getSession(COST_INFO_CACHE_KEY, {});
|
||||
|
||||
function cacheAndResolve(cost, includesData) {
|
||||
|
@ -245,7 +245,7 @@ lbry.publish = function(
|
|||
errorCallback
|
||||
) {
|
||||
lbry.call(
|
||||
'publish',
|
||||
"publish",
|
||||
params,
|
||||
result => {
|
||||
if (returnedPending) {
|
||||
|
@ -273,7 +273,7 @@ lbry.publish = function(
|
|||
if (publishedCallback) {
|
||||
savePendingPublish({
|
||||
name: params.name,
|
||||
channel_name: params.channel_name
|
||||
channel_name: params.channel_name,
|
||||
});
|
||||
publishedCallback(true);
|
||||
}
|
||||
|
@ -282,7 +282,7 @@ lbry.publish = function(
|
|||
const { name, channel_name } = params;
|
||||
savePendingPublish({
|
||||
name: params.name,
|
||||
channel_name: params.channel_name
|
||||
channel_name: params.channel_name,
|
||||
});
|
||||
fileListedCallback(true);
|
||||
}
|
||||
|
@ -292,7 +292,7 @@ lbry.publish = function(
|
|||
lbry.getClientSettings = function() {
|
||||
var outSettings = {};
|
||||
for (let setting of Object.keys(lbry.defaultClientSettings)) {
|
||||
var localStorageVal = localStorage.getItem('setting_' + setting);
|
||||
var localStorageVal = localStorage.getItem("setting_" + setting);
|
||||
outSettings[setting] = localStorageVal === null
|
||||
? lbry.defaultClientSettings[setting]
|
||||
: JSON.parse(localStorageVal);
|
||||
|
@ -301,8 +301,8 @@ lbry.getClientSettings = function() {
|
|||
};
|
||||
|
||||
lbry.getClientSetting = function(setting) {
|
||||
var localStorageVal = localStorage.getItem('setting_' + setting);
|
||||
if (setting == 'showDeveloperMenu') {
|
||||
var localStorageVal = localStorage.getItem("setting_" + setting);
|
||||
if (setting == "showDeveloperMenu") {
|
||||
return true;
|
||||
}
|
||||
return localStorageVal === null
|
||||
|
@ -317,18 +317,18 @@ lbry.setClientSettings = function(settings) {
|
|||
};
|
||||
|
||||
lbry.setClientSetting = function(setting, value) {
|
||||
return localStorage.setItem('setting_' + setting, JSON.stringify(value));
|
||||
return localStorage.setItem("setting_" + setting, JSON.stringify(value));
|
||||
};
|
||||
|
||||
lbry.getSessionInfo = function(callback) {
|
||||
lbry.call('status', { session_status: true }, callback);
|
||||
lbry.call("status", { session_status: true }, callback);
|
||||
};
|
||||
|
||||
lbry.reportBug = function(message, callback) {
|
||||
lbry.call(
|
||||
'report_bug',
|
||||
"report_bug",
|
||||
{
|
||||
message: message
|
||||
message: message,
|
||||
},
|
||||
callback
|
||||
);
|
||||
|
@ -336,46 +336,46 @@ lbry.reportBug = function(message, callback) {
|
|||
|
||||
//utilities
|
||||
lbry.formatCredits = function(amount, precision) {
|
||||
return amount.toFixed(precision || 1).replace(/\.?0+$/, '');
|
||||
return amount.toFixed(precision || 1).replace(/\.?0+$/, "");
|
||||
};
|
||||
|
||||
lbry.formatName = function(name) {
|
||||
// Converts LBRY name to standard format (all lower case, no special characters, spaces replaced by dashes)
|
||||
name = name.replace('/s+/g', '-');
|
||||
name = name.toLowerCase().replace(/[^a-z0-9\-]/g, '');
|
||||
name = name.replace("/s+/g", "-");
|
||||
name = name.toLowerCase().replace(/[^a-z0-9\-]/g, "");
|
||||
return name;
|
||||
};
|
||||
|
||||
lbry.imagePath = function(file) {
|
||||
return 'img/' + file;
|
||||
return "img/" + file;
|
||||
};
|
||||
|
||||
lbry.getMediaType = function(contentType, fileName) {
|
||||
if (contentType) {
|
||||
return /^[^/]+/.exec(contentType)[0];
|
||||
} else if (fileName) {
|
||||
var dotIndex = fileName.lastIndexOf('.');
|
||||
var dotIndex = fileName.lastIndexOf(".");
|
||||
if (dotIndex == -1) {
|
||||
return 'unknown';
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
var ext = fileName.substr(dotIndex + 1);
|
||||
if (/^mp4|mov|m4v|flv|f4v$/i.test(ext)) {
|
||||
return 'video';
|
||||
return "video";
|
||||
} else if (/^mp3|m4a|aac|wav|flac|ogg$/i.test(ext)) {
|
||||
return 'audio';
|
||||
return "audio";
|
||||
} else if (/^html|htm|pdf|odf|doc|docx|md|markdown|txt$/i.test(ext)) {
|
||||
return 'document';
|
||||
return "document";
|
||||
} else {
|
||||
return 'unknown';
|
||||
return "unknown";
|
||||
}
|
||||
} else {
|
||||
return 'unknown';
|
||||
return "unknown";
|
||||
}
|
||||
};
|
||||
|
||||
lbry.stop = function(callback) {
|
||||
lbry.call('stop', {}, callback);
|
||||
lbry.call("stop", {}, callback);
|
||||
};
|
||||
|
||||
lbry._subscribeIdCount = 0;
|
||||
|
@ -418,22 +418,22 @@ lbry.balanceUnsubscribe = function(subscribeId) {
|
|||
};
|
||||
|
||||
lbry.showMenuIfNeeded = function() {
|
||||
const showingMenu = sessionStorage.getItem('menuShown') || null;
|
||||
const chosenMenu = lbry.getClientSetting('showDeveloperMenu')
|
||||
? 'developer'
|
||||
: 'normal';
|
||||
const showingMenu = sessionStorage.getItem("menuShown") || null;
|
||||
const chosenMenu = lbry.getClientSetting("showDeveloperMenu")
|
||||
? "developer"
|
||||
: "normal";
|
||||
if (chosenMenu != showingMenu) {
|
||||
menu.showMenubar(chosenMenu == 'developer');
|
||||
menu.showMenubar(chosenMenu == "developer");
|
||||
}
|
||||
sessionStorage.setItem('menuShown', chosenMenu);
|
||||
sessionStorage.setItem("menuShown", chosenMenu);
|
||||
};
|
||||
|
||||
lbry.getAppVersionInfo = function() {
|
||||
return new Promise((resolve, reject) => {
|
||||
ipcRenderer.once('version-info-received', (event, versionInfo) => {
|
||||
ipcRenderer.once("version-info-received", (event, versionInfo) => {
|
||||
resolve(versionInfo);
|
||||
});
|
||||
ipcRenderer.send('version-info-requested');
|
||||
ipcRenderer.send("version-info-requested");
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -464,7 +464,7 @@ lbry.file_list = function(params = {}) {
|
|||
}
|
||||
|
||||
lbry.call(
|
||||
'file_list',
|
||||
"file_list",
|
||||
params,
|
||||
fileInfos => {
|
||||
removePendingPublishIfNeeded({ name, channel_name, outpoint });
|
||||
|
@ -483,14 +483,14 @@ lbry.file_list = function(params = {}) {
|
|||
lbry.claim_list_mine = function(params = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
lbry.call(
|
||||
'claim_list_mine',
|
||||
"claim_list_mine",
|
||||
params,
|
||||
claims => {
|
||||
for (let { name, channel_name, txid, nout } of claims) {
|
||||
removePendingPublishIfNeeded({
|
||||
name,
|
||||
channel_name,
|
||||
outpoint: txid + ':' + nout
|
||||
outpoint: txid + ":" + nout,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -505,30 +505,20 @@ lbry.claim_list_mine = function(params = {}) {
|
|||
});
|
||||
};
|
||||
|
||||
const claimCacheKey = 'resolve_claim_cache';
|
||||
lbry._claimCache = getSession(claimCacheKey, {});
|
||||
lbry._resolveXhrs = {};
|
||||
lbry.resolve = function(params = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!params.uri) {
|
||||
throw __('Resolve has hacked cache on top of it that requires a URI');
|
||||
throw __("Resolve has hacked cache on top of it that requires a URI");
|
||||
}
|
||||
if (params.uri && lbry._claimCache[params.uri] !== undefined) {
|
||||
resolve(lbry._claimCache[params.uri]);
|
||||
} else {
|
||||
lbry._resolveXhrs[params.uri] = lbry.call(
|
||||
'resolve',
|
||||
"resolve",
|
||||
params,
|
||||
function(data) {
|
||||
if (data !== undefined) {
|
||||
lbry._claimCache[params.uri] = data;
|
||||
}
|
||||
setSession(claimCacheKey, lbry._claimCache);
|
||||
resolve(data);
|
||||
},
|
||||
reject
|
||||
);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -557,7 +547,7 @@ lbry = new Proxy(lbry, {
|
|||
);
|
||||
});
|
||||
};
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
export default lbry;
|
||||
|
|
|
@ -12,7 +12,7 @@ import SubHeader from "component/subHeader";
|
|||
|
||||
class FileListDownloaded extends React.PureComponent {
|
||||
componentWillMount() {
|
||||
this.props.fetchFileInfosDownloaded();
|
||||
if (!this.props.isPending) this.props.fetchFileInfosDownloaded();
|
||||
}
|
||||
|
||||
render() {
|
||||
|
|
|
@ -12,7 +12,7 @@ import SubHeader from "component/subHeader";
|
|||
|
||||
class FileListPublished extends React.PureComponent {
|
||||
componentWillMount() {
|
||||
this.props.fetchFileListPublished();
|
||||
if (!this.props.isPending) this.props.fetchFileListPublished();
|
||||
}
|
||||
|
||||
componentDidUpdate() {
|
||||
|
|
Loading…
Reference in a new issue