separated constants into own folder

This commit is contained in:
bill bittner 2018-01-16 11:38:37 -08:00
parent 1a77110df7
commit c072f8846b
5 changed files with 42 additions and 43 deletions

View file

@ -1,30 +1,22 @@
// export action types
export const FILE_SELECTED = 'FILE_SELECTED';
export const FILE_CLEAR = 'FILE_CLEAR';
export const METADATA_UPDATE = 'METADATA_UPDATE';
export const CLAIM_UPDATE = 'CLAIM_UPDATE';
export const CHANNEL_UPDATE = 'CHANNEL_UPDATE';
export const SET_PUBLISH_IN_CHANNEL = 'SET_PUBLISH_IN_CHANNEL';
export const PUBLISH_STATUS_UPDATE = 'PUBLISH_STATUS_UPDATE';
export const ERROR_UPDATE = 'ERROR_UPDATE';
import * as actions from '../constants/action_types.js';
// export action creators
export function selectFile (file) {
return {
type: FILE_SELECTED,
type: actions.FILE_SELECTED,
file: file,
};
};
export function clearFile () {
return {
type: FILE_CLEAR,
type: actions.FILE_CLEAR,
};
};
export function updateMetadata (name, value) {
return {
type: METADATA_UPDATE,
type: actions.METADATA_UPDATE,
name,
value,
};
@ -32,14 +24,14 @@ export function updateMetadata (name, value) {
export function updateClaim (value) {
return {
type: CLAIM_UPDATE,
type: actions.CLAIM_UPDATE,
value,
};
};
export function updateLoggedInChannel (name, shortId, longId) {
return {
type: CHANNEL_UPDATE,
type: actions.CHANNEL_UPDATE,
name,
shortId,
longId,
@ -48,14 +40,14 @@ export function updateLoggedInChannel (name, shortId, longId) {
export function setPublishInChannel (channel) {
return {
type: SET_PUBLISH_IN_CHANNEL,
type: actions.SET_PUBLISH_IN_CHANNEL,
channel,
};
};
export function updatePublishStatus (status, message) {
return {
type: PUBLISH_STATUS_UPDATE,
type: actions.PUBLISH_STATUS_UPDATE,
status,
message,
};
@ -63,7 +55,7 @@ export function updatePublishStatus (status, message) {
export function updateError (name, value) {
return {
type: ERROR_UPDATE,
type: actions.ERROR_UPDATE,
name,
value,
};

View file

@ -0,0 +1,9 @@
// export action types
export const FILE_SELECTED = 'FILE_SELECTED';
export const FILE_CLEAR = 'FILE_CLEAR';
export const METADATA_UPDATE = 'METADATA_UPDATE';
export const CLAIM_UPDATE = 'CLAIM_UPDATE';
export const CHANNEL_UPDATE = 'CHANNEL_UPDATE';
export const SET_PUBLISH_IN_CHANNEL = 'SET_PUBLISH_IN_CHANNEL';
export const PUBLISH_STATUS_UPDATE = 'PUBLISH_STATUS_UPDATE';
export const ERROR_UPDATE = 'ERROR_UPDATE';

View file

@ -0,0 +1,6 @@
// publishing states
export const LOAD_START = 'LOAD_START';
export const LOADING = 'LOADING';
export const PUBLISHING = 'PUBLISHING';
export const SUCCESS = 'SUCCESS';
export const FAILED = 'FAILED';

View file

@ -7,15 +7,10 @@ import PublishThumbnailInput from './PublishThumbnailInput.jsx';
import PublishMetadataInputs from './PublishMetadataInputs.jsx';
import AnonymousOrChannelSelect from './ChannelSelect.jsx';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import { getCookie } from '../utils/cookies.js';
import {selectFile, clearFile, updateLoggedInChannel, updatePublishStatus, updateError} from '../actions';
import PropTypes from 'prop-types';
const LOAD_START = 'LOAD_START';
const LOADING = 'LOADING';
const PUBLISHING = 'PUBLISHING';
const SUCCESS = 'SUCCESS';
const FAILED = 'FAILED';
import * as states from '../constants/publishing_states';
class PublishForm extends React.Component {
constructor (props) {
@ -60,18 +55,18 @@ class PublishForm extends React.Component {
const fd = this.appendDataToFormData(file, metadata);
const that = this;
xhr.upload.addEventListener('loadstart', function () {
that.props.onPublishStatusChange(LOAD_START, 'upload started');
that.props.onPublishStatusChange(states.LOAD_START, 'upload started');
});
xhr.upload.addEventListener('progress', function (e) {
if (e.lengthComputable) {
const percentage = Math.round((e.loaded * 100) / e.total);
console.log('progress:', percentage);
that.props.onPublishStatusChange(LOADING, `${percentage}%`);
that.props.onPublishStatusChange(states.LOADING, `${percentage}%`);
}
}, false);
xhr.upload.addEventListener('load', function () {
console.log('loaded 100%');
that.props.onPublishStatusChange(PUBLISHING, null);
that.props.onPublishStatusChange(states.PUBLISHING, null);
}, false);
xhr.open('POST', uri, true);
xhr.onreadystatechange = function () {
@ -80,12 +75,12 @@ class PublishForm extends React.Component {
if (xhr.status === 200) {
console.log('publish complete!');
const url = JSON.parse(xhr.response).message.url;
that.props.onPublishStatusChange(SUCCESS, url);
that.props.onPublishStatusChange(states.SUCCESS, url);
window.location = url;
} else if (xhr.status === 502) {
that.props.onPublishStatusChange(FAILED, 'Spee.ch was not able to get a response from the LBRY network.');
that.props.onPublishStatusChange(states.FAILED, 'Spee.ch was not able to get a response from the LBRY network.');
} else {
that.props.onPublishStatusChange(FAILED, JSON.parse(xhr.response).message);
that.props.onPublishStatusChange(states.FAILED, JSON.parse(xhr.response).message);
}
}
};
@ -248,7 +243,7 @@ PublishForm.propTypes = {
onFileClear : PropTypes.func.isRequired,
onChannelLogin : PropTypes.func.isRequired,
onPublishStatusChange: PropTypes.func.isRequired,
onPublishSubmitError: PropTypes.func.isRequired,
onPublishSubmitError : PropTypes.func.isRequired,
};
export default connect(mapStateToProps, mapDispatchToProps)(PublishForm);

View file

@ -1,7 +1,4 @@
import {
CHANNEL_UPDATE, CLAIM_UPDATE, ERROR_UPDATE, FILE_CLEAR, FILE_SELECTED, METADATA_UPDATE, PUBLISH_STATUS_UPDATE,
SET_PUBLISH_IN_CHANNEL,
} from '../actions';
import * as actions from '../constants/action_types';
const initialState = {
loggedInChannel: {
@ -36,23 +33,23 @@ Reducers describe how the application's state changes in response to actions
export default function (state = initialState, action) {
switch (action.type) {
case FILE_SELECTED:
case actions.FILE_SELECTED:
return Object.assign({}, state, {
file: action.file,
});
case FILE_CLEAR:
case actions.FILE_CLEAR:
return initialState;
case METADATA_UPDATE:
case actions.METADATA_UPDATE:
return Object.assign({}, state, {
metadata: Object.assign({}, state.metadata, {
[action.name]: action.value,
}),
});
case CLAIM_UPDATE:
case actions.CLAIM_UPDATE:
return Object.assign({}, state, {
claim: action.value,
});
case CHANNEL_UPDATE:
case actions.CHANNEL_UPDATE:
return Object.assign({}, state, {
loggedInChannel: {
name : action.name,
@ -60,18 +57,18 @@ export default function (state = initialState, action) {
longId : action.longId,
},
});
case SET_PUBLISH_IN_CHANNEL:
case actions.SET_PUBLISH_IN_CHANNEL:
return Object.assign({}, state, {
publishInChannel: action.channel,
});
case PUBLISH_STATUS_UPDATE:
case actions.PUBLISH_STATUS_UPDATE:
return Object.assign({}, state, {
status: Object.assign({}, state.status, {
status : action.status,
message: action.message,
}),
});
case ERROR_UPDATE:
case actions.ERROR_UPDATE:
return Object.assign({}, state, {
error: Object.assign({}, state.error, {
[action.name]: action.value,