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

108 lines
2.5 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';
type PublishState = {
editingURI: ?string,
filePath: ?string,
contentIsFree: boolean,
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,
uploadThumbnailStatus: string,
2018-03-26 23:32:43 +02:00
description: string,
language: string,
channel: string,
channelId: ?string,
2018-03-26 23:32:43 +02:00
name: string,
nameError: ?string,
bid: number,
bidError: ?string,
otherLicenseDescription: string,
licenseUrl: string,
tags: Array<string>,
2018-03-26 23:32:43 +02:00
};
const defaultState: PublishState = {
editingURI: undefined,
filePath: undefined,
contentIsFree: true,
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: '',
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
name: '',
nameError: undefined,
bid: 0.1,
bidError: undefined,
licenseType: 'None',
otherLicenseDescription: 'All rights reserved',
2018-03-26 23:32:43 +02:00
licenseUrl: '',
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
);