forked from cybrespace/mastodon
Fix #238 - Add "favourites" column
This commit is contained in:
parent
da5d366230
commit
7d53ee73f3
|
@ -0,0 +1,83 @@
|
||||||
|
import api, { getLinks } from '../api'
|
||||||
|
|
||||||
|
export const FAVOURITED_STATUSES_FETCH_REQUEST = 'FAVOURITED_STATUSES_FETCH_REQUEST';
|
||||||
|
export const FAVOURITED_STATUSES_FETCH_SUCCESS = 'FAVOURITED_STATUSES_FETCH_SUCCESS';
|
||||||
|
export const FAVOURITED_STATUSES_FETCH_FAIL = 'FAVOURITED_STATUSES_FETCH_FAIL';
|
||||||
|
|
||||||
|
export const FAVOURITED_STATUSES_EXPAND_REQUEST = 'FAVOURITED_STATUSES_EXPAND_REQUEST';
|
||||||
|
export const FAVOURITED_STATUSES_EXPAND_SUCCESS = 'FAVOURITED_STATUSES_EXPAND_SUCCESS';
|
||||||
|
export const FAVOURITED_STATUSES_EXPAND_FAIL = 'FAVOURITED_STATUSES_EXPAND_FAIL';
|
||||||
|
|
||||||
|
export function fetchFavouritedStatuses() {
|
||||||
|
return (dispatch, getState) => {
|
||||||
|
dispatch(fetchFavouritedStatusesRequest());
|
||||||
|
|
||||||
|
api(getState).get('/api/v1/favourites').then(response => {
|
||||||
|
const next = getLinks(response).refs.find(link => link.rel === 'next');
|
||||||
|
dispatch(fetchFavouritedStatusesSuccess(response.data, next ? next.uri : null));
|
||||||
|
}).catch(error => {
|
||||||
|
dispatch(fetchFavouritedStatusesFail(error));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export function fetchFavouritedStatusesRequest() {
|
||||||
|
return {
|
||||||
|
type: FAVOURITED_STATUSES_FETCH_REQUEST
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export function fetchFavouritedStatusesSuccess(statuses, next) {
|
||||||
|
return {
|
||||||
|
type: FAVOURITED_STATUSES_FETCH_SUCCESS,
|
||||||
|
statuses,
|
||||||
|
next
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export function fetchFavouritedStatusesFail(error) {
|
||||||
|
return {
|
||||||
|
type: FAVOURITED_STATUSES_FETCH_FAIL,
|
||||||
|
error
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export function expandFavouritedStatuses() {
|
||||||
|
return (dispatch, getState) => {
|
||||||
|
const url = getState().getIn(['status_lists', 'favourites', 'next'], null);
|
||||||
|
|
||||||
|
if (url === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatch(expandFavouritedStatusesRequest());
|
||||||
|
|
||||||
|
api(getState).get(url).then(response => {
|
||||||
|
const next = getLinks(response).refs.find(link => link.rel === 'next');
|
||||||
|
dispatch(expandFavouritedStatusesSuccess(response.data, next ? next.uri : null));
|
||||||
|
}).catch(error => {
|
||||||
|
dispatch(expandFavouritedStatusesFail(error));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export function expandFavouritedStatusesRequest() {
|
||||||
|
return {
|
||||||
|
type: FAVOURITED_STATUSES_EXPAND_REQUEST
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export function expandFavouritedStatusesSuccess(statuses, next) {
|
||||||
|
return {
|
||||||
|
type: FAVOURITED_STATUSES_EXPAND_SUCCESS,
|
||||||
|
statuses,
|
||||||
|
next
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export function expandFavouritedStatusesFail(error) {
|
||||||
|
return {
|
||||||
|
type: FAVOURITED_STATUSES_EXPAND_FAIL,
|
||||||
|
error
|
||||||
|
};
|
||||||
|
};
|
|
@ -97,6 +97,11 @@ export function expandTimeline(timeline, id = null) {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
const lastId = getState().getIn(['timelines', timeline, 'items'], Immutable.List()).last();
|
const lastId = getState().getIn(['timelines', timeline, 'items'], Immutable.List()).last();
|
||||||
|
|
||||||
|
if (!lastId) {
|
||||||
|
// If timeline is empty, don't try to load older posts since there are none
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
dispatch(expandTimelineRequest(timeline));
|
dispatch(expandTimelineRequest(timeline));
|
||||||
|
|
||||||
let path = timeline;
|
let path = timeline;
|
||||||
|
|
|
@ -34,6 +34,7 @@ import HashtagTimeline from '../features/hashtag_timeline';
|
||||||
import Notifications from '../features/notifications';
|
import Notifications from '../features/notifications';
|
||||||
import FollowRequests from '../features/follow_requests';
|
import FollowRequests from '../features/follow_requests';
|
||||||
import GenericNotFound from '../features/generic_not_found';
|
import GenericNotFound from '../features/generic_not_found';
|
||||||
|
import FavouritedStatuses from '../features/favourited_statuses';
|
||||||
import { IntlProvider, addLocaleData } from 'react-intl';
|
import { IntlProvider, addLocaleData } from 'react-intl';
|
||||||
import en from 'react-intl/locale-data/en';
|
import en from 'react-intl/locale-data/en';
|
||||||
import de from 'react-intl/locale-data/de';
|
import de from 'react-intl/locale-data/de';
|
||||||
|
@ -113,6 +114,7 @@ const Mastodon = React.createClass({
|
||||||
<Route path='timelines/tag/:id' component={HashtagTimeline} />
|
<Route path='timelines/tag/:id' component={HashtagTimeline} />
|
||||||
|
|
||||||
<Route path='notifications' component={Notifications} />
|
<Route path='notifications' component={Notifications} />
|
||||||
|
<Route path='favourites' component={FavouritedStatuses} />
|
||||||
|
|
||||||
<Route path='statuses/new' component={Compose} />
|
<Route path='statuses/new' component={Compose} />
|
||||||
<Route path='statuses/:statusId' component={Status} />
|
<Route path='statuses/:statusId' component={Status} />
|
||||||
|
|
|
@ -18,7 +18,8 @@ const AccountTimeline = React.createClass({
|
||||||
propTypes: {
|
propTypes: {
|
||||||
params: React.PropTypes.object.isRequired,
|
params: React.PropTypes.object.isRequired,
|
||||||
dispatch: React.PropTypes.func.isRequired,
|
dispatch: React.PropTypes.func.isRequired,
|
||||||
statusIds: ImmutablePropTypes.list
|
statusIds: ImmutablePropTypes.list,
|
||||||
|
me: React.PropTypes.number.isRequired
|
||||||
},
|
},
|
||||||
|
|
||||||
mixins: [PureRenderMixin],
|
mixins: [PureRenderMixin],
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
import { connect } from 'react-redux';
|
||||||
|
import PureRenderMixin from 'react-addons-pure-render-mixin';
|
||||||
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||||
|
import LoadingIndicator from '../../components/loading_indicator';
|
||||||
|
import { fetchFavouritedStatuses, expandFavouritedStatuses } from '../../actions/favourites';
|
||||||
|
import Column from '../ui/components/column';
|
||||||
|
import StatusList from '../../components/status_list';
|
||||||
|
import ColumnBackButton from '../public_timeline/components/column_back_button';
|
||||||
|
import { defineMessages, injectIntl } from 'react-intl';
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
heading: { id: 'column.favourites', defaultMessage: 'Favourites' }
|
||||||
|
});
|
||||||
|
|
||||||
|
const mapStateToProps = state => ({
|
||||||
|
statusIds: state.getIn(['status_lists', 'favourites', 'items']),
|
||||||
|
loaded: state.getIn(['status_lists', 'favourites', 'loaded']),
|
||||||
|
me: state.getIn(['meta', 'me'])
|
||||||
|
});
|
||||||
|
|
||||||
|
const Favourites = React.createClass({
|
||||||
|
|
||||||
|
propTypes: {
|
||||||
|
params: React.PropTypes.object.isRequired,
|
||||||
|
dispatch: React.PropTypes.func.isRequired,
|
||||||
|
statusIds: ImmutablePropTypes.list.isRequired,
|
||||||
|
loaded: React.PropTypes.bool,
|
||||||
|
intl: React.PropTypes.object.isRequired,
|
||||||
|
me: React.PropTypes.number.isRequired
|
||||||
|
},
|
||||||
|
|
||||||
|
mixins: [PureRenderMixin],
|
||||||
|
|
||||||
|
componentWillMount () {
|
||||||
|
this.props.dispatch(fetchFavouritedStatuses());
|
||||||
|
},
|
||||||
|
|
||||||
|
handleScrollToBottom () {
|
||||||
|
this.props.dispatch(expandFavouritedStatuses());
|
||||||
|
},
|
||||||
|
|
||||||
|
render () {
|
||||||
|
const { statusIds, loaded, intl, me } = this.props;
|
||||||
|
|
||||||
|
if (!loaded) {
|
||||||
|
return (
|
||||||
|
<Column>
|
||||||
|
<LoadingIndicator />
|
||||||
|
</Column>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Column icon='star' heading={intl.formatMessage(messages.heading)}>
|
||||||
|
<ColumnBackButton />
|
||||||
|
<StatusList statusIds={statusIds} me={me} onScrollToBottom={this.handleScrollToBottom} />
|
||||||
|
</Column>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
export default connect(mapStateToProps)(injectIntl(Favourites));
|
|
@ -10,7 +10,8 @@ const messages = defineMessages({
|
||||||
public_timeline: { id: 'navigation_bar.public_timeline', defaultMessage: 'Public timeline' },
|
public_timeline: { id: 'navigation_bar.public_timeline', defaultMessage: 'Public timeline' },
|
||||||
preferences: { id: 'navigation_bar.preferences', defaultMessage: 'Preferences' },
|
preferences: { id: 'navigation_bar.preferences', defaultMessage: 'Preferences' },
|
||||||
follow_requests: { id: 'navigation_bar.follow_requests', defaultMessage: 'Follow requests' },
|
follow_requests: { id: 'navigation_bar.follow_requests', defaultMessage: 'Follow requests' },
|
||||||
sign_out: { id: 'navigation_bar.logout', defaultMessage: 'Sign out' }
|
sign_out: { id: 'navigation_bar.logout', defaultMessage: 'Sign out' },
|
||||||
|
favourites: { id: 'navigation_bar.favourites', defaultMessage: 'Favourites' }
|
||||||
});
|
});
|
||||||
|
|
||||||
const mapStateToProps = state => ({
|
const mapStateToProps = state => ({
|
||||||
|
@ -29,6 +30,7 @@ const GettingStarted = ({ intl, me }) => {
|
||||||
<div style={{ position: 'relative' }}>
|
<div style={{ position: 'relative' }}>
|
||||||
<ColumnLink icon='globe' text={intl.formatMessage(messages.public_timeline)} to='/timelines/public' />
|
<ColumnLink icon='globe' text={intl.formatMessage(messages.public_timeline)} to='/timelines/public' />
|
||||||
<ColumnLink icon='cog' text={intl.formatMessage(messages.preferences)} href='/settings/preferences' />
|
<ColumnLink icon='cog' text={intl.formatMessage(messages.preferences)} href='/settings/preferences' />
|
||||||
|
<ColumnLink icon='star' text={intl.formatMessage(messages.favourites)} to='/favourites' />
|
||||||
{followRequests}
|
{followRequests}
|
||||||
<ColumnLink icon='sign-out' text={intl.formatMessage(messages.sign_out)} href='/auth/sign_out' method='delete' />
|
<ColumnLink icon='sign-out' text={intl.formatMessage(messages.sign_out)} href='/auth/sign_out' method='delete' />
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
import { showLoading, hideLoading } from 'react-redux-loading-bar';
|
||||||
|
|
||||||
|
const defaultTypeSuffixes = ['PENDING', 'FULFILLED', 'REJECTED'];
|
||||||
|
|
||||||
|
export default function loadingBarMiddleware(config = {}) {
|
||||||
|
const promiseTypeSuffixes = config.promiseTypeSuffixes || defaultTypeSuffixes;
|
||||||
|
|
||||||
|
return ({ dispatch }) => next => (action) => {
|
||||||
|
if (action.type && !action.skipLoading) {
|
||||||
|
const [PENDING, FULFILLED, REJECTED] = promiseTypeSuffixes;
|
||||||
|
|
||||||
|
const isPending = new RegExp(`${PENDING}$`, 'g');
|
||||||
|
const isFulfilled = new RegExp(`${FULFILLED}$`, 'g');
|
||||||
|
const isRejected = new RegExp(`${REJECTED}$`, 'g');
|
||||||
|
|
||||||
|
if (action.type.match(isPending)) {
|
||||||
|
dispatch(showLoading());
|
||||||
|
} else if (action.type.match(isFulfilled) || action.type.match(isRejected)) {
|
||||||
|
dispatch(hideLoading());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return next(action);
|
||||||
|
};
|
||||||
|
};
|
|
@ -32,6 +32,10 @@ import {
|
||||||
NOTIFICATIONS_REFRESH_SUCCESS,
|
NOTIFICATIONS_REFRESH_SUCCESS,
|
||||||
NOTIFICATIONS_EXPAND_SUCCESS
|
NOTIFICATIONS_EXPAND_SUCCESS
|
||||||
} from '../actions/notifications';
|
} from '../actions/notifications';
|
||||||
|
import {
|
||||||
|
FAVOURITED_STATUSES_FETCH_SUCCESS,
|
||||||
|
FAVOURITED_STATUSES_EXPAND_SUCCESS
|
||||||
|
} from '../actions/favourites';
|
||||||
import { STORE_HYDRATE } from '../actions/store';
|
import { STORE_HYDRATE } from '../actions/store';
|
||||||
import Immutable from 'immutable';
|
import Immutable from 'immutable';
|
||||||
|
|
||||||
|
@ -90,6 +94,8 @@ export default function accounts(state = initialState, action) {
|
||||||
case ACCOUNT_TIMELINE_FETCH_SUCCESS:
|
case ACCOUNT_TIMELINE_FETCH_SUCCESS:
|
||||||
case ACCOUNT_TIMELINE_EXPAND_SUCCESS:
|
case ACCOUNT_TIMELINE_EXPAND_SUCCESS:
|
||||||
case CONTEXT_FETCH_SUCCESS:
|
case CONTEXT_FETCH_SUCCESS:
|
||||||
|
case FAVOURITED_STATUSES_FETCH_SUCCESS:
|
||||||
|
case FAVOURITED_STATUSES_EXPAND_SUCCESS:
|
||||||
return normalizeAccountsFromStatuses(state, action.statuses);
|
return normalizeAccountsFromStatuses(state, action.statuses);
|
||||||
case REBLOG_SUCCESS:
|
case REBLOG_SUCCESS:
|
||||||
case FAVOURITE_SUCCESS:
|
case FAVOURITE_SUCCESS:
|
||||||
|
|
|
@ -12,6 +12,7 @@ import relationships from './relationships';
|
||||||
import search from './search';
|
import search from './search';
|
||||||
import notifications from './notifications';
|
import notifications from './notifications';
|
||||||
import settings from './settings';
|
import settings from './settings';
|
||||||
|
import status_lists from './status_lists';
|
||||||
|
|
||||||
export default combineReducers({
|
export default combineReducers({
|
||||||
timelines,
|
timelines,
|
||||||
|
@ -21,6 +22,7 @@ export default combineReducers({
|
||||||
loadingBar: loadingBarReducer,
|
loadingBar: loadingBarReducer,
|
||||||
modal,
|
modal,
|
||||||
user_lists,
|
user_lists,
|
||||||
|
status_lists,
|
||||||
accounts,
|
accounts,
|
||||||
statuses,
|
statuses,
|
||||||
relationships,
|
relationships,
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
import {
|
||||||
|
FAVOURITED_STATUSES_FETCH_SUCCESS,
|
||||||
|
FAVOURITED_STATUSES_EXPAND_SUCCESS
|
||||||
|
} from '../actions/favourites';
|
||||||
|
import Immutable from 'immutable';
|
||||||
|
|
||||||
|
const initialState = Immutable.Map({
|
||||||
|
favourites: Immutable.Map({
|
||||||
|
next: null,
|
||||||
|
loaded: false,
|
||||||
|
items: Immutable.List()
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
const normalizeList = (state, listType, statuses, next) => {
|
||||||
|
return state.update(listType, listMap => listMap.withMutations(map => {
|
||||||
|
map.set('next', next);
|
||||||
|
map.set('loaded', true);
|
||||||
|
map.set('items', Immutable.List(statuses.map(item => item.id)));
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
|
const appendToList = (state, listType, statuses, next) => {
|
||||||
|
return state.update(listType, listMap => listMap.withMutations(map => {
|
||||||
|
map.set('next', next);
|
||||||
|
map.set('items', map.get('items').push(...statuses.map(item => item.id)));
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function statusLists(state = initialState, action) {
|
||||||
|
switch(action.type) {
|
||||||
|
case FAVOURITED_STATUSES_FETCH_SUCCESS:
|
||||||
|
return normalizeList(state, 'favourites', action.statuses, action.next);
|
||||||
|
case FAVOURITED_STATUSES_EXPAND_SUCCESS:
|
||||||
|
return appendToList(state, 'favourites', action.statuses, action.next);
|
||||||
|
default:
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
};
|
|
@ -28,6 +28,10 @@ import {
|
||||||
NOTIFICATIONS_REFRESH_SUCCESS,
|
NOTIFICATIONS_REFRESH_SUCCESS,
|
||||||
NOTIFICATIONS_EXPAND_SUCCESS
|
NOTIFICATIONS_EXPAND_SUCCESS
|
||||||
} from '../actions/notifications';
|
} from '../actions/notifications';
|
||||||
|
import {
|
||||||
|
FAVOURITED_STATUSES_FETCH_SUCCESS,
|
||||||
|
FAVOURITED_STATUSES_EXPAND_SUCCESS
|
||||||
|
} from '../actions/favourites';
|
||||||
import Immutable from 'immutable';
|
import Immutable from 'immutable';
|
||||||
|
|
||||||
const normalizeStatus = (state, status) => {
|
const normalizeStatus = (state, status) => {
|
||||||
|
@ -101,6 +105,8 @@ export default function statuses(state = initialState, action) {
|
||||||
case CONTEXT_FETCH_SUCCESS:
|
case CONTEXT_FETCH_SUCCESS:
|
||||||
case NOTIFICATIONS_REFRESH_SUCCESS:
|
case NOTIFICATIONS_REFRESH_SUCCESS:
|
||||||
case NOTIFICATIONS_EXPAND_SUCCESS:
|
case NOTIFICATIONS_EXPAND_SUCCESS:
|
||||||
|
case FAVOURITED_STATUSES_FETCH_SUCCESS:
|
||||||
|
case FAVOURITED_STATUSES_EXPAND_SUCCESS:
|
||||||
return normalizeStatuses(state, action.statuses);
|
return normalizeStatuses(state, action.statuses);
|
||||||
case TIMELINE_DELETE:
|
case TIMELINE_DELETE:
|
||||||
return deleteStatus(state, action.id, action.references);
|
return deleteStatus(state, action.id, action.references);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { createStore, applyMiddleware, compose } from 'redux';
|
import { createStore, applyMiddleware, compose } from 'redux';
|
||||||
import thunk from 'redux-thunk';
|
import thunk from 'redux-thunk';
|
||||||
import appReducer from '../reducers';
|
import appReducer from '../reducers';
|
||||||
import { loadingBarMiddleware } from 'react-redux-loading-bar';
|
import loadingBarMiddleware from '../middleware/loading_bar';
|
||||||
import errorsMiddleware from '../middleware/errors';
|
import errorsMiddleware from '../middleware/errors';
|
||||||
import Immutable from 'immutable';
|
import Immutable from 'immutable';
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ class Api::V1::FavouritesController < ApiController
|
||||||
set_maps(@statuses)
|
set_maps(@statuses)
|
||||||
set_counters_maps(@statuses)
|
set_counters_maps(@statuses)
|
||||||
|
|
||||||
next_path = api_v1_favourites_url(max_id: results.last.id) if results.size == DEFAULT_ACCOUNTS_LIMIT
|
next_path = api_v1_favourites_url(max_id: results.last.id) if results.size == DEFAULT_STATUSES_LIMIT
|
||||||
prev_path = api_v1_favourites_url(since_id: results.first.id) unless results.empty?
|
prev_path = api_v1_favourites_url(since_id: results.first.id) unless results.empty?
|
||||||
|
|
||||||
set_pagination_headers(next_path, prev_path)
|
set_pagination_headers(next_path, prev_path)
|
||||||
|
|
Loading…
Reference in New Issue