Merge branch 'small-ui-updates' into 'develop'

Small UI updates

See merge request soapbox-pub/soapbox-fe!865
This commit is contained in:
Alex Gleason 2021-11-12 20:03:49 +00:00
commit 9970780e53
5 changed files with 80 additions and 11 deletions

View file

@ -77,7 +77,6 @@ export function unreblog(status) {
dispatch(unreblogRequest(status)); dispatch(unreblogRequest(status));
api(getState).post(`/api/v1/statuses/${status.get('id')}/unreblog`).then(response => { api(getState).post(`/api/v1/statuses/${status.get('id')}/unreblog`).then(response => {
dispatch(importFetchedStatus(response.data));
dispatch(unreblogSuccess(status)); dispatch(unreblogSuccess(status));
}).catch(error => { }).catch(error => {
dispatch(unreblogFail(status, error)); dispatch(unreblogFail(status, error));
@ -157,7 +156,6 @@ export function unfavourite(status) {
dispatch(unfavouriteRequest(status)); dispatch(unfavouriteRequest(status));
api(getState).post(`/api/v1/statuses/${status.get('id')}/unfavourite`).then(response => { api(getState).post(`/api/v1/statuses/${status.get('id')}/unfavourite`).then(response => {
dispatch(importFetchedStatus(response.data));
dispatch(unfavouriteSuccess(status)); dispatch(unfavouriteSuccess(status));
}).catch(error => { }).catch(error => {
dispatch(unfavouriteFail(status, error)); dispatch(unfavouriteFail(status, error));

View file

@ -20,6 +20,7 @@ const mapStateToProps = state => {
account: state.getIn(['accounts', me]), account: state.getIn(['accounts', me]),
composeText: state.getIn(['compose', 'text']), composeText: state.getIn(['compose', 'text']),
privacy: state.getIn(['compose', 'privacy']), privacy: state.getIn(['compose', 'privacy']),
inReplyTo: state.getIn(['compose', 'in_reply_to']),
}; };
}; };
@ -31,6 +32,7 @@ class ComposeModal extends ImmutablePureComponent {
onClose: PropTypes.func.isRequired, onClose: PropTypes.func.isRequired,
composeText: PropTypes.string, composeText: PropTypes.string,
privacy: PropTypes.string, privacy: PropTypes.string,
inReplyTo: PropTypes.string,
dispatch: PropTypes.func.isRequired, dispatch: PropTypes.func.isRequired,
}; };
@ -49,18 +51,26 @@ class ComposeModal extends ImmutablePureComponent {
} }
}; };
renderTitle = () => {
const { privacy, inReplyTo } = this.props;
if (privacy === 'direct') {
return <FormattedMessage id='navigation_bar.compose_direct' defaultMessage='Direct message' />;
} else if (inReplyTo) {
return <FormattedMessage id='navigation_bar.compose_reply' defaultMessage='Reply to post' />;
} else {
return <FormattedMessage id='navigation_bar.compose' defaultMessage='Compose new post' />;
}
}
render() { render() {
const { intl, privacy } = this.props; const { intl } = this.props;
return ( return (
<div className='modal-root__modal compose-modal'> <div className='modal-root__modal compose-modal'>
<div className='compose-modal__header'> <div className='compose-modal__header'>
<h3 className='compose-modal__header__title'> <h3 className='compose-modal__header__title'>
{privacy === 'direct' ? ( {this.renderTitle()}
<FormattedMessage id='navigation_bar.compose_direct' defaultMessage='Direct message' />
) : (
<FormattedMessage id='navigation_bar.compose' defaultMessage='Compose new post' />
)}
</h3> </h3>
<IconButton <IconButton
className='compose-modal__close' className='compose-modal__close'

View file

@ -1,8 +1,41 @@
import reducer from '../statuses'; import reducer from '../statuses';
import { Map as ImmutableMap } from 'immutable'; import { Map as ImmutableMap, fromJS } from 'immutable';
import {
STATUS_CREATE_REQUEST,
STATUS_CREATE_FAIL,
} from 'soapbox/actions/statuses';
describe('statuses reducer', () => { describe('statuses reducer', () => {
it('should return the initial state', () => { it('should return the initial state', () => {
expect(reducer(undefined, {})).toEqual(ImmutableMap()); expect(reducer(undefined, {})).toEqual(ImmutableMap());
}); });
describe('STATUS_CREATE_REQUEST', () => {
it('increments the replies_count of its parent', () => {
const state = fromJS({ '123': { replies_count: 4 } });
const action = {
type: STATUS_CREATE_REQUEST,
params: { in_reply_to_id: '123' },
};
const result = reducer(state, action).getIn(['123', 'replies_count']);
expect(result).toEqual(5);
});
});
describe('STATUS_CREATE_FAIL', () => {
it('decrements the replies_count of its parent', () => {
const state = fromJS({ '123': { replies_count: 5 } });
const action = {
type: STATUS_CREATE_FAIL,
params: { in_reply_to_id: '123' },
};
const result = reducer(state, action).getIn(['123', 'replies_count']);
expect(result).toEqual(4);
});
});
}); });

View file

@ -6,6 +6,8 @@ import {
FAVOURITE_FAIL, FAVOURITE_FAIL,
} from '../actions/interactions'; } from '../actions/interactions';
import { import {
STATUS_CREATE_REQUEST,
STATUS_CREATE_FAIL,
STATUS_MUTE_SUCCESS, STATUS_MUTE_SUCCESS,
STATUS_UNMUTE_SUCCESS, STATUS_UNMUTE_SUCCESS,
STATUS_REVEAL, STATUS_REVEAL,
@ -33,6 +35,22 @@ const deleteStatus = (state, id, references) => {
return state.delete(id); return state.delete(id);
}; };
const importPendingStatus = (state, { in_reply_to_id }) => {
if (in_reply_to_id) {
return state.updateIn([in_reply_to_id, 'replies_count'], 0, count => count + 1);
} else {
return state;
}
};
const deletePendingStatus = (state, { in_reply_to_id }) => {
if (in_reply_to_id) {
return state.updateIn([in_reply_to_id, 'replies_count'], 0, count => Math.max(0, count - 1));
} else {
return state;
}
};
const initialState = ImmutableMap(); const initialState = ImmutableMap();
export default function statuses(state = initialState, action) { export default function statuses(state = initialState, action) {
@ -41,6 +59,10 @@ export default function statuses(state = initialState, action) {
return importStatus(state, action.status); return importStatus(state, action.status);
case STATUSES_IMPORT: case STATUSES_IMPORT:
return importStatuses(state, action.statuses); return importStatuses(state, action.statuses);
case STATUS_CREATE_REQUEST:
return importPendingStatus(state, action.params);
case STATUS_CREATE_FAIL:
return deletePendingStatus(state, action.params);
case FAVOURITE_REQUEST: case FAVOURITE_REQUEST:
return state.update(action.status.get('id'), status => return state.update(action.status.get('id'), status =>
status status

View file

@ -87,6 +87,7 @@
color: var(--primary-text-color); color: var(--primary-text-color);
text-decoration: none; text-decoration: none;
font-size: 20px; font-size: 20px;
width: 55px;
span { span {
margin-top: 1px; margin-top: 1px;
@ -155,19 +156,24 @@
justify-content: center; justify-content: center;
color: var(--primary-text-color); color: var(--primary-text-color);
opacity: 0.6; opacity: 0.6;
font-size: 16px;
.svg-icon { .svg-icon {
margin-right: 7px; margin-right: 7px;
width: 22px; width: 26px;
height: 22px; height: 26px;
} }
} }
&__message { &__message {
position: absolute; position: absolute;
padding: 0 10px;
align-self: center; align-self: center;
justify-self: center; justify-self: center;
font-weight: bold; font-weight: bold;
overflow-x: hidden;
text-overflow: ellipsis;
max-width: calc(100vw - 200px);
} }
&__cog { &__cog {