Refactor back to lbry.js localStorage for pending publishes

This commit is contained in:
6ea86b96 2017-07-10 21:44:49 +07:00
parent 470f61da9d
commit 76fe44e519
5 changed files with 34 additions and 136 deletions

View file

@ -389,62 +389,19 @@ export function doCreateChannel(name, amount) {
export function doPublish(params) { export function doPublish(params) {
return function(dispatch, getState) { return function(dispatch, getState) {
let uri;
const { name, channel_name } = params;
if (channel_name) {
uri = lbryuri.build({ name: channel_name, path: name }, false);
} else {
uri = lbryuri.build({ name: name }, false);
}
const fakeId = "pending";
const pendingPublish = {
name,
channel_name,
claim_id: fakeId,
txid: "pending_" + uri,
nout: 0,
outpoint: fakeId + ":0",
time: Date.now(),
pending: true,
};
dispatch({
type: types.PUBLISH_STARTED,
data: {
params,
pendingPublish,
},
});
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const success = claim => { const success = claim => {
claim.name = params.name;
claim.channel_name = params.channel_name;
dispatch({
type: types.PUBLISH_COMPLETED,
data: {
claim,
uri,
pendingPublish,
},
});
dispatch(doFileList());
resolve(claim); resolve(claim);
};
const failure = error => {
dispatch({
type: types.PUBLISH_FAILED,
data: {
error,
params,
uri,
pendingPublish,
},
});
reject(error);
};
lbry.publish(params).then(success, failure); if (claim === true) dispatch(doFetchClaimListMine());
else
setTimeout(() => dispatch(doFetchClaimListMine()), 20000, {
once: true,
});
};
const failure = err => reject(err);
lbry.publishDeprecated(params, null, success, failure);
}); });
}; };
} }

View file

@ -66,14 +66,7 @@ class FileTile extends React.PureComponent {
? metadata.title ? metadata.title
: lbryuri.parse(uri).contentName; : lbryuri.parse(uri).contentName;
const obscureNsfw = this.props.obscureNsfw && metadata && metadata.nsfw; const obscureNsfw = this.props.obscureNsfw && metadata && metadata.nsfw;
let onClick; let onClick = () => navigate("/show", { uri });
if (isClaimed) {
onClick = () => navigate("/show", { uri });
} else {
onClick = () => {
return false;
};
}
let description = ""; let description = "";
if (isClaimed) { if (isClaimed) {

View file

@ -223,45 +223,38 @@ lbry.publishDeprecated = function(
) { ) {
lbry.publish(params).then( lbry.publish(params).then(
result => { result => {
if (returnedPending) { if (returnPendingTimeout) clearTimeout(returnPendingTimeout);
return;
}
clearTimeout(returnPendingTimeout);
publishedCallback(result); publishedCallback(result);
}, },
err => { err => {
if (returnedPending) { if (returnPendingTimeout) clearTimeout(returnPendingTimeout);
return;
}
clearTimeout(returnPendingTimeout);
errorCallback(err); errorCallback(err);
} }
); );
let returnedPending = false;
// Give a short grace period in case publish() returns right away or (more likely) gives an error // Give a short grace period in case publish() returns right away or (more likely) gives an error
const returnPendingTimeout = setTimeout(() => { const returnPendingTimeout = setTimeout(
returnedPending = true; () => {
if (publishedCallback) {
savePendingPublish({
name: params.name,
channel_name: params.channel_name,
});
publishedCallback(true);
}
if (publishedCallback) { if (fileListedCallback) {
savePendingPublish({ const { name, channel_name } = params;
name: params.name, savePendingPublish({
channel_name: params.channel_name, name: params.name,
}); channel_name: params.channel_name,
publishedCallback(true); });
} fileListedCallback(true);
}
if (fileListedCallback) { },
const { name, channel_name } = params; 2000,
savePendingPublish({ { once: true }
name: params.name, );
channel_name: params.channel_name,
});
fileListedCallback(true);
}
}, 2000);
}; };
lbry.getClientSettings = function() { lbry.getClientSettings = function() {

View file

@ -159,45 +159,6 @@ reducers[types.CREATE_CHANNEL_COMPLETED] = function(state, action) {
}); });
}; };
reducers[types.PUBLISH_STARTED] = function(state, action) {
const { pendingPublish } = action.data;
const pendingById = Object.assign({}, state.pendingById);
pendingById[pendingPublish.claim_id] = pendingPublish;
return Object.assign({}, state, {
pendingById,
});
};
reducers[types.PUBLISH_COMPLETED] = function(state, action) {
const { claim, pendingPublish } = action.data;
const byId = Object.assign({}, state.byId);
const myClaims = new Set(state.myClaims);
const pendingById = Object.assign({}, state.pendingById);
byId[claim.claim_id] = claim;
myClaims.add(claim.claim_id);
delete pendingById[pendingPublish.claim_id];
return Object.assign({}, state, {
byId,
myClaims,
pendingById,
});
};
reducers[types.PUBLISH_FAILED] = function(state, action) {
const { pendingPublish } = action.data;
const pendingById = Object.assign({}, state.pendingById);
delete pendingById[pendingPublish.claim_id];
return Object.assign({}, state, {
pendingById,
});
};
export default function reducer(state = defaultState, action) { export default function reducer(state = defaultState, action) {
const handler = reducers[action.type]; const handler = reducers[action.type];
if (handler) return handler(state, action); if (handler) return handler(state, action);

View file

@ -86,13 +86,7 @@ const createStoreWithMiddleware = redux.compose(
const reduxStore = createStoreWithMiddleware(enableBatching(reducers)); const reduxStore = createStoreWithMiddleware(enableBatching(reducers));
const compressor = createCompressor(); const compressor = createCompressor();
const saveClaimsFilter = createFilter("claims", [ const saveClaimsFilter = createFilter("claims", ["byId", "claimsByUri"]);
"byId",
"claimsByUri",
"myClaims",
"myChannelClaims",
"pendingById",
]);
const persistOptions = { const persistOptions = {
whitelist: ["claims"], whitelist: ["claims"],