Use redux hooks on buttons components
This commit is contained in:
parent
81f497170f
commit
6ac382b659
@ -1,7 +1,7 @@
|
|||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
import { List } from "immutable";
|
import { List } from "immutable";
|
||||||
import { connect } from "react-redux";
|
import { useDispatch } from "react-redux";
|
||||||
|
|
||||||
import { prettySize } from "../../utils";
|
import { prettySize } from "../../utils";
|
||||||
import { addTorrent } from "../../actions/torrents";
|
import { addTorrent } from "../../actions/torrents";
|
||||||
@ -45,10 +45,10 @@ function buildMenuItems(torrents) {
|
|||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
const torrentsButton = ({ torrents, search, searching, addTorrent, url }) => {
|
export const TorrentsButton = ({ torrents, search, searching, url }) => {
|
||||||
/* eslint-disable */
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
const [show, setShow] = useState(false);
|
const [show, setShow] = useState(false);
|
||||||
/* eslint-enable */
|
|
||||||
const entries = buildMenuItems(torrents);
|
const entries = buildMenuItems(torrents);
|
||||||
const count = torrents && torrents.size !== 0 ? torrents.size : 0;
|
const count = torrents && torrents.size !== 0 ? torrents.size : 0;
|
||||||
|
|
||||||
@ -97,7 +97,10 @@ const torrentsButton = ({ torrents, search, searching, addTorrent, url }) => {
|
|||||||
return <Dropdown.Divider key={index} />;
|
return <Dropdown.Divider key={index} />;
|
||||||
case "entry":
|
case "entry":
|
||||||
return (
|
return (
|
||||||
<Dropdown.Item key={index} onClick={() => addTorrent(e.url)}>
|
<Dropdown.Item
|
||||||
|
key={index}
|
||||||
|
onClick={() => dispatch(addTorrent(e.url))}
|
||||||
|
>
|
||||||
{e.quality}
|
{e.quality}
|
||||||
{e.size !== 0 && (
|
{e.size !== 0 && (
|
||||||
<small className="ml-1">({prettySize(e.size)})</small>
|
<small className="ml-1">({prettySize(e.size)})</small>
|
||||||
@ -111,15 +114,12 @@ const torrentsButton = ({ torrents, search, searching, addTorrent, url }) => {
|
|||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
torrentsButton.propTypes = {
|
TorrentsButton.propTypes = {
|
||||||
torrents: PropTypes.instanceOf(List),
|
torrents: PropTypes.instanceOf(List),
|
||||||
searching: PropTypes.bool,
|
searching: PropTypes.bool,
|
||||||
search: PropTypes.func.isRequired,
|
search: PropTypes.func.isRequired,
|
||||||
addTorrent: PropTypes.func.isRequired,
|
|
||||||
url: PropTypes.string,
|
url: PropTypes.string,
|
||||||
};
|
};
|
||||||
torrentsButton.defaultProps = {
|
TorrentsButton.defaultProps = {
|
||||||
torrents: List(),
|
torrents: List(),
|
||||||
};
|
};
|
||||||
|
|
||||||
export const TorrentsButton = connect(null, { addTorrent })(torrentsButton);
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user