Browse Source

show comments on timeline, and show right count when unfavourite/unreblog

pull/4/head
欧醚 5 years ago
parent
commit
66561200b5
3 changed files with 22 additions and 19 deletions
  1. +8
    -2
      app/javascript/mastodon/actions/interactions.js
  2. +9
    -17
      app/javascript/mastodon/components/status.js
  3. +5
    -0
      app/javascript/mastodon/containers/status_container.js

+ 8
- 2
app/javascript/mastodon/actions/interactions.js View File

@ -52,8 +52,11 @@ export function unreblog(status) {
return (dispatch, getState) => {
dispatch(unreblogRequest(status));
let old_reblogs_count = status.get('reblogs_count');
api(getState).post(`/api/v1/statuses/${status.get('id')}/unreblog`).then(response => {
dispatch(importFetchedStatus(response.data));
let pred = response.data
pred.reblogs_count = old_reblogs_count - 1; // unreb is async
dispatch(importFetchedStatus(pred));
dispatch(unreblogSuccess(status));
}).catch(error => {
dispatch(unreblogFail(status, error));
@ -128,8 +131,11 @@ export function unfavourite(status) {
return (dispatch, getState) => {
dispatch(unfavouriteRequest(status));
let old_favourites_count = status.get('favourites_count');
api(getState).post(`/api/v1/statuses/${status.get('id')}/unfavourite`).then(response => {
dispatch(importFetchedStatus(response.data));
let pred = response.data
pred.favourites_count = old_favourites_count - 1; // unfav is async
dispatch(importFetchedStatus(pred));
dispatch(unfavouriteSuccess(status));
}).catch(error => {
dispatch(unfavouriteFail(status, error));

+ 9
- 17
app/javascript/mastodon/components/status.js View File

@ -91,6 +91,7 @@ class Status extends ImmutablePureComponent {
cachedMediaWidth: PropTypes.number,
sonsIds: ImmutablePropTypes.list,
onPreview: PropTypes.func
};
// Avoid checking props that are functions (and whose equality will always
@ -100,6 +101,7 @@ class Status extends ImmutablePureComponent {
'account',
'muted',
'hidden',
'sonsIds'
];
state = {
@ -110,6 +112,10 @@ class Status extends ImmutablePureComponent {
// Track height changes we know about to compensate scrolling
componentDidMount () {
this.didShowCard = !this.props.muted && !this.props.hidden && this.props.status && this.props.status.get('card');
if(this.props.com_prev) {
const { status } = this.props;
this.props.onPreview(status.get('id'));
}
}
getSnapshotBeforeUpdate () {
@ -260,7 +266,7 @@ class Status extends ImmutablePureComponent {
handleHotkeyToggleSensitive = () => {
this.handleToggleMediaVisibility();
}
_properStatus () {
const { status } = this.props;
@ -275,22 +281,8 @@ class Status extends ImmutablePureComponent {
this.node = c;
}
renderChildren (list) {
/*
return list.map(id => (
<DetailedStatus
key = {id}
status={status}
onOpenVideo={this.nothing}
onOpenMedia={this.nothing}
onToggleHidden={this.nothing}
domain={"domain"}
showMedia={this.nothing}
onToggleMediaVisibility={this.nothing}
/>
));
*/
renderChildren (list) {
return list.map(id => (
<StatusContainer
key={id}
@ -485,7 +477,7 @@ class Status extends ImmutablePureComponent {
<div className={classNames('status__wrapper', `status__wrapper-${status.get('visibility')}`, { 'status__wrapper-reply': !!status.get('in_reply_to_id'), read: unread === false, focusable: !this.props.muted }, (deep!=null) && 'tree-'+tree_type)} tabIndex={this.props.muted ? null : 0} data-featured={featured ? 'true' : null} aria-label={textForScreenReader(intl, status, rebloggedByText)} ref={this.handleRef}>
{prepend}
<div className={classNames('status', `status-${status.get('visibility')}`, { 'status-reply': !!status.get('in_reply_to_id'), muted: this.props.muted, read: unread === false })} data-id={status.get('id')}>
<div className={classNames('status', `status-${status.get('visibility')}`, { 'status-reply': !!status.get('in_reply_to_id'), muted: this.props.muted, read: unread === false })} data-id={status.get('id')} >
<div className='status__expand' onClick={this.handleExpandClick} role='presentation' />
<div className='status__info'>
<a href={status.get('url')} className='status__relative-time' target='_blank' rel='noopener'><RelativeTimestamp timestamp={status.get('created_at')} /></a>

+ 5
- 0
app/javascript/mastodon/containers/status_container.js View File

@ -20,6 +20,7 @@ import {
deleteStatus,
hideStatus,
revealStatus,
fetchContext,
} from '../actions/statuses';
import { initMuteModal } from '../actions/mutes';
import { initBlockModal } from '../actions/blocks';
@ -163,6 +164,10 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
}
},
onPreview (id) {
dispatch(fetchContext(id));
},
});
export default injectIntl(connect(makeMapStateToProps, mapDispatchToProps)(Status));

Loading…
Cancel
Save