about summary refs log tree commit diff
path: root/app/javascript/glitch/components/notification/container.js
blob: dc4c2168a97123e886778057397d302a8f7f01e9 (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
/*

`<NotificationContainer>`
=========================

This container connects `<Notification>`s to the Redux store.

*/

//  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

/*

Imports:
--------

*/

//  Package imports  //
import { connect } from 'react-redux';

//  Our imports  //
import Notification from '.';

//  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

const mapStateToProps = (state, props) => {
  // replace account id with object
  let leNotif = props.notification.set('account', state.getIn(['accounts', props.notification.get('account')]));

  // populate markedForDelete from state - is mysteriously lost somewhere
  for (let n of state.getIn(['notifications', 'items'])) {
    if (n.get('id') === props.notification.get('id')) {
      leNotif = leNotif.set('markedForDelete', n.get('markedForDelete'));
      break;
    }
  }

  return ({
    notification: leNotif,
    settings: state.get('local_settings'),
    notifCleaning: state.getIn(['notifications', 'cleaningMode']),
  });
};

//  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

export default connect(mapStateToProps)(Notification);