Make emoji reacts more responsive
This commit is contained in:
parent
29bcc4a0d1
commit
e04ab557ac
|
@ -10,9 +10,13 @@ import {
|
||||||
STATUS_REVEAL,
|
STATUS_REVEAL,
|
||||||
STATUS_HIDE,
|
STATUS_HIDE,
|
||||||
} from '../actions/statuses';
|
} from '../actions/statuses';
|
||||||
|
import {
|
||||||
|
EMOJI_REACT_REQUEST,
|
||||||
|
} from '../actions/emoji_reacts';
|
||||||
import { TIMELINE_DELETE } from '../actions/timelines';
|
import { TIMELINE_DELETE } from '../actions/timelines';
|
||||||
import { STATUS_IMPORT, STATUSES_IMPORT } from '../actions/importer';
|
import { STATUS_IMPORT, STATUSES_IMPORT } from '../actions/importer';
|
||||||
import { Map as ImmutableMap, fromJS } from 'immutable';
|
import { Map as ImmutableMap, fromJS } from 'immutable';
|
||||||
|
import { simulateEmojiReact } from 'gabsocial/utils/emoji_reacts';
|
||||||
|
|
||||||
const importStatus = (state, status) => state.set(status.id, fromJS(status));
|
const importStatus = (state, status) => state.set(status.id, fromJS(status));
|
||||||
|
|
||||||
|
@ -37,6 +41,10 @@ export default function statuses(state = initialState, action) {
|
||||||
return importStatuses(state, action.statuses);
|
return importStatuses(state, action.statuses);
|
||||||
case FAVOURITE_REQUEST:
|
case FAVOURITE_REQUEST:
|
||||||
return state.setIn([action.status.get('id'), 'favourited'], true);
|
return state.setIn([action.status.get('id'), 'favourited'], true);
|
||||||
|
case EMOJI_REACT_REQUEST:
|
||||||
|
const path = [action.status.get('id'), 'pleroma', 'emoji_reactions'];
|
||||||
|
const emojiReacts = state.getIn(path);
|
||||||
|
return state.setIn(path, simulateEmojiReact(emojiReacts, action.emoji));
|
||||||
case FAVOURITE_FAIL:
|
case FAVOURITE_FAIL:
|
||||||
return state.get(action.status.get('id')) === undefined ? state : state.setIn([action.status.get('id'), 'favourited'], false);
|
return state.get(action.status.get('id')) === undefined ? state : state.setIn([action.status.get('id'), 'favourited'], false);
|
||||||
case REBLOG_REQUEST:
|
case REBLOG_REQUEST:
|
||||||
|
|
|
@ -5,6 +5,7 @@ import {
|
||||||
oneEmojiPerAccount,
|
oneEmojiPerAccount,
|
||||||
reduceEmoji,
|
reduceEmoji,
|
||||||
getReactForStatus,
|
getReactForStatus,
|
||||||
|
simulateEmojiReact,
|
||||||
} from '../emoji_reacts';
|
} from '../emoji_reacts';
|
||||||
import { fromJS } from 'immutable';
|
import { fromJS } from 'immutable';
|
||||||
|
|
||||||
|
@ -179,3 +180,28 @@ describe('getReactForStatus', () => {
|
||||||
expect(getReactForStatus(status)).toEqual(undefined);
|
expect(getReactForStatus(status)).toEqual(undefined);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('simulateEmojiReact', () => {
|
||||||
|
it('adds the emoji to the list', () => {
|
||||||
|
const emojiReacts = fromJS([
|
||||||
|
{ 'count': 2, 'me': false, 'name': '👍' },
|
||||||
|
{ 'count': 2, 'me': false, 'name': '❤' },
|
||||||
|
]);
|
||||||
|
expect(simulateEmojiReact(emojiReacts, '❤')).toEqual(fromJS([
|
||||||
|
{ 'count': 2, 'me': false, 'name': '👍' },
|
||||||
|
{ 'count': 3, 'me': true, 'name': '❤' },
|
||||||
|
]));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('creates the emoji if it didn\'t already exist', () => {
|
||||||
|
const emojiReacts = fromJS([
|
||||||
|
{ 'count': 2, 'me': false, 'name': '👍' },
|
||||||
|
{ 'count': 2, 'me': false, 'name': '❤' },
|
||||||
|
]);
|
||||||
|
expect(simulateEmojiReact(emojiReacts, '😯')).toEqual(fromJS([
|
||||||
|
{ 'count': 2, 'me': false, 'name': '👍' },
|
||||||
|
{ 'count': 2, 'me': false, 'name': '❤' },
|
||||||
|
{ 'count': 1, 'me': true, 'name': '😯' },
|
||||||
|
]));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -83,3 +83,20 @@ export const getReactForStatus = status => {
|
||||||
).filter(e => e.get('me') === true)
|
).filter(e => e.get('me') === true)
|
||||||
.getIn([0, 'name']);
|
.getIn([0, 'name']);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const simulateEmojiReact = (emojiReacts, emoji) => {
|
||||||
|
const idx = emojiReacts.findIndex(e => e.get('name') === emoji);
|
||||||
|
if (idx > -1) {
|
||||||
|
const emojiReact = emojiReacts.get(idx);
|
||||||
|
return emojiReacts.set(idx, emojiReact.merge({
|
||||||
|
count: emojiReact.get('count') + 1,
|
||||||
|
me: true,
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
return emojiReacts.push(ImmutableMap({
|
||||||
|
count: 1,
|
||||||
|
me: true,
|
||||||
|
name: emoji,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue