Skip to content

Commit fdedb4d

Browse files
committed
add transfer interruptions
1 parent a5f3e81 commit fdedb4d

File tree

5 files changed

+74
-2
lines changed

5 files changed

+74
-2
lines changed

animated.gif

274 KB
Loading

src/components/Transfers/BluePrints/TransferringComponent.js

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ const TransferringComponent = ({ classes, dbPath }) => {
116116
<TransferringItem
117117
data={obj}
118118
classes={classes}
119+
dbPath={dbPath}
119120
key={obj.key}
120121
id={obj.key}
121122
/>

src/components/Transfers/BluePrints/TransferringItem.js

+58-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from "react";
1+
import React, { useCallback, useState } from "react";
22
import Typography from "@mui/material/Typography";
33
import LinearProgress from "@mui/material/LinearProgress";
44
import Box from "@mui/material/Box";
@@ -10,16 +10,38 @@ import { faSync } from "@fortawesome/free-solid-svg-icons/faSync";
1010
import ListItemText from "@mui/material/ListItemText";
1111
import CustomizedToolTip from "../../../helpers/CustomizedToolTip";
1212
import { get } from "lodash";
13+
import ConfirmationDialog from "../../../helpers/ConfirmationDialog";
14+
import { common, red } from "@mui/material/colors";
15+
import RemoveCircleIcon from "@mui/icons-material/RemoveCircle";
16+
import { interruptTransfer } from "../../../store/actions";
17+
import { useFirebase } from "react-redux-firebase";
1318

1419
/**
1520
*
1621
* @param {object} data
1722
* @param {object} classes
23+
* @param {string} dbPath
1824
* @param {string} id
1925
* @returns {JSX.Element}
2026
* @constructor
2127
*/
22-
const TransferringItem = ({ data, classes, id }) => {
28+
const TransferringItem = ({ data, classes, dbPath, id }) => {
29+
const [open, setOpen] = useState(false);
30+
const firebase = useFirebase();
31+
32+
const handleClose = useCallback(() => {
33+
setOpen(false);
34+
}, []);
35+
36+
const onInterruptTransfer = useCallback(
37+
() => interruptTransfer(dbPath, id)(firebase),
38+
[firebase, dbPath, id]
39+
);
40+
41+
const handleInterruptions = useCallback(() => {
42+
setOpen(true);
43+
}, []);
44+
2345
return (
2446
<React.Fragment key={id}>
2547
<ListItem alignItems="flex-start" className={classes.glass}>
@@ -72,6 +94,40 @@ const TransferringItem = ({ data, classes, id }) => {
7294
</React.Fragment>
7395
}
7496
/>
97+
<ListItemAvatar
98+
sx={{
99+
display: "flex",
100+
justifyContent: "flex-end",
101+
}}
102+
>
103+
<ConfirmationDialog
104+
id="interrupt-transfer"
105+
keepMounted
106+
open={open}
107+
onClose={handleClose}
108+
primaryMessage={"Interrupt transfer"}
109+
secondaryMessage={
110+
"Now you are going to interrupt the transferring job"
111+
}
112+
action={onInterruptTransfer}
113+
/>
114+
<CustomizedToolTip arrow placement="top" title="Remove">
115+
<Avatar
116+
sx={{
117+
width: 24,
118+
height: 24,
119+
bgcolor: common["black"],
120+
cursor: "pointer",
121+
}}
122+
onClick={handleInterruptions}
123+
>
124+
<RemoveCircleIcon
125+
sx={{ color: red["A700"] }}
126+
fontSize="inherit"
127+
/>
128+
</Avatar>
129+
</CustomizedToolTip>
130+
</ListItemAvatar>
75131
</ListItem>
76132
</React.Fragment>
77133
);

src/store/actions/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export {
88
removeTorrents,
99
queueMegaTransfer,
1010
readNotifications,
11+
interruptTransfer,
1112
} from "./userActions";
1213

1314
export {

src/store/actions/userActions.js

+14
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,20 @@ export const removeTransferred = (dbPath, key) => async (firebase) => {
107107
}
108108
};
109109

110+
export const interruptTransfer = (dbPath, key) => async (firebase) => {
111+
const trace = perfmon.trace("interruptTransfer");
112+
trace.start();
113+
trace.putAttribute("dbPath", dbPath);
114+
try {
115+
const uid = await firebase.auth().currentUser.uid;
116+
await firebase.set(`interruptions/${uid}/${dbPath}/${key}`, true);
117+
trace.stop();
118+
} catch (e) {
119+
trace.stop();
120+
console.log(e.message);
121+
}
122+
};
123+
110124
export const removeTorrents = (dbPath, key) => async (firebase) => {
111125
const trace = perfmon.trace("removeTorrents");
112126
trace.start();

0 commit comments

Comments
 (0)