Add <MissingIndicator /> when status or account are not found, skip alerts

for those errors
main
Eugen Rochko 2017-02-26 23:06:27 +01:00
parent 4bb8ff7c8e
commit 4fbdf100c4
8 changed files with 27 additions and 36 deletions

View File

@ -138,7 +138,8 @@ export function fetchAccountFail(id, error) {
return { return {
type: ACCOUNT_FETCH_FAIL, type: ACCOUNT_FETCH_FAIL,
id, id,
error error,
skipAlert: true
}; };
}; };
@ -231,7 +232,8 @@ export function fetchAccountTimelineFail(id, error, skipLoading) {
type: ACCOUNT_TIMELINE_FETCH_FAIL, type: ACCOUNT_TIMELINE_FETCH_FAIL,
id, id,
error, error,
skipLoading skipLoading,
skipAlert: error.response.status === 404
}; };
}; };

View File

@ -46,6 +46,7 @@ export function fetchStatusCardFail(id, error) {
type: STATUS_CARD_FETCH_FAIL, type: STATUS_CARD_FETCH_FAIL,
id, id,
error, error,
skipLoading: true skipLoading: true,
skipAlert: true
}; };
}; };

View File

@ -28,6 +28,7 @@ export function fetchStatus(id) {
const skipLoading = getState().getIn(['statuses', id], null) !== null; const skipLoading = getState().getIn(['statuses', id], null) !== null;
dispatch(fetchContext(id)); dispatch(fetchContext(id));
dispatch(fetchStatusCard(id));
if (skipLoading) { if (skipLoading) {
return; return;
@ -56,7 +57,8 @@ export function fetchStatusFail(id, error, skipLoading) {
type: STATUS_FETCH_FAIL, type: STATUS_FETCH_FAIL,
id, id,
error, error,
skipLoading skipLoading,
skipAlert: true
}; };
}; };
@ -101,14 +103,13 @@ export function fetchContext(id) {
api(getState).get(`/api/v1/statuses/${id}/context`).then(response => { api(getState).get(`/api/v1/statuses/${id}/context`).then(response => {
dispatch(fetchContextSuccess(id, response.data.ancestors, response.data.descendants)); dispatch(fetchContextSuccess(id, response.data.ancestors, response.data.descendants));
dispatch(fetchStatusCard(id));
}).catch(error => { }).catch(error => {
if (error.response.status == 404){ if (error.response.status === 404) {
dispatch(deleteStatusSuccess(id));
dispatch(deleteFromTimelines(id)); dispatch(deleteFromTimelines(id));
}else{
dispatch(fetchContextFail(id, error));
} }
dispatch(fetchContextFail(id, error));
}); });
}; };
}; };
@ -134,6 +135,7 @@ export function fetchContextFail(id, error) {
return { return {
type: CONTEXT_FETCH_FAIL, type: CONTEXT_FETCH_FAIL,
id, id,
error error,
skipAlert: true
}; };
}; };

View File

@ -1,16 +0,0 @@
import { FormattedMessage } from 'react-intl';
const style = {
textAlign: 'center',
fontSize: '16px',
fontWeight: '500',
paddingTop: '120px'
};
const StatusNotFound = () => (
<div className='status-not-found-indicator' style={style}>
<FormattedMessage id='status_not_found_indicator.label' defaultMessage='Status Not Found' />
</div>
);
export default StatusNotFound;

View File

@ -2,6 +2,7 @@ import PureRenderMixin from 'react-addons-pure-render-mixin';
import ImmutablePropTypes from 'react-immutable-proptypes'; import ImmutablePropTypes from 'react-immutable-proptypes';
import InnerHeader from '../../account/components/header'; import InnerHeader from '../../account/components/header';
import ActionBar from '../../account/components/action_bar'; import ActionBar from '../../account/components/action_bar';
import MissingIndicator from '../../../components/missing_indicator';
const Header = React.createClass({ const Header = React.createClass({
contextTypes: { contextTypes: {
@ -9,7 +10,7 @@ const Header = React.createClass({
}, },
propTypes: { propTypes: {
account: ImmutablePropTypes.map.isRequired, account: ImmutablePropTypes.map,
me: React.PropTypes.number.isRequired, me: React.PropTypes.number.isRequired,
onFollow: React.PropTypes.func.isRequired, onFollow: React.PropTypes.func.isRequired,
onBlock: React.PropTypes.func.isRequired, onBlock: React.PropTypes.func.isRequired,
@ -39,8 +40,8 @@ const Header = React.createClass({
render () { render () {
const { account, me } = this.props; const { account, me } = this.props;
if (!account) { if (account === null) {
return null; return <MissingIndicator />;
} }
return ( return (

View File

@ -4,7 +4,7 @@ import ImmutablePropTypes from 'react-immutable-proptypes';
import { fetchStatus } from '../../actions/statuses'; import { fetchStatus } from '../../actions/statuses';
import Immutable from 'immutable'; import Immutable from 'immutable';
import EmbeddedStatus from '../../components/status'; import EmbeddedStatus from '../../components/status';
import StatusNotFound from '../../components/status_not_found'; import MissingIndicator from '../../components/missing_indicator';
import DetailedStatus from './components/detailed_status'; import DetailedStatus from './components/detailed_status';
import ActionBar from './components/action_bar'; import ActionBar from './components/action_bar';
import Column from '../ui/components/column'; import Column from '../ui/components/column';
@ -118,7 +118,7 @@ const Status = React.createClass({
return ( return (
<Column> <Column>
<ColumnBackButton /> <ColumnBackButton />
<StatusNotFound /> <MissingIndicator />
</Column> </Column>
); );
} }

View File

@ -5,7 +5,7 @@ const defaultFailSuffix = 'FAIL';
export default function errorsMiddleware() { export default function errorsMiddleware() {
return ({ dispatch }) => next => action => { return ({ dispatch }) => next => action => {
if (action.type) { if (action.type && !action.skipAlert) {
const isFail = new RegExp(`${defaultFailSuffix}$`, 'g'); const isFail = new RegExp(`${defaultFailSuffix}$`, 'g');
const isSuccess = new RegExp(`${defaultSuccessSuffix}$`, 'g'); const isSuccess = new RegExp(`${defaultSuccessSuffix}$`, 'g');

View File

@ -39,14 +39,15 @@ const normalizeStatus = (state, status) => {
return state; return state;
} }
status.account = status.account.id; const normalStatus = { ...status };
normalStatus.account = status.account.id;
if (status.reblog && status.reblog.id) { if (status.reblog && status.reblog.id) {
state = normalizeStatus(state, status.reblog); state = normalizeStatus(state, status.reblog);
status.reblog = status.reblog.id; normalStatus.reblog = status.reblog.id;
} }
return state.update(status.id, Immutable.Map(), map => map.mergeDeep(Immutable.fromJS(status))); return state.update(status.id, Immutable.Map(), map => map.mergeDeep(Immutable.fromJS(normalStatus)));
}; };
const normalizeStatuses = (state, statuses) => { const normalizeStatuses = (state, statuses) => {