lbry-desktop/src/renderer/redux/reducers/publish.js

164 lines
3.6 KiB
JavaScript
Raw Normal View History

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';
import * as THUMBNAIL_STATUSES from 'constants/thumbnail_upload_statuses';
2018-03-26 23:32:43 +02:00
import { CHANNEL_ANONYMOUS } from 'constants/claim';
2018-10-13 18:42:02 +02:00
import type { Source } from 'types/claim';
2018-03-26 23:32:43 +02:00
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,
uploadThumbnailStatus: string,
2018-03-26 23:32:43 +02:00
description: string,
language: string,
tosAccepted: boolean,
channel: string,
channelId: ?string,
2018-03-26 23:32:43 +02:00
name: string,
nameError: ?string,
bid: number,
bidError: ?string,
otherLicenseDescription: string,
licenseUrl: string,
};
export type UpdatePublishFormData = {
filePath?: string,
contentIsFree?: boolean,
price?: {
amount: number,
currency: string,
},
title?: string,
thumbnail?: string,
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,
channelId?: string,
2018-03-26 23:32:43 +02:00
name?: string,
nameError?: string,
bid?: number,
bidError?: string,
otherLicenseDescription?: string,
licenseUrl?: string,
2018-10-13 17:49:47 +02:00
licenseType?: string,
uri?: string,
2018-03-26 23:32:43 +02:00
};
export type UpdatePublishFormAction = {
type: ACTIONS.UPDATE_PUBLISH_FORM | ACTIONS.DO_PREPARE_EDIT,
data: UpdatePublishFormData,
};
export type PublishParams = {
2018-10-13 17:49:47 +02:00
name?: string,
bid?: number,
filePath?: string,
2018-03-26 23:32:43 +02:00
description: ?string,
language: string,
2018-10-13 17:49:47 +02:00
publishingLicense?: string,
publishingLicenseUrl?: string,
2018-03-26 23:32:43 +02:00
thumbnail: ?string,
nsfw: boolean,
channel: string,
2018-10-13 17:49:47 +02:00
channelId?: string,
2018-03-26 23:32:43 +02:00
title: string,
contentIsFree: boolean,
2018-10-13 17:49:47 +02:00
uri?: string,
2018-03-26 23:32:43 +02:00
license: ?string,
licenseUrl: ?string,
price: {
currency: string,
amount: number,
},
2018-10-13 18:42:02 +02:00
sources?: Source,
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: '',
uploadThumbnailStatus: THUMBNAIL_STATUSES.API_DOWN,
2018-03-26 23:32:43 +02:00
description: '',
language: 'en',
nsfw: false,
channel: CHANNEL_ANONYMOUS,
channelId: '',
2018-03-26 23:32:43 +02:00
tosAccepted: false,
name: '',
nameError: undefined,
bid: 0.1,
bidError: undefined,
licenseType: 'None',
otherLicenseDescription: 'All rights reserved',
2018-03-26 23:32:43 +02:00
licenseUrl: '',
publishing: false,
publishSuccess: false,
publishError: undefined,
};
export default handleActions(
{
[ACTIONS.UPDATE_PUBLISH_FORM]: (state, action): PublishState => {
const { data } = action;
return {
...state,
...data,
};
},
2018-10-26 06:20:18 +02:00
[ACTIONS.CLEAR_PUBLISH]: (): PublishState => ({
...defaultState,
}),
2018-03-26 23:32:43 +02:00
[ACTIONS.PUBLISH_START]: (state: PublishState): PublishState => ({
...state,
publishing: true,
}),
[ACTIONS.PUBLISH_FAIL]: (state: PublishState): PublishState => ({
...state,
publishing: false,
}),
2018-10-26 06:20:18 +02:00
[ACTIONS.PUBLISH_SUCCESS]: (state: PublishState): PublishState => ({
...state,
publishing: false,
}),
2018-03-26 23:32:43 +02:00
[ACTIONS.DO_PREPARE_EDIT]: (state: PublishState, action) => {
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-12 07:11:17 +02:00
editingURI: uri,
uri: shortUri,
2018-03-26 23:32:43 +02:00
};
},
},
defaultState
);