The code powering m.abunchtell.com https://m.abunchtell.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

114 lines
2.7 KiB

  1. import { connect } from 'react-redux';
  2. import Status from '../components/status';
  3. import { makeGetStatus } from '../selectors';
  4. import {
  5. replyCompose,
  6. mentionCompose
  7. } from '../actions/compose';
  8. import {
  9. reblog,
  10. favourite,
  11. unreblog,
  12. unfavourite
  13. } from '../actions/interactions';
  14. import { blockAccount } from '../actions/accounts';
  15. import { deleteStatus } from '../actions/statuses';
  16. import { initReport } from '../actions/reports';
  17. import { openMedia } from '../actions/modal';
  18. import { createSelector } from 'reselect'
  19. import { isMobile } from '../is_mobile'
  20. const mapStateToProps = (state, props) => ({
  21. statusBase: state.getIn(['statuses', props.id]),
  22. me: state.getIn(['meta', 'me'])
  23. });
  24. const makeMapStateToPropsInner = () => {
  25. const getStatus = (() => {
  26. return createSelector(
  27. [
  28. (_, base) => base,
  29. (state, base) => (base ? state.getIn(['accounts', base.get('account')]) : null),
  30. (state, base) => (base ? state.getIn(['statuses', base.get('reblog')], null) : null)
  31. ],
  32. (base, account, reblog) => (base ? base.set('account', account).set('reblog', reblog) : null)
  33. );
  34. })();
  35. const mapStateToProps = (state, { statusBase }) => ({
  36. status: getStatus(state, statusBase)
  37. });
  38. return mapStateToProps;
  39. };
  40. const makeMapStateToPropsLast = () => {
  41. const getStatus = (() => {
  42. return createSelector(
  43. [
  44. (_, status) => status,
  45. (state, status) => (status ? state.getIn(['accounts', status.getIn(['reblog', 'account'])], null) : null)
  46. ],
  47. (status, reblogAccount) => (status && status.get('reblog') ? status.setIn(['reblog', 'account'], reblogAccount) : status)
  48. );
  49. })();
  50. const mapStateToProps = (state, { status }) => ({
  51. status: getStatus(state, status)
  52. });
  53. return mapStateToProps;
  54. };
  55. const mapDispatchToProps = (dispatch) => ({
  56. onReply (status, router) {
  57. dispatch(replyCompose(status, router));
  58. },
  59. onReblog (status) {
  60. if (status.get('reblogged')) {
  61. dispatch(unreblog(status));
  62. } else {
  63. dispatch(reblog(status));
  64. }
  65. },
  66. onFavourite (status) {
  67. if (status.get('favourited')) {
  68. dispatch(unfavourite(status));
  69. } else {
  70. dispatch(favourite(status));
  71. }
  72. },
  73. onDelete (status) {
  74. dispatch(deleteStatus(status.get('id')));
  75. },
  76. onMention (account, router) {
  77. dispatch(mentionCompose(account, router));
  78. },
  79. onOpenMedia (media, index) {
  80. dispatch(openMedia(media, index));
  81. },
  82. onBlock (account) {
  83. dispatch(blockAccount(account.get('id')));
  84. },
  85. onReport (status) {
  86. dispatch(initReport(status.get('account'), status));
  87. }
  88. });
  89. export default connect(mapStateToProps, mapDispatchToProps)(
  90. connect(makeMapStateToPropsInner)(
  91. connect(makeMapStateToPropsLast)(Status)
  92. )
  93. );