~cytrogen/masto-fe

ref: f8dc013b0d81d5d463c086e291ce99ab1d796a9d masto-fe/app/javascript/mastodon/containers/dropdown_menu_container.js -rw-r--r-- 1.2 KiB
f8dc013b — Cytrogen [feature] Add language selector to local settings 4 days ago
                                                                                
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
import { connect } from "react-redux";

import { fetchRelationships } from "mastodon/actions/accounts";

import { openDropdownMenu, closeDropdownMenu } from "../actions/dropdown_menu";
import { openModal, closeModal } from "../actions/modal";
import DropdownMenu from "../components/dropdown_menu";
import { isUserTouching } from "../is_mobile";

/**
 * @param {import('mastodon/store').RootState} state
 */
const mapStateToProps = state => ({
  openDropdownId: state.dropdownMenu.openId,
  openedViaKeyboard: state.dropdownMenu.keyboard,
});

const mapDispatchToProps = (dispatch, { status, items, scrollKey }) => ({
  onOpen(id, onItemClick, keyboard) {
    if (status) {
      dispatch(fetchRelationships([status.getIn(["account", "id"])]));
    }

    dispatch(isUserTouching() ? openModal({
      modalType: "ACTIONS",
      modalProps: {
        status,
        actions: items,
        onClick: onItemClick,
      },
    }) : openDropdownMenu({ id, keyboard, scrollKey }));
  },

  onClose(id) {
    dispatch(closeModal({
      modalType: "ACTIONS",
      ignoreFocus: false,
    }));
    dispatch(closeDropdownMenu({ id }));
  },
});

export default connect(mapStateToProps, mapDispatchToProps)(DropdownMenu);