From 8bfef313869ca48687cd8548075cdf3519f2c879 Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Sun, 30 Jun 2019 21:16:44 -0400 Subject: [PATCH 1/2] jessop's commit - channel edit functionality --- dist/bundle.es.js | 56 +++++++++++++++++++++++++++++++++++ dist/flow-typed/Lbry.js | 2 ++ flow-typed/Lbry.js | 2 ++ src/constants/action_types.js | 3 ++ src/index.js | 2 ++ src/lbry.js | 1 + src/redux/actions/claims.js | 34 +++++++++++++++++++++ src/redux/reducers/claims.js | 11 +++++++ src/redux/selectors/claims.js | 8 +++++ 9 files changed, 119 insertions(+) diff --git a/dist/bundle.es.js b/dist/bundle.es.js index 9143564..d81f802 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -103,6 +103,9 @@ const FETCH_CHANNEL_LIST_COMPLETED = 'FETCH_CHANNEL_LIST_COMPLETED'; const CREATE_CHANNEL_STARTED = 'CREATE_CHANNEL_STARTED'; const CREATE_CHANNEL_COMPLETED = 'CREATE_CHANNEL_COMPLETED'; const CREATE_CHANNEL_FAILED = 'CREATE_CHANNEL_FAILED'; +const UPDATE_CHANNEL_STARTED = 'UPDATE_CHANNEL_STARTED'; +const UPDATE_CHANNEL_COMPLETED = 'UPDATE_CHANNEL_COMPLETED'; +const UPDATE_CHANNEL_FAILED = 'UPDATE_CHANNEL_FAILED'; const PUBLISH_STARTED = 'PUBLISH_STARTED'; const PUBLISH_COMPLETED = 'PUBLISH_COMPLETED'; const PUBLISH_FAILED = 'PUBLISH_FAILED'; @@ -328,6 +331,9 @@ var action_types = /*#__PURE__*/Object.freeze({ CREATE_CHANNEL_STARTED: CREATE_CHANNEL_STARTED, CREATE_CHANNEL_COMPLETED: CREATE_CHANNEL_COMPLETED, CREATE_CHANNEL_FAILED: CREATE_CHANNEL_FAILED, + UPDATE_CHANNEL_STARTED: UPDATE_CHANNEL_STARTED, + UPDATE_CHANNEL_COMPLETED: UPDATE_CHANNEL_COMPLETED, + UPDATE_CHANNEL_FAILED: UPDATE_CHANNEL_FAILED, PUBLISH_STARTED: PUBLISH_STARTED, PUBLISH_COMPLETED: PUBLISH_COMPLETED, PUBLISH_FAILED: PUBLISH_FAILED, @@ -707,6 +713,7 @@ const Lbry = { claim_search: params => daemonCallWithResult('claim_search', params), claim_list: params => daemonCallWithResult('claim_list', params), channel_create: params => daemonCallWithResult('channel_create', params), + channel_update: params => daemonCallWithResult('channel_update', params), channel_list: params => daemonCallWithResult('channel_list', params), stream_abandon: params => daemonCallWithResult('stream_abandon', params), channel_abandon: params => daemonCallWithResult('channel_abandon', params), @@ -1334,6 +1341,10 @@ const makeSelectDateForUri = uri => reselect.createSelector(makeSelectClaimForUr return dateObj; }); +const makeSelectAmountForUri = uri => reselect.createSelector(makeSelectClaimForUri(uri), claim => { + return claim && claim.amount; +}); + const makeSelectContentTypeForUri = uri => reselect.createSelector(makeSelectClaimForUri(uri), claim => { const source = claim && claim.value && claim.value.source; return source ? source.media_type : undefined; @@ -2229,6 +2240,38 @@ function doCreateChannel(name, amount) { }; } +function doUpdateChannel(params) { + return dispatch => { + dispatch({ + type: UPDATE_CHANNEL_STARTED + }); + const updateParams = { + claim_id: params.claim_id, + bid: creditsToString(params.amount), + title: params.title, + cover_url: params.cover, + thumbnail_url: params.thumbnail, + description: params.description, + website_url: params.website, + email: params.email, + replace: true + }; + + return lbryProxy.channel_update(updateParams).then(result => { + const channelClaim = result.outputs[0]; + dispatch({ + type: UPDATE_CHANNEL_COMPLETED, + data: { channelClaim } + }); + }).catch(error => { + dispatch({ + type: UPDATE_CHANNEL_FAILED, + data: error + }); + }); + }; +} + function doFetchChannelListMine() { return dispatch => { dispatch({ @@ -3476,6 +3519,17 @@ reducers[CREATE_CHANNEL_COMPLETED] = (state, action) => { }); }; +reducers[UPDATE_CHANNEL_COMPLETED] = (state, action) => { + const channelClaim = action.data.channelClaim; + const byId = Object.assign({}, state.byId); + + byId[channelClaim.claim_id] = channelClaim; + + return Object.assign({}, state, { + byId + }); +}; + reducers[RESOLVE_URIS_STARTED] = (state, action) => { const { uris } = action.data; @@ -4619,6 +4673,7 @@ exports.doToggleTagFollow = doToggleTagFollow; exports.doTotalBalanceSubscribe = doTotalBalanceSubscribe; exports.doUpdateBalance = doUpdateBalance; exports.doUpdateBlockHeight = doUpdateBlockHeight; +exports.doUpdateChannel = doUpdateChannel; exports.doUpdatePublishForm = doUpdatePublishForm; exports.doUpdateSearchOptions = doUpdateSearchOptions; exports.doUpdateSearchQuery = doUpdateSearchQuery; @@ -4636,6 +4691,7 @@ exports.isClaimNsfw = isClaimNsfw; exports.isNameValid = isNameValid; exports.isURIClaimable = isURIClaimable; exports.isURIValid = isURIValid; +exports.makeSelectAmountForUri = makeSelectAmountForUri; exports.makeSelectChannelForClaimUri = makeSelectChannelForClaimUri; exports.makeSelectClaimForUri = makeSelectClaimForUri; exports.makeSelectClaimIsMine = makeSelectClaimIsMine; diff --git a/dist/flow-typed/Lbry.js b/dist/flow-typed/Lbry.js index 9931f68..6438792 100644 --- a/dist/flow-typed/Lbry.js +++ b/dist/flow-typed/Lbry.js @@ -176,6 +176,8 @@ declare type LbryTypes = { claim_search: (params: {}) => Promise, claim_list: (params?: {}) => Promise, channel_create: (params: {}) => Promise, + // TODO fix this type: + channel_update: (params: {}) => Promise, channel_list: () => Promise, stream_abandon: (params: {}) => Promise, channel_abandon: (params: {}) => Promise, diff --git a/flow-typed/Lbry.js b/flow-typed/Lbry.js index 9931f68..6438792 100644 --- a/flow-typed/Lbry.js +++ b/flow-typed/Lbry.js @@ -176,6 +176,8 @@ declare type LbryTypes = { claim_search: (params: {}) => Promise, claim_list: (params?: {}) => Promise, channel_create: (params: {}) => Promise, + // TODO fix this type: + channel_update: (params: {}) => Promise, channel_list: () => Promise, stream_abandon: (params: {}) => Promise, channel_abandon: (params: {}) => Promise, diff --git a/src/constants/action_types.js b/src/constants/action_types.js index 3fa9547..bdbad5d 100644 --- a/src/constants/action_types.js +++ b/src/constants/action_types.js @@ -80,6 +80,9 @@ export const FETCH_CHANNEL_LIST_COMPLETED = 'FETCH_CHANNEL_LIST_COMPLETED'; export const CREATE_CHANNEL_STARTED = 'CREATE_CHANNEL_STARTED'; export const CREATE_CHANNEL_COMPLETED = 'CREATE_CHANNEL_COMPLETED'; export const CREATE_CHANNEL_FAILED = 'CREATE_CHANNEL_FAILED'; +export const UPDATE_CHANNEL_STARTED = 'UPDATE_CHANNEL_STARTED'; +export const UPDATE_CHANNEL_COMPLETED = 'UPDATE_CHANNEL_COMPLETED'; +export const UPDATE_CHANNEL_FAILED = 'UPDATE_CHANNEL_FAILED'; export const PUBLISH_STARTED = 'PUBLISH_STARTED'; export const PUBLISH_COMPLETED = 'PUBLISH_COMPLETED'; export const PUBLISH_FAILED = 'PUBLISH_FAILED'; diff --git a/src/index.js b/src/index.js index 5b861a1..9754c25 100644 --- a/src/index.js +++ b/src/index.js @@ -49,6 +49,7 @@ export { doResolveUri, doFetchChannelListMine, doCreateChannel, + doUpdateChannel, doClaimSearch, } from 'redux/actions/claims'; @@ -149,6 +150,7 @@ export { makeSelectCoverForUri, makeSelectTitleForUri, makeSelectDateForUri, + makeSelectAmountForUri, makeSelectTagsForUri, makeSelectContentTypeForUri, makeSelectIsUriResolving, diff --git a/src/lbry.js b/src/lbry.js index 617b24b..07fe1f0 100644 --- a/src/lbry.js +++ b/src/lbry.js @@ -71,6 +71,7 @@ const Lbry: LbryTypes = { claim_search: params => daemonCallWithResult('claim_search', params), claim_list: params => daemonCallWithResult('claim_list', params), channel_create: params => daemonCallWithResult('channel_create', params), + channel_update: params => daemonCallWithResult('channel_update', params), channel_list: params => daemonCallWithResult('channel_list', params), stream_abandon: params => daemonCallWithResult('stream_abandon', params), channel_abandon: params => daemonCallWithResult('channel_abandon', params), diff --git a/src/redux/actions/claims.js b/src/redux/actions/claims.js index ea5e1a4..f973890 100644 --- a/src/redux/actions/claims.js +++ b/src/redux/actions/claims.js @@ -248,6 +248,40 @@ export function doCreateChannel(name: string, amount: number) { }; } +export function doUpdateChannel(params: any) { + return (dispatch: Dispatch) => { + dispatch({ + type: ACTIONS.UPDATE_CHANNEL_STARTED, + }); + const updateParams = { + claim_id: params.claim_id, + bid: creditsToString(params.amount), + title: params.title, + cover_url: params.cover, + thumbnail_url: params.thumbnail, + description: params.description, + website_url: params.website, + email: params.email, + replace: true, + }; + + return Lbry.channel_update(updateParams) + .then((result: ChannelCreateResponse) => { + const channelClaim = result.outputs[0]; + dispatch({ + type: ACTIONS.UPDATE_CHANNEL_COMPLETED, + data: { channelClaim }, + }); + }) + .catch(error => { + dispatch({ + type: ACTIONS.UPDATE_CHANNEL_FAILED, + data: error, + }); + }); + }; +} + export function doFetchChannelListMine() { return (dispatch: Dispatch) => { dispatch({ diff --git a/src/redux/reducers/claims.js b/src/redux/reducers/claims.js index 43ee173..99a8f7f 100644 --- a/src/redux/reducers/claims.js +++ b/src/redux/reducers/claims.js @@ -257,6 +257,17 @@ reducers[ACTIONS.CREATE_CHANNEL_COMPLETED] = (state: State, action: any): State }); }; +reducers[ACTIONS.UPDATE_CHANNEL_COMPLETED] = (state: State, action: any): State => { + const channelClaim: ChannelClaim = action.data.channelClaim; + const byId = Object.assign({}, state.byId); + + byId[channelClaim.claim_id] = channelClaim; + + return Object.assign({}, state, { + byId, + }); +}; + reducers[ACTIONS.RESOLVE_URIS_STARTED] = (state: State, action: any): State => { const { uris }: { uris: Array } = action.data; diff --git a/src/redux/selectors/claims.js b/src/redux/selectors/claims.js index 7caa2d2..69fddb5 100644 --- a/src/redux/selectors/claims.js +++ b/src/redux/selectors/claims.js @@ -204,6 +204,14 @@ export const makeSelectDateForUri = (uri: string) => } ); +export const makeSelectAmountForUri = (uri: string) => + createSelector( + makeSelectClaimForUri(uri), + claim => { + return claim && claim.amount; + } + ); + export const makeSelectContentTypeForUri = (uri: string) => createSelector( makeSelectClaimForUri(uri), From 4c6147efcc3823c4008b99cf4815952cb02aacc4 Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Tue, 2 Jul 2019 13:47:42 -0400 Subject: [PATCH 2/2] add ChannelUpdateResponse type --- dist/flow-typed/Lbry.js | 15 ++++++++------- flow-typed/Lbry.js | 15 ++++++++------- src/redux/actions/claims.js | 2 +- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/dist/flow-typed/Lbry.js b/dist/flow-typed/Lbry.js index 6438792..bc02e1f 100644 --- a/dist/flow-typed/Lbry.js +++ b/dist/flow-typed/Lbry.js @@ -65,9 +65,7 @@ declare type VersionResponse = { declare type ResolveResponse = { // Keys are the url(s) passed to resolve - [string]: - | Claim - | { error?: {} }, + [string]: Claim | { error?: {} }, }; declare type GetResponse = FileListItem; @@ -105,6 +103,10 @@ declare type ChannelCreateResponse = GenericTxResponse & { outputs: Array, }; +declare type UpdateChannelResponse = GenericTxResponse & { + outputs: Array, +}; + declare type CommentCreateResponse = Comment; declare type CommentListResponse = Array; @@ -157,10 +159,10 @@ declare type LbryTypes = { connectPromise: ?Promise, connect: () => void, daemonConnectionString: string, - apiRequestHeaders: {[key: string]: string}, + apiRequestHeaders: { [key: string]: string }, setDaemonConnectionString: string => void, setApiHeader: (string, string) => void, - unsetApiHeader: (string) => void, + unsetApiHeader: string => void, overrides: { [string]: ?Function }, setOverride: (string, Function) => void, getMediaType: (string, ?string) => string, @@ -176,8 +178,7 @@ declare type LbryTypes = { claim_search: (params: {}) => Promise, claim_list: (params?: {}) => Promise, channel_create: (params: {}) => Promise, - // TODO fix this type: - channel_update: (params: {}) => Promise, + channel_update: (params: {}) => Promise, channel_list: () => Promise, stream_abandon: (params: {}) => Promise, channel_abandon: (params: {}) => Promise, diff --git a/flow-typed/Lbry.js b/flow-typed/Lbry.js index 6438792..335eda1 100644 --- a/flow-typed/Lbry.js +++ b/flow-typed/Lbry.js @@ -65,9 +65,7 @@ declare type VersionResponse = { declare type ResolveResponse = { // Keys are the url(s) passed to resolve - [string]: - | Claim - | { error?: {} }, + [string]: Claim | { error?: {} }, }; declare type GetResponse = FileListItem; @@ -105,6 +103,10 @@ declare type ChannelCreateResponse = GenericTxResponse & { outputs: Array, }; +declare type ChannelUpdateResponse = GenericTxResponse & { + outputs: Array, +}; + declare type CommentCreateResponse = Comment; declare type CommentListResponse = Array; @@ -157,10 +159,10 @@ declare type LbryTypes = { connectPromise: ?Promise, connect: () => void, daemonConnectionString: string, - apiRequestHeaders: {[key: string]: string}, + apiRequestHeaders: { [key: string]: string }, setDaemonConnectionString: string => void, setApiHeader: (string, string) => void, - unsetApiHeader: (string) => void, + unsetApiHeader: string => void, overrides: { [string]: ?Function }, setOverride: (string, Function) => void, getMediaType: (string, ?string) => string, @@ -176,8 +178,7 @@ declare type LbryTypes = { claim_search: (params: {}) => Promise, claim_list: (params?: {}) => Promise, channel_create: (params: {}) => Promise, - // TODO fix this type: - channel_update: (params: {}) => Promise, + channel_update: (params: {}) => Promise, channel_list: () => Promise, stream_abandon: (params: {}) => Promise, channel_abandon: (params: {}) => Promise, diff --git a/src/redux/actions/claims.js b/src/redux/actions/claims.js index f973890..51fd397 100644 --- a/src/redux/actions/claims.js +++ b/src/redux/actions/claims.js @@ -266,7 +266,7 @@ export function doUpdateChannel(params: any) { }; return Lbry.channel_update(updateParams) - .then((result: ChannelCreateResponse) => { + .then((result: ChannelUpdateResponse) => { const channelClaim = result.outputs[0]; dispatch({ type: ACTIONS.UPDATE_CHANNEL_COMPLETED,