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-06-14 22:28:50 +02:00
|
|
|
import * as THUMBNAIL_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,
|
2019-05-10 08:27:51 +02:00
|
|
|
fee: {
|
2018-03-26 23:32:43 +02:00
|
|
|
amount: number,
|
|
|
|
currency: string,
|
|
|
|
},
|
|
|
|
title: string,
|
2019-04-24 16:02:08 +02:00
|
|
|
thumbnail_url: 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,
|
|
|
|
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,
|
2019-06-28 09:27:55 +02:00
|
|
|
tags: Array<string>,
|
2018-03-26 23:32:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const defaultState: PublishState = {
|
|
|
|
editingURI: undefined,
|
|
|
|
filePath: undefined,
|
|
|
|
contentIsFree: true,
|
2019-05-10 08:27:51 +02:00
|
|
|
fee: {
|
2018-03-26 23:32:43 +02:00
|
|
|
amount: 1,
|
|
|
|
currency: 'LBC',
|
|
|
|
},
|
|
|
|
title: '',
|
2019-04-24 16:02:08 +02:00
|
|
|
thumbnail_url: '',
|
2018-06-08 06:05:45 +02:00
|
|
|
thumbnailPath: '',
|
2018-06-14 22:28:50 +02:00
|
|
|
uploadThumbnailStatus: THUMBNAIL_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
|
|
|
name: '',
|
|
|
|
nameError: undefined,
|
|
|
|
bid: 0.1,
|
|
|
|
bidError: undefined,
|
|
|
|
licenseType: 'None',
|
2018-10-03 21:00:06 +02:00
|
|
|
otherLicenseDescription: 'All rights reserved',
|
2018-03-26 23:32:43 +02:00
|
|
|
licenseUrl: '',
|
2019-06-28 09:27:55 +02:00
|
|
|
tags: [],
|
2018-03-26 23:32:43 +02:00
|
|
|
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
|
|
|
|
);
|