Favouriting works, reblogging is a little broken because of <Status>
parent
c2a4d70265
commit
595c8dda60
|
@ -49,9 +49,10 @@ export function submitComposeRequest() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function submitComposeSuccess(response) {
|
export function submitComposeSuccess(status) {
|
||||||
return {
|
return {
|
||||||
type: COMPOSE_SUBMIT_SUCCESS
|
type: COMPOSE_SUBMIT_SUCCESS,
|
||||||
|
status: status
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,81 @@
|
||||||
|
import api from '../api'
|
||||||
|
|
||||||
|
export const REBLOG = 'REBLOG';
|
||||||
|
export const REBLOG_REQUEST = 'REBLOG_REQUEST';
|
||||||
|
export const REBLOG_SUCCESS = 'REBLOG_SUCCESS';
|
||||||
|
export const REBLOG_FAIL = 'REBLOG_FAIL';
|
||||||
|
|
||||||
|
export const FAVOURITE = 'FAVOURITE';
|
||||||
|
export const FAVOURITE_REQUEST = 'FAVOURITE_REQUEST';
|
||||||
|
export const FAVOURITE_SUCCESS = 'FAVOURITE_SUCCESS';
|
||||||
|
export const FAVOURITE_FAIL = 'FAVOURITE_FAIL';
|
||||||
|
|
||||||
|
export function reblog(status) {
|
||||||
|
return function (dispatch, getState) {
|
||||||
|
dispatch(reblogRequest(status));
|
||||||
|
|
||||||
|
api(getState).post(`/api/statuses/${status.get('id')}/reblog`).then(function (response) {
|
||||||
|
dispatch(reblogSuccess(status, response.data));
|
||||||
|
}).catch(function (error) {
|
||||||
|
dispatch(reblogFail(status, error));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function reblogRequest(status) {
|
||||||
|
return {
|
||||||
|
type: REBLOG_REQUEST,
|
||||||
|
status: status
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function reblogSuccess(status, response) {
|
||||||
|
return {
|
||||||
|
type: REBLOG_SUCCESS,
|
||||||
|
status: status,
|
||||||
|
response: response
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function reblogFail(status, error) {
|
||||||
|
return {
|
||||||
|
type: REBLOG_FAIL,
|
||||||
|
status: status,
|
||||||
|
error: error
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function favourite(status) {
|
||||||
|
return function (dispatch, getState) {
|
||||||
|
dispatch(favouriteRequest(status));
|
||||||
|
|
||||||
|
api(getState).post(`/api/statuses/${status.get('id')}/favourite`).then(function (response) {
|
||||||
|
dispatch(favouriteSuccess(status, response.data));
|
||||||
|
}).catch(function (error) {
|
||||||
|
dispatch(favouriteFail(status, error));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function favouriteRequest(status) {
|
||||||
|
return {
|
||||||
|
type: FAVOURITE_REQUEST,
|
||||||
|
status: status
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function favouriteSuccess(status, response) {
|
||||||
|
return {
|
||||||
|
type: FAVOURITE_SUCCESS,
|
||||||
|
status: status,
|
||||||
|
response: response
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function favouriteFail(status, error) {
|
||||||
|
return {
|
||||||
|
type: FAVOURITE_FAIL,
|
||||||
|
status: status,
|
||||||
|
error: error
|
||||||
|
};
|
||||||
|
}
|
|
@ -6,12 +6,14 @@ const IconButton = React.createClass({
|
||||||
title: React.PropTypes.string.isRequired,
|
title: React.PropTypes.string.isRequired,
|
||||||
icon: React.PropTypes.string.isRequired,
|
icon: React.PropTypes.string.isRequired,
|
||||||
onClick: React.PropTypes.func.isRequired,
|
onClick: React.PropTypes.func.isRequired,
|
||||||
size: React.PropTypes.number
|
size: React.PropTypes.number,
|
||||||
|
active: React.PropTypes.bool
|
||||||
},
|
},
|
||||||
|
|
||||||
getDefaultProps () {
|
getDefaultProps () {
|
||||||
return {
|
return {
|
||||||
size: 18
|
size: 18,
|
||||||
|
active: false
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -24,7 +26,7 @@ const IconButton = React.createClass({
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
return (
|
return (
|
||||||
<a href='#' title={this.props.title} className='icon-button' onClick={this.handleClick} style={{ display: 'inline-block', fontSize: `${this.props.size}px`, width: `${this.props.size}px`, height: `${this.props.size}px`, lineHeight: `${this.props.size}px`}}>
|
<a href='#' title={this.props.title} className={`icon-button ${this.props.active ? 'active' : ''}`} onClick={this.handleClick} style={{ display: 'inline-block', fontSize: `${this.props.size}px`, width: `${this.props.size}px`, height: `${this.props.size}px`, lineHeight: `${this.props.size}px`}}>
|
||||||
<i className={`fa fa-fw fa-${this.props.icon}`}></i>
|
<i className={`fa fa-fw fa-${this.props.icon}`}></i>
|
||||||
</a>
|
</a>
|
||||||
);
|
);
|
||||||
|
|
|
@ -8,7 +8,9 @@ const Status = React.createClass({
|
||||||
|
|
||||||
propTypes: {
|
propTypes: {
|
||||||
status: ImmutablePropTypes.map.isRequired,
|
status: ImmutablePropTypes.map.isRequired,
|
||||||
onReply: React.PropTypes.func
|
onReply: React.PropTypes.func,
|
||||||
|
onFavourite: React.PropTypes.func,
|
||||||
|
onReblog: React.PropTypes.func
|
||||||
},
|
},
|
||||||
|
|
||||||
mixins: [PureRenderMixin],
|
mixins: [PureRenderMixin],
|
||||||
|
@ -17,6 +19,14 @@ const Status = React.createClass({
|
||||||
this.props.onReply(this.props.status);
|
this.props.onReply(this.props.status);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
handleFavouriteClick () {
|
||||||
|
this.props.onFavourite(this.props.status);
|
||||||
|
},
|
||||||
|
|
||||||
|
handleReblogClick () {
|
||||||
|
this.props.onReblog(this.props.status);
|
||||||
|
},
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
var content = { __html: this.props.status.get('content') };
|
var content = { __html: this.props.status.get('content') };
|
||||||
var status = this.props.status;
|
var status = this.props.status;
|
||||||
|
@ -43,8 +53,8 @@ const Status = React.createClass({
|
||||||
|
|
||||||
<div style={{ marginTop: '10px', overflow: 'hidden' }}>
|
<div style={{ marginTop: '10px', overflow: 'hidden' }}>
|
||||||
<div style={{ float: 'left', marginRight: '10px'}}><IconButton title='Reply' icon='reply' onClick={this.handleReplyClick} /></div>
|
<div style={{ float: 'left', marginRight: '10px'}}><IconButton title='Reply' icon='reply' onClick={this.handleReplyClick} /></div>
|
||||||
<div style={{ float: 'left', marginRight: '10px'}}><IconButton title='Reblog' icon='retweet' /></div>
|
<div style={{ float: 'left', marginRight: '10px'}}><IconButton active={status.get('reblogged')} title='Reblog' icon='retweet' onClick={this.handleReblogClick} /></div>
|
||||||
<div style={{ float: 'left'}}><IconButton title='Favourite' icon='star' /></div>
|
<div style={{ float: 'left'}}><IconButton active={status.get('favourited')} title='Favourite' icon='star' onClick={this.handleFavouriteClick} /></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
@ -5,7 +5,10 @@ import PureRenderMixin from 'react-addons-pure-render-mixin';
|
||||||
const StatusList = React.createClass({
|
const StatusList = React.createClass({
|
||||||
|
|
||||||
propTypes: {
|
propTypes: {
|
||||||
statuses: ImmutablePropTypes.list.isRequired
|
statuses: ImmutablePropTypes.list.isRequired,
|
||||||
|
onReply: React.PropTypes.func,
|
||||||
|
onReblog: React.PropTypes.func,
|
||||||
|
onFavourite: React.PropTypes.func
|
||||||
},
|
},
|
||||||
|
|
||||||
mixins: [PureRenderMixin],
|
mixins: [PureRenderMixin],
|
||||||
|
@ -15,7 +18,7 @@ const StatusList = React.createClass({
|
||||||
<div style={{ overflowY: 'scroll', flex: '1 1 auto' }}>
|
<div style={{ overflowY: 'scroll', flex: '1 1 auto' }}>
|
||||||
<div>
|
<div>
|
||||||
{this.props.statuses.map((status) => {
|
{this.props.statuses.map((status) => {
|
||||||
return <Status key={status.get('id')} status={status} onReply={this.props.onReply} />;
|
return <Status key={status.get('id')} status={status} onReply={this.props.onReply} onReblog={this.props.onReblog} onFavourite={this.props.onFavourite} />;
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import StatusList from '../components/status_list';
|
import StatusList from '../components/status_list';
|
||||||
import { replyCompose } from '../actions/compose';
|
import { replyCompose } from '../actions/compose';
|
||||||
|
import { reblog, favourite } from '../actions/interactions';
|
||||||
|
|
||||||
const mapStateToProps = function (state, props) {
|
const mapStateToProps = function (state, props) {
|
||||||
return {
|
return {
|
||||||
|
@ -12,6 +13,14 @@ const mapDispatchToProps = function (dispatch) {
|
||||||
return {
|
return {
|
||||||
onReply: function (status) {
|
onReply: function (status) {
|
||||||
dispatch(replyCompose(status));
|
dispatch(replyCompose(status));
|
||||||
|
},
|
||||||
|
|
||||||
|
onFavourite: function (status) {
|
||||||
|
dispatch(favourite(status));
|
||||||
|
},
|
||||||
|
|
||||||
|
onReblog: function (status) {
|
||||||
|
dispatch(reblog(status));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,16 +1,30 @@
|
||||||
import { TIMELINE_SET, TIMELINE_UPDATE } from '../actions/timelines';
|
import { TIMELINE_SET, TIMELINE_UPDATE } from '../actions/timelines';
|
||||||
|
import { REBLOG_SUCCESS, FAVOURITE_SUCCESS } from '../actions/interactions';
|
||||||
import Immutable from 'immutable';
|
import Immutable from 'immutable';
|
||||||
|
|
||||||
const initialState = Immutable.Map();
|
const initialState = Immutable.Map();
|
||||||
|
|
||||||
|
function updateMatchingStatuses(state, needle, callback) {
|
||||||
|
return state.map(function (list) {
|
||||||
|
return list.map(function (status) {
|
||||||
|
if (status.get('id') === needle.get('id')) {
|
||||||
|
return callback(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
export default function timelines(state = initialState, action) {
|
export default function timelines(state = initialState, action) {
|
||||||
switch(action.type) {
|
switch(action.type) {
|
||||||
case TIMELINE_SET:
|
case TIMELINE_SET:
|
||||||
return state.set(action.timeline, Immutable.fromJS(action.statuses));
|
return state.set(action.timeline, Immutable.fromJS(action.statuses));
|
||||||
case TIMELINE_UPDATE:
|
case TIMELINE_UPDATE:
|
||||||
return state.update(action.timeline, function (list) {
|
return state.update(action.timeline, list => list.unshift(Immutable.fromJS(action.status)));
|
||||||
return list.unshift(Immutable.fromJS(action.status));
|
case REBLOG_SUCCESS:
|
||||||
});
|
case FAVOURITE_SUCCESS:
|
||||||
|
return updateMatchingStatuses(state, action.status, () => Immutable.fromJS(action.response));
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,10 @@
|
||||||
color: #535b72;
|
color: #535b72;
|
||||||
cursor: default;
|
cursor: default;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&.active {
|
||||||
|
color: #2b90d9;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.compose-drawer__textarea {
|
.compose-drawer__textarea {
|
||||||
|
|
|
@ -75,7 +75,7 @@ class Account < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def ping!(atom_url, hubs)
|
def ping!(atom_url, hubs)
|
||||||
return unless local?
|
return unless local? && !Rails.env.development?
|
||||||
OStatus2::Publication.new(atom_url, hubs).publish
|
OStatus2::Publication.new(atom_url, hubs).publish
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,8 @@ class Favourite < ApplicationRecord
|
||||||
belongs_to :account, inverse_of: :favourites
|
belongs_to :account, inverse_of: :favourites
|
||||||
belongs_to :status, inverse_of: :favourites
|
belongs_to :status, inverse_of: :favourites
|
||||||
|
|
||||||
|
validates :status_id, uniqueness: { scope: :account_id }
|
||||||
|
|
||||||
def verb
|
def verb
|
||||||
:favorite
|
:favorite
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue