track when publishState.hasChanged; only update when true
This commit is contained in:
parent
e9c60f652f
commit
3378e4289f
9 changed files with 43 additions and 16 deletions
|
@ -20,6 +20,13 @@ export function setUpdateTrue () {
|
|||
};
|
||||
}
|
||||
|
||||
export function setHasChanged (status) {
|
||||
return {
|
||||
type: actions.SET_HAS_CHANGED,
|
||||
data: status,
|
||||
};
|
||||
}
|
||||
|
||||
export function updateMetadata (name, value) {
|
||||
return {
|
||||
type: actions.METADATA_UPDATE,
|
||||
|
|
|
@ -12,3 +12,4 @@ export const PUBLISH_START = 'PUBLISH_START';
|
|||
export const CLAIM_AVAILABILITY = 'CLAIM_AVAILABILITY';
|
||||
export const SET_UPDATE_TRUE = 'SET_UPDATE_TRUE';
|
||||
export const ABANDON_CLAIM = 'ABANDON_CLAIM';
|
||||
export const SET_HAS_CHANGED = 'SET_HAS_CHANGED';
|
||||
|
|
|
@ -5,9 +5,10 @@ import View from './view';
|
|||
|
||||
const mapStateToProps = ({ show, publish }) => {
|
||||
return {
|
||||
file : publish.file,
|
||||
file: publish.file,
|
||||
isUpdate: publish.isUpdate,
|
||||
asset : selectAsset(show),
|
||||
hasChanged: publish.hasChanged,
|
||||
asset: selectAsset(show),
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -32,8 +32,8 @@ class PublishDetails extends React.Component {
|
|||
}
|
||||
}
|
||||
onCancel () {
|
||||
const { isUpdate, clearFile, history } = this.props;
|
||||
if (isUpdate) {
|
||||
const { isUpdate, hasChanged, clearFile, history } = this.props;
|
||||
if (isUpdate || !hasChanged) {
|
||||
history.push('/');
|
||||
} else {
|
||||
if (confirm(SAVE)) {
|
||||
|
|
|
@ -12,9 +12,10 @@ const mapStateToProps = props => {
|
|||
}
|
||||
return {
|
||||
disabled: publish.disabled,
|
||||
file : publish.file,
|
||||
status : publish.status.status,
|
||||
file: publish.file,
|
||||
status: publish.status.status,
|
||||
isUpdate: publish.isUpdate,
|
||||
hasChanged: publish.hasChanged,
|
||||
uri,
|
||||
};
|
||||
};
|
||||
|
|
|
@ -8,7 +8,7 @@ import { SAVE } from '../../constants/confirmation_messages';
|
|||
|
||||
class PublishTool extends React.Component {
|
||||
render () {
|
||||
const {disabled, file, isUpdate, uri, status} = this.props;
|
||||
const {disabled, file, isUpdate, hasChanged, uri, status} = this.props;
|
||||
if (disabled) {
|
||||
return (
|
||||
<PublishDisabledMessage />
|
||||
|
@ -23,6 +23,7 @@ class PublishTool extends React.Component {
|
|||
return (
|
||||
<React.Fragment>
|
||||
<Prompt
|
||||
when={hasChanged}
|
||||
message={SAVE}
|
||||
/>
|
||||
<PublishPreview isUpdate={isUpdate} uri={uri} />
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { connect } from 'react-redux';
|
||||
import { setUpdateTrue, updateMetadata, clearFile } from '../../actions/publish';
|
||||
import { setUpdateTrue, setHasChanged, updateMetadata, clearFile } from '../../actions/publish';
|
||||
import { onHandleShowPageUri } from '../../actions/show';
|
||||
import { selectAsset } from '../../selectors/show';
|
||||
import View from './view';
|
||||
|
@ -17,6 +17,7 @@ const mapDispatchToProps = {
|
|||
updateMetadata,
|
||||
onHandleShowPageUri,
|
||||
setUpdateTrue,
|
||||
setHasChanged,
|
||||
clearFile,
|
||||
};
|
||||
|
||||
|
|
|
@ -5,12 +5,13 @@ import PublishTool from '@containers/PublishTool';
|
|||
|
||||
class EditPage extends React.Component {
|
||||
componentDidMount () {
|
||||
const {asset, match, onHandleShowPageUri, clearFile, setUpdateTrue, updateMetadata} = this.props;
|
||||
const {asset, match, onHandleShowPageUri, setUpdateTrue, setHasChanged, updateMetadata} = this.props;
|
||||
onHandleShowPageUri(match.params);
|
||||
setUpdateTrue();
|
||||
if (asset) {
|
||||
['title', 'description', 'license', 'nsfw'].forEach(meta => updateMetadata(meta, asset.claimData[meta]));
|
||||
}
|
||||
setHasChanged(false);
|
||||
}
|
||||
componentWillUnmount () {
|
||||
this.props.clearFile();
|
||||
|
|
|
@ -41,7 +41,8 @@ const initialState = {
|
|||
license : '',
|
||||
nsfw : false,
|
||||
},
|
||||
isUpdate : false,
|
||||
isUpdate: false,
|
||||
hasChanged: false,
|
||||
thumbnail: null,
|
||||
thumbnailChannel,
|
||||
thumbnailChannelId,
|
||||
|
@ -52,6 +53,7 @@ export default function (state = initialState, action) {
|
|||
case actions.FILE_SELECTED:
|
||||
return Object.assign({}, state.isUpdate ? state : initialState, { // note: clears to initial state
|
||||
file: action.data,
|
||||
hasChanged: true,
|
||||
});
|
||||
case actions.FILE_CLEAR:
|
||||
return initialState;
|
||||
|
@ -60,14 +62,17 @@ export default function (state = initialState, action) {
|
|||
metadata: Object.assign({}, state.metadata, {
|
||||
[action.data.name]: action.data.value,
|
||||
}),
|
||||
hasChanged: true,
|
||||
});
|
||||
case actions.CLAIM_UPDATE:
|
||||
return Object.assign({}, state, {
|
||||
claim: action.data,
|
||||
hasChanged: true,
|
||||
});
|
||||
case actions.SET_PUBLISH_IN_CHANNEL:
|
||||
return Object.assign({}, state, {
|
||||
publishInChannel: action.channel,
|
||||
hasChanged: true,
|
||||
});
|
||||
case actions.PUBLISH_STATUS_UPDATE:
|
||||
return Object.assign({}, state, {
|
||||
|
@ -84,17 +89,26 @@ export default function (state = initialState, action) {
|
|||
selectedChannel: action.data,
|
||||
});
|
||||
case actions.TOGGLE_METADATA_INPUTS:
|
||||
return Object.assign({}, state, {
|
||||
return {
|
||||
...state,
|
||||
showMetadataInputs: action.data,
|
||||
});
|
||||
};
|
||||
case actions.THUMBNAIL_NEW:
|
||||
return Object.assign({}, state, {
|
||||
return {
|
||||
...state,
|
||||
thumbnail: action.data,
|
||||
});
|
||||
hasChanged: true,
|
||||
};
|
||||
case actions.SET_UPDATE_TRUE:
|
||||
return Object.assign({}, state, {
|
||||
return {
|
||||
...state,
|
||||
isUpdate: true,
|
||||
});
|
||||
};
|
||||
case actions.SET_HAS_CHANGED:
|
||||
return {
|
||||
...state,
|
||||
hasChanged: action.data,
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue