b20b24bdb6
* Move menu entries & add publish buttons * Save * Separate publish forms * Make new header dynamic for all screen sizes * Save some livestream creation changes * Save more livestream changes * Save * Change publish folder structure * Update paths * Change position of form elements. Again. * Move, add & delete form fields * Clean post form * Clean post form even more * Clean publish post component * Save * Add custom post form state * Move price to additional options * Adjust livestream form * Adjust headers & titles * Update key section * Adjust active header icons * Adjust toggle menu * Save * Adjust active button style * Change active button selector in header * Fix header menu links * Move price section in post form * Adjust instruction text color * Adjust replay table * Revert changes & adjust tag section * Make more form elements dynamic * Finalize additional options section * Update post form * Set mode in upload form * Update livestream form * Add clear button * Make clear button dynamic * Set upload mode * Remove new button * Clean upload form * Show disabled key on livestream form * Remove old key section * Update channel selector for publish forms * Add updated channel selector to publish forms * Add mobile links * Update mobile header * Adjust channel selector on mobile * Adjust livestream form on mobile * Adjust edit links for livestreams * Adjust edit links for posts * Adjust more edit links * Adjust channel selector * Update disabled in livestream form * Add missing change * Fix sign out function * Save * Adjust livestream page on mobile * Adjust tags section on upload page on mobile * Adjust publish links in left navigation on mobile * Add images to accepted filetypes on upload page * Add autofocus to input fields * Add autofocus to all publish forms * Save * Ignore thumbnail api status * Put active thumbnail upload label in card * Fix crashes * Fix flow * Fix licence fields * Adjust wallet in header on smaller screens * Fix channel selector line break on small screens * Fix border radius for some buttons * PublishReleaseDate: fix initial value to reflect what's actually in Redux 'undefined' is a valid value that means "use publish time", but the GUI incorrectly starts off by locking to the mounted timestamp. * Add and hide channel selector on livestream publish page * Fix channel selector on livestream setup page * Fix gif aspect ratio in channel selector * Make layout more dynamic * Fix some edit redirects * Save * Clean publishFile * Fix build errors * Fix more build errors in profile menu button * Remove console logs * Remove post form reducer * Limit publish title length to 200 characters * Remove totalRewardValue from livestreamCreate index * Remove console log * Add tooltip to replay refresh button * Remove scrollToTop function from publish forms * Adjust emty wallet value trigger and add error to livestream publish page * Disable some tabs in edit mode in livestream form * Fix maxLength typo * Remove 'as' label * Remove selectPublishFormValues * Reenable setup tab * Remove inactive line * Remove another inactive line * Remove flow fix * Update label switch logic in confirmation modal Adjust gif margin Adjust gif margin Remove navigate from edit link Remove manual updateLabels execution on init Remove editLabel function Fix labels in publish modal Adjust post livestream setup redirect Remove setOverMaxBitrate from livestream form Clean livestream publish More cleanup Update post livestream creation redirect Bring back edit tab for livestreams Update edit tab Reset form on livestream edit => clear Update label switch logic Readjust channel selector position on mobile * Make some space adjustments for mobile Update livestream edit page on mobile Update action label on publish forms in edit mode * Hide replay options in edit mode in livestream form * Update label switch logic in confirmation modal Adjust gif margin Adjust gif margin Remove navigate from edit link Remove manual updateLabels execution on init Remove editLabel function Fix labels in publish modal Adjust post livestream setup redirect Remove setOverMaxBitrate from livestream form Clean livestream publish More cleanup Update post livestream creation redirect Bring back edit tab for livestreams Update edit tab Reset form on livestream edit => clear Update label switch logic Readjust channel selector position on mobile Make some space adjustments for mobile Update livestream edit page on mobile Update action label on publish forms in edit mode Hide replay options in edit mode in livestream form * Make form titles dynamic * Remove spinner on livestream form * Remove console log * Fix double history push * Fix thumbnail status on post form * Update error message style * Handle publish error button behavior * Clean code * Fix scheduling & date picker * Fix calendar overlap * Add replay selector to livestream claim edit form * Clean code * Disable autocomplete * Show replays in edit & replay tab * Redesign replay picker * Fix design details * Save dynamic replay picker * Fix autoComplete typo * Change label text * Add upload to livestream replay form * Fix scss structure * Add comunity guideline link to publish forms * Fix error * Fix selectThumbnail index * Reset form values on replay source change * Add replay redirect to upload page * Fix publishError state change * Remove label effect from publish confirmation modal * Update labels in publish confirmation modal * Add ? to chaptersButton * Remove doPrepareEdit({ name }) * Bring upload redirect back * Adjust redirects * Save * Update edit redirects * Revert scheduling options * Replace checkboxes for replays with radio * Update form on source change * Rearrange entries in mobile navigation * Change key position on livestream setup page * Change label for livestream update without replay change * Adjust margin below label Co-authored-by: infinite-persistence <inf.persistence@gmail.com>
272 lines
7.9 KiB
JavaScript
272 lines
7.9 KiB
JavaScript
// @flow
|
|
import { handleActions } from 'util/redux-utils';
|
|
import { buildURI } from 'util/lbryURI';
|
|
import { serializeFileObj } from 'util/file';
|
|
import {
|
|
tusLockAndNotify,
|
|
tusUnlockAndNotify,
|
|
tusRemoveAndNotify,
|
|
tusClearRemovedUploads,
|
|
tusClearLockedUploads,
|
|
} from 'util/tus';
|
|
import * as ACTIONS from 'constants/action_types';
|
|
import * as THUMBNAIL_STATUSES from 'constants/thumbnail_upload_statuses';
|
|
import { CHANNEL_ANONYMOUS } from 'constants/claim';
|
|
|
|
// This is the old key formula. Retain it for now to allow users to delete
|
|
// any pending uploads. Can be removed from January 2022 onwards.
|
|
const getOldKeyFromParam = (params) => `${params.name}#${params.channel || 'anonymous'}`;
|
|
|
|
type PublishState = {
|
|
editingURI: ?string,
|
|
fileText: ?string,
|
|
filePath: ?string,
|
|
remoteFileUrl: ?string,
|
|
contentIsFree: boolean,
|
|
fileDur: number,
|
|
fileSize: number,
|
|
fileVid: boolean,
|
|
fee: {
|
|
amount: number,
|
|
currency: string,
|
|
},
|
|
title: string,
|
|
thumbnail_url: string,
|
|
thumbnailPath: string,
|
|
uploadThumbnailStatus: string,
|
|
thumbnailError: ?boolean,
|
|
description: string,
|
|
language: string,
|
|
releaseTime: ?number,
|
|
releaseTimeEdited: ?number,
|
|
releaseAnytime: boolean,
|
|
channel: string,
|
|
channelId: ?string,
|
|
name: string,
|
|
nameError: ?string,
|
|
bid: number,
|
|
bidError: ?string,
|
|
otherLicenseDescription: string,
|
|
licenseUrl: string,
|
|
tags: Array<string>,
|
|
optimize: boolean,
|
|
useLBRYUploader: boolean,
|
|
currentUploads: { [key: string]: FileUploadItem },
|
|
isMarkdownPost: boolean,
|
|
isLivestreamPublish: boolean,
|
|
publishError?: boolean,
|
|
};
|
|
|
|
const defaultState: PublishState = {
|
|
editingURI: undefined,
|
|
fileText: '',
|
|
filePath: undefined,
|
|
fileDur: 0,
|
|
fileSize: 0,
|
|
fileVid: false,
|
|
remoteFileUrl: undefined,
|
|
contentIsFree: true,
|
|
fee: {
|
|
amount: 1,
|
|
currency: 'LBC',
|
|
},
|
|
title: '',
|
|
thumbnail_url: '',
|
|
thumbnailPath: '',
|
|
uploadThumbnailStatus: THUMBNAIL_STATUSES.API_DOWN,
|
|
thumbnailError: undefined,
|
|
description: '',
|
|
language: '',
|
|
releaseTime: undefined,
|
|
releaseTimeEdited: undefined,
|
|
releaseTimeError: false,
|
|
releaseAnytime: false,
|
|
nsfw: false,
|
|
channel: CHANNEL_ANONYMOUS,
|
|
channelId: '',
|
|
name: '',
|
|
nameError: undefined,
|
|
bid: 0.01,
|
|
bidError: undefined,
|
|
licenseType: 'None',
|
|
otherLicenseDescription: 'All rights reserved',
|
|
licenseUrl: '',
|
|
tags: [],
|
|
publishing: false,
|
|
publishSuccess: false,
|
|
publishError: undefined,
|
|
optimize: false,
|
|
useLBRYUploader: false,
|
|
currentUploads: {},
|
|
isMarkdownPost: false,
|
|
isLivestreamPublish: false,
|
|
};
|
|
|
|
export const publishReducer = handleActions(
|
|
{
|
|
[ACTIONS.UPDATE_PUBLISH_FORM]: (state, action): PublishState => {
|
|
const { data } = action;
|
|
return {
|
|
...state,
|
|
...data,
|
|
};
|
|
},
|
|
[ACTIONS.CLEAR_PUBLISH]: (state: PublishState): PublishState => ({
|
|
...defaultState,
|
|
uri: undefined,
|
|
channel: state.channel,
|
|
bid: state.bid,
|
|
optimize: state.optimize,
|
|
language: state.language,
|
|
currentUploads: state.currentUploads,
|
|
}),
|
|
[ACTIONS.PUBLISH_START]: (state: PublishState): PublishState => ({
|
|
...state,
|
|
publishing: true,
|
|
publishSuccess: false,
|
|
}),
|
|
[ACTIONS.PUBLISH_FAIL]: (state: PublishState): PublishState => ({
|
|
...state,
|
|
publishing: false,
|
|
}),
|
|
[ACTIONS.PUBLISH_SUCCESS]: (state: PublishState): PublishState => ({
|
|
...state,
|
|
publishing: false,
|
|
publishSuccess: true,
|
|
}),
|
|
[ACTIONS.DO_PREPARE_EDIT]: (state: PublishState, action) => {
|
|
const { ...publishData } = action.data;
|
|
const { channel, name, uri } = publishData;
|
|
|
|
// The short uri is what is presented to the user
|
|
// The editingUri is the full uri with claim id
|
|
const shortUri = buildURI({
|
|
channelName: channel,
|
|
streamName: name,
|
|
});
|
|
|
|
return {
|
|
...defaultState,
|
|
...publishData,
|
|
editingURI: uri,
|
|
uri: shortUri,
|
|
currentUploads: state.currentUploads,
|
|
};
|
|
},
|
|
[ACTIONS.UPDATE_UPLOAD_ADD]: (state: PublishState, action) => {
|
|
const { file, params, uploader } = action.data;
|
|
const currentUploads = Object.assign({}, state.currentUploads);
|
|
|
|
currentUploads[params.guid] = {
|
|
file,
|
|
fileFingerprint: file ? serializeFileObj(file) : undefined, // TODO: get hash instead?
|
|
progress: '0',
|
|
params,
|
|
uploader,
|
|
resumable: !(uploader instanceof XMLHttpRequest),
|
|
};
|
|
|
|
return { ...state, currentUploads };
|
|
},
|
|
[ACTIONS.UPDATE_UPLOAD_PROGRESS]: (state: PublishState, action) => {
|
|
const { guid, progress, status } = action.data;
|
|
const key = guid;
|
|
const currentUploads = Object.assign({}, state.currentUploads);
|
|
|
|
if (guid === 'force--update') {
|
|
return { ...state, currentUploads };
|
|
} else if (guid === 'refresh--lock') {
|
|
// Re-lock all uploads that are in progress under our tab.
|
|
const uploadKeys = Object.keys(currentUploads);
|
|
uploadKeys.forEach((k) => {
|
|
if (currentUploads[k].uploader) {
|
|
tusLockAndNotify(k);
|
|
}
|
|
});
|
|
}
|
|
|
|
if (!currentUploads[key]) {
|
|
if (status === 'error' || status === 'conflict') {
|
|
return { ...state, publishError: true };
|
|
} else {
|
|
return state;
|
|
}
|
|
}
|
|
|
|
if (progress) {
|
|
currentUploads[key].progress = progress;
|
|
delete currentUploads[key].status;
|
|
|
|
if (currentUploads[key].uploader.url) {
|
|
// TUS has finally obtained an upload url from the server...
|
|
if (!currentUploads[key].params.uploadUrl) {
|
|
// ... Stash that to check later when resuming.
|
|
// Ignoring immutable-update requirement (probably doesn't matter to the GUI).
|
|
currentUploads[key].params.uploadUrl = currentUploads[key].uploader.url;
|
|
}
|
|
|
|
// ... lock this tab as the active uploader.
|
|
tusLockAndNotify(key);
|
|
}
|
|
} else if (status) {
|
|
currentUploads[key].status = status;
|
|
if (status === 'error' || status === 'conflict') {
|
|
delete currentUploads[key].uploader;
|
|
}
|
|
}
|
|
|
|
return { ...state, currentUploads };
|
|
},
|
|
[ACTIONS.UPDATE_UPLOAD_REMOVE]: (state: PublishState, action) => {
|
|
const { guid, params } = action.data;
|
|
const key = guid || getOldKeyFromParam(params);
|
|
|
|
if (state.currentUploads[key]) {
|
|
const currentUploads = Object.assign({}, state.currentUploads);
|
|
delete currentUploads[key];
|
|
tusUnlockAndNotify(key);
|
|
tusRemoveAndNotify(key);
|
|
|
|
return { ...state, currentUploads };
|
|
}
|
|
|
|
return state;
|
|
},
|
|
[ACTIONS.REHYDRATE]: (state: PublishState, action) => {
|
|
if (action && action.payload && action.payload.publish) {
|
|
const newPublish = { ...action.payload.publish };
|
|
|
|
// Cleanup for 'publish::currentUploads'
|
|
if (newPublish.currentUploads) {
|
|
const uploadKeys = Object.keys(newPublish.currentUploads);
|
|
if (uploadKeys.length > 0) {
|
|
// Clear uploader and corrupted params
|
|
uploadKeys.forEach((key) => {
|
|
const params = newPublish.currentUploads[key].params;
|
|
if (!params || Object.keys(params).length === 0) {
|
|
// The intended payload for the API is corrupted, so no point
|
|
// retaining. Remove from the pending-uploads list.
|
|
delete newPublish.currentUploads[key];
|
|
} else {
|
|
// The data is still good, so we can resume upload. We just need
|
|
// to delete the previous reference of the tus-uploader (no
|
|
// longer functional, will be re-created). An empty 'uploader'
|
|
// also tells the GUI that we just rebooted.
|
|
delete newPublish.currentUploads[key].uploader;
|
|
}
|
|
});
|
|
} else {
|
|
tusClearRemovedUploads();
|
|
}
|
|
|
|
tusClearLockedUploads();
|
|
}
|
|
|
|
return newPublish;
|
|
}
|
|
|
|
return state;
|
|
},
|
|
},
|
|
defaultState
|
|
);
|