about summary refs log tree commit diff
path: root/app/assets/javascripts/components/containers/status_container.jsx
blob: 5e0b489b3e10ec86624d7713ba1829b2f5f7fe10 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { connect }       from 'react-redux';
import Status            from '../components/status';
import { makeGetStatus } from '../selectors';
import {
  replyCompose,
  mentionCompose
}                        from '../actions/compose';
import {
  reblog,
  favourite,
  unreblog,
  unfavourite
}                        from '../actions/interactions';
import { deleteStatus }  from '../actions/statuses';
import { openMedia }     from '../actions/modal';

const makeMapStateToProps = () => {
  const getStatus = makeGetStatus();

  const mapStateToProps = (state, props) => ({
    status: getStatus(state, props.id),
    me: state.getIn(['meta', 'me'])
  });

  return mapStateToProps;
};

const mapDispatchToProps = (dispatch) => ({

  onReply (status) {
    dispatch(replyCompose(status));
  },

  onReblog (status) {
    if (status.get('reblogged')) {
      dispatch(unreblog(status));
    } else {
      dispatch(reblog(status));
    }
  },

  onFavourite (status) {
    if (status.get('favourited')) {
      dispatch(unfavourite(status));
    } else {
      dispatch(favourite(status));
    }
  },

  onDelete (status) {
    dispatch(deleteStatus(status.get('id')));
  },

  onMention (account) {
    dispatch(mentionCompose(account));
  },

  onOpenMedia (url) {
    dispatch(openMedia(url));
  }

});

export default connect(makeMapStateToProps, mapDispatchToProps)(Status);