2018-03-26 23:32:43 +02:00
|
|
|
// @flow
|
|
|
|
import { handleActions } from 'util/redux-utils';
|
2018-04-18 06:03:01 +02:00
|
|
|
import { buildURI } from 'lbry-redux';
|
2018-03-26 23:32:43 +02:00
|
|
|
import * as ACTIONS from 'constants/action_types';
|
2018-04-02 15:35:52 +02:00
|
|
|
import * as STATUSES from 'constants/thumbnail_upload_statuses';
|
2018-03-26 23:32:43 +02:00
|
|
|
import { CHANNEL_ANONYMOUS } from 'constants/claim';
|
|
|
|
|
|
|
|
type PublishState = {
|
|
|
|
editingURI: ?string,
|
|
|
|
filePath: ?string,
|
|
|
|
contentIsFree: boolean,
|
|
|
|
price: {
|
|
|
|
amount: number,
|
|
|
|
currency: string,
|
|
|
|
},
|
|
|
|
title: string,
|
|
|
|
thumbnail: string,
|
2018-06-08 06:05:45 +02:00
|
|
|
thumbnailPath: string,
|
2018-04-02 15:53:29 +02:00
|
|
|
uploadThumbnailStatus: string,
|
2018-03-26 23:32:43 +02:00
|
|
|
description: string,
|
|
|
|
language: string,
|
|
|
|
tosAccepted: boolean,
|
|
|
|
channel: string,
|
2018-05-16 01:01:53 +02:00
|
|
|
channelId: ?string,
|
2018-03-26 23:32:43 +02:00
|
|
|
name: string,
|
|
|
|
nameError: ?string,
|
|
|
|
bid: number,
|
|
|
|
bidError: ?string,
|
|
|
|
otherLicenseDescription: string,
|
|
|
|
licenseUrl: string,
|
|
|
|
copyrightNotice: string,
|
|
|
|
pendingPublishes: Array<any>,
|
|
|
|
};
|
|
|
|
|
|
|
|
export type UpdatePublishFormData = {
|
|
|
|
filePath?: string,
|
|
|
|
contentIsFree?: boolean,
|
|
|
|
price?: {
|
|
|
|
amount: number,
|
|
|
|
currency: string,
|
|
|
|
},
|
|
|
|
title?: string,
|
|
|
|
thumbnail?: string,
|
2018-04-02 15:53:29 +02:00
|
|
|
uploadThumbnailStatus?: string,
|
2018-06-08 06:05:45 +02:00
|
|
|
thumbnailPath?: string,
|
2018-03-26 23:32:43 +02:00
|
|
|
description?: string,
|
|
|
|
language?: string,
|
|
|
|
tosAccepted?: boolean,
|
|
|
|
channel?: string,
|
2018-05-16 01:01:53 +02:00
|
|
|
channelId?: string,
|
2018-03-26 23:32:43 +02:00
|
|
|
name?: string,
|
|
|
|
nameError?: string,
|
|
|
|
bid?: number,
|
|
|
|
bidError?: string,
|
|
|
|
otherLicenseDescription?: string,
|
|
|
|
licenseUrl?: string,
|
|
|
|
copyrightNotice?: string,
|
|
|
|
};
|
|
|
|
|
|
|
|
export type UpdatePublishFormAction = {
|
|
|
|
type: ACTIONS.UPDATE_PUBLISH_FORM | ACTIONS.DO_PREPARE_EDIT,
|
|
|
|
data: UpdatePublishFormData,
|
|
|
|
};
|
|
|
|
|
|
|
|
export type PublishParams = {
|
|
|
|
name: string,
|
|
|
|
bid: number,
|
|
|
|
filePath: string,
|
|
|
|
description: ?string,
|
|
|
|
language: string,
|
|
|
|
publishingLicense: string,
|
|
|
|
publishingLicenseUrl: string,
|
|
|
|
thumbnail: ?string,
|
|
|
|
nsfw: boolean,
|
|
|
|
channel: string,
|
2018-05-16 01:01:53 +02:00
|
|
|
channelId: string,
|
2018-03-26 23:32:43 +02:00
|
|
|
title: string,
|
|
|
|
contentIsFree: boolean,
|
|
|
|
uri: string,
|
|
|
|
license: ?string,
|
|
|
|
licenseUrl: ?string,
|
|
|
|
price: {
|
|
|
|
currency: string,
|
|
|
|
amount: number,
|
|
|
|
},
|
2018-04-04 01:46:03 +02:00
|
|
|
source?: {
|
|
|
|
contentType: string,
|
|
|
|
source: string,
|
|
|
|
sourceType: string,
|
|
|
|
version: string,
|
|
|
|
},
|
2018-03-26 23:32:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const defaultState: PublishState = {
|
|
|
|
editingURI: undefined,
|
|
|
|
filePath: undefined,
|
|
|
|
contentIsFree: true,
|
|
|
|
price: {
|
|
|
|
amount: 1,
|
|
|
|
currency: 'LBC',
|
|
|
|
},
|
|
|
|
title: '',
|
|
|
|
thumbnail: '',
|
2018-06-08 06:05:45 +02:00
|
|
|
thumbnailPath: '',
|
2018-04-02 15:53:29 +02:00
|
|
|
uploadThumbnailStatus: STATUSES.API_DOWN,
|
2018-03-26 23:32:43 +02:00
|
|
|
description: '',
|
|
|
|
language: 'en',
|
|
|
|
nsfw: false,
|
|
|
|
channel: CHANNEL_ANONYMOUS,
|
2018-05-16 01:01:53 +02:00
|
|
|
channelId: '',
|
2018-03-26 23:32:43 +02:00
|
|
|
tosAccepted: false,
|
|
|
|
name: '',
|
|
|
|
nameError: undefined,
|
|
|
|
bid: 0.1,
|
|
|
|
bidError: undefined,
|
|
|
|
licenseType: 'None',
|
|
|
|
otherLicenseDescription: '',
|
|
|
|
licenseUrl: '',
|
|
|
|
copyrightNotice: 'All rights reserved',
|
|
|
|
publishing: false,
|
|
|
|
publishSuccess: false,
|
|
|
|
publishError: undefined,
|
|
|
|
pendingPublishes: [],
|
|
|
|
};
|
|
|
|
|
|
|
|
export default handleActions(
|
|
|
|
{
|
|
|
|
[ACTIONS.UPDATE_PUBLISH_FORM]: (state, action): PublishState => {
|
|
|
|
const { data } = action;
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
...data,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
[ACTIONS.CLEAR_PUBLISH]: (state: PublishState): PublishState => {
|
|
|
|
const { pendingPublishes } = state;
|
|
|
|
return { ...defaultState, pendingPublishes };
|
|
|
|
},
|
|
|
|
[ACTIONS.PUBLISH_START]: (state: PublishState): PublishState => ({
|
|
|
|
...state,
|
|
|
|
publishing: true,
|
|
|
|
}),
|
|
|
|
[ACTIONS.PUBLISH_FAIL]: (state: PublishState): PublishState => ({
|
|
|
|
...state,
|
|
|
|
publishing: false,
|
|
|
|
}),
|
|
|
|
[ACTIONS.PUBLISH_SUCCESS]: (state: PublishState, action): PublishState => {
|
|
|
|
const { pendingPublish } = action.data;
|
|
|
|
|
2018-04-24 03:15:15 +02:00
|
|
|
// If it's an edit, don't create a pending publish
|
|
|
|
// It will take some more work to know when an edit is confirmed
|
2018-03-26 23:32:43 +02:00
|
|
|
const newPendingPublishes = state.pendingPublishes.slice();
|
2018-04-24 07:29:16 +02:00
|
|
|
if (!pendingPublish.isEdit) {
|
2018-04-24 03:15:15 +02:00
|
|
|
newPendingPublishes.push(pendingPublish);
|
|
|
|
}
|
2018-03-26 23:32:43 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
publishing: false,
|
|
|
|
pendingPublishes: newPendingPublishes,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
[ACTIONS.REMOVE_PENDING_PUBLISH]: (state: PublishState, action) => {
|
|
|
|
const { name } = action.data;
|
|
|
|
const pendingPublishes = state.pendingPublishes.filter(publish => publish.name !== name);
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
pendingPublishes,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
[ACTIONS.DO_PREPARE_EDIT]: (state: PublishState, action) => {
|
2018-06-13 05:28:06 +02:00
|
|
|
const { pendingPublishes } = state;
|
2018-03-26 23:32:43 +02:00
|
|
|
const { ...publishData } = action.data;
|
2018-06-12 07:11:17 +02:00
|
|
|
const { channel, name, uri } = publishData;
|
2018-03-26 23:32:43 +02:00
|
|
|
|
2018-06-12 07:11:17 +02:00
|
|
|
// The short uri is what is presented to the user
|
|
|
|
// The editingUri is the full uri with claim id
|
|
|
|
const shortUri = buildURI({
|
2018-03-26 23:32:43 +02:00
|
|
|
channelName: channel,
|
|
|
|
contentName: name,
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
...defaultState,
|
|
|
|
...publishData,
|
2018-06-13 05:28:06 +02:00
|
|
|
pendingPublishes,
|
2018-06-12 07:11:17 +02:00
|
|
|
editingURI: uri,
|
|
|
|
uri: shortUri,
|
2018-03-26 23:32:43 +02:00
|
|
|
};
|
|
|
|
},
|
|
|
|
},
|
|
|
|
defaultState
|
|
|
|
);
|