Refactor back to lbry.js localStorage for pending publishes
This commit is contained in:
parent
470f61da9d
commit
76fe44e519
5 changed files with 34 additions and 136 deletions
|
@ -389,62 +389,19 @@ export function doCreateChannel(name, amount) {
|
|||
|
||||
export function doPublish(params) {
|
||||
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) => {
|
||||
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);
|
||||
};
|
||||
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);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
|
@ -66,14 +66,7 @@ class FileTile extends React.PureComponent {
|
|||
? metadata.title
|
||||
: lbryuri.parse(uri).contentName;
|
||||
const obscureNsfw = this.props.obscureNsfw && metadata && metadata.nsfw;
|
||||
let onClick;
|
||||
if (isClaimed) {
|
||||
onClick = () => navigate("/show", { uri });
|
||||
} else {
|
||||
onClick = () => {
|
||||
return false;
|
||||
};
|
||||
}
|
||||
let onClick = () => navigate("/show", { uri });
|
||||
|
||||
let description = "";
|
||||
if (isClaimed) {
|
||||
|
|
|
@ -223,45 +223,38 @@ lbry.publishDeprecated = function(
|
|||
) {
|
||||
lbry.publish(params).then(
|
||||
result => {
|
||||
if (returnedPending) {
|
||||
return;
|
||||
}
|
||||
|
||||
clearTimeout(returnPendingTimeout);
|
||||
if (returnPendingTimeout) clearTimeout(returnPendingTimeout);
|
||||
publishedCallback(result);
|
||||
},
|
||||
err => {
|
||||
if (returnedPending) {
|
||||
return;
|
||||
}
|
||||
|
||||
clearTimeout(returnPendingTimeout);
|
||||
if (returnPendingTimeout) clearTimeout(returnPendingTimeout);
|
||||
errorCallback(err);
|
||||
}
|
||||
);
|
||||
|
||||
let returnedPending = false;
|
||||
// Give a short grace period in case publish() returns right away or (more likely) gives an error
|
||||
const returnPendingTimeout = setTimeout(() => {
|
||||
returnedPending = true;
|
||||
const returnPendingTimeout = setTimeout(
|
||||
() => {
|
||||
if (publishedCallback) {
|
||||
savePendingPublish({
|
||||
name: params.name,
|
||||
channel_name: params.channel_name,
|
||||
});
|
||||
publishedCallback(true);
|
||||
}
|
||||
|
||||
if (publishedCallback) {
|
||||
savePendingPublish({
|
||||
name: params.name,
|
||||
channel_name: params.channel_name,
|
||||
});
|
||||
publishedCallback(true);
|
||||
}
|
||||
|
||||
if (fileListedCallback) {
|
||||
const { name, channel_name } = params;
|
||||
savePendingPublish({
|
||||
name: params.name,
|
||||
channel_name: params.channel_name,
|
||||
});
|
||||
fileListedCallback(true);
|
||||
}
|
||||
}, 2000);
|
||||
if (fileListedCallback) {
|
||||
const { name, channel_name } = params;
|
||||
savePendingPublish({
|
||||
name: params.name,
|
||||
channel_name: params.channel_name,
|
||||
});
|
||||
fileListedCallback(true);
|
||||
}
|
||||
},
|
||||
2000,
|
||||
{ once: true }
|
||||
);
|
||||
};
|
||||
|
||||
lbry.getClientSettings = function() {
|
||||
|
|
|
@ -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) {
|
||||
const handler = reducers[action.type];
|
||||
if (handler) return handler(state, action);
|
||||
|
|
|
@ -86,13 +86,7 @@ const createStoreWithMiddleware = redux.compose(
|
|||
|
||||
const reduxStore = createStoreWithMiddleware(enableBatching(reducers));
|
||||
const compressor = createCompressor();
|
||||
const saveClaimsFilter = createFilter("claims", [
|
||||
"byId",
|
||||
"claimsByUri",
|
||||
"myClaims",
|
||||
"myChannelClaims",
|
||||
"pendingById",
|
||||
]);
|
||||
const saveClaimsFilter = createFilter("claims", ["byId", "claimsByUri"]);
|
||||
|
||||
const persistOptions = {
|
||||
whitelist: ["claims"],
|
||||
|
|
Loading…
Add table
Reference in a new issue