Skip to content

Commit

Permalink
add transfer interruptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Niweera committed May 30, 2022
1 parent a5f3e81 commit fdedb4d
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 2 deletions.
Binary file modified animated.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ const TransferringComponent = ({ classes, dbPath }) => {
<TransferringItem
data={obj}
classes={classes}
dbPath={dbPath}
key={obj.key}
id={obj.key}
/>
Expand Down
60 changes: 58 additions & 2 deletions src/components/Transfers/BluePrints/TransferringItem.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useCallback, useState } from "react";
import Typography from "@mui/material/Typography";
import LinearProgress from "@mui/material/LinearProgress";
import Box from "@mui/material/Box";
Expand All @@ -10,16 +10,38 @@ import { faSync } from "@fortawesome/free-solid-svg-icons/faSync";
import ListItemText from "@mui/material/ListItemText";
import CustomizedToolTip from "../../../helpers/CustomizedToolTip";
import { get } from "lodash";
import ConfirmationDialog from "../../../helpers/ConfirmationDialog";
import { common, red } from "@mui/material/colors";
import RemoveCircleIcon from "@mui/icons-material/RemoveCircle";
import { interruptTransfer } from "../../../store/actions";
import { useFirebase } from "react-redux-firebase";

/**
*
* @param {object} data
* @param {object} classes
* @param {string} dbPath
* @param {string} id
* @returns {JSX.Element}
* @constructor
*/
const TransferringItem = ({ data, classes, id }) => {
const TransferringItem = ({ data, classes, dbPath, id }) => {
const [open, setOpen] = useState(false);
const firebase = useFirebase();

const handleClose = useCallback(() => {
setOpen(false);
}, []);

const onInterruptTransfer = useCallback(
() => interruptTransfer(dbPath, id)(firebase),
[firebase, dbPath, id]
);

const handleInterruptions = useCallback(() => {
setOpen(true);
}, []);

return (
<React.Fragment key={id}>
<ListItem alignItems="flex-start" className={classes.glass}>
Expand Down Expand Up @@ -72,6 +94,40 @@ const TransferringItem = ({ data, classes, id }) => {
</React.Fragment>
}
/>
<ListItemAvatar
sx={{
display: "flex",
justifyContent: "flex-end",
}}
>
<ConfirmationDialog
id="interrupt-transfer"
keepMounted
open={open}
onClose={handleClose}
primaryMessage={"Interrupt transfer"}
secondaryMessage={
"Now you are going to interrupt the transferring job"
}
action={onInterruptTransfer}
/>
<CustomizedToolTip arrow placement="top" title="Remove">
<Avatar
sx={{
width: 24,
height: 24,
bgcolor: common["black"],
cursor: "pointer",
}}
onClick={handleInterruptions}
>
<RemoveCircleIcon
sx={{ color: red["A700"] }}
fontSize="inherit"
/>
</Avatar>
</CustomizedToolTip>
</ListItemAvatar>
</ListItem>
</React.Fragment>
);
Expand Down
1 change: 1 addition & 0 deletions src/store/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export {
removeTorrents,
queueMegaTransfer,
readNotifications,
interruptTransfer,
} from "./userActions";

export {
Expand Down
14 changes: 14 additions & 0 deletions src/store/actions/userActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,20 @@ export const removeTransferred = (dbPath, key) => async (firebase) => {
}
};

export const interruptTransfer = (dbPath, key) => async (firebase) => {
const trace = perfmon.trace("interruptTransfer");
trace.start();
trace.putAttribute("dbPath", dbPath);
try {
const uid = await firebase.auth().currentUser.uid;
await firebase.set(`interruptions/${uid}/${dbPath}/${key}`, true);
trace.stop();
} catch (e) {
trace.stop();
console.log(e.message);
}
};

export const removeTorrents = (dbPath, key) => async (firebase) => {
const trace = perfmon.trace("removeTorrents");
trace.start();
Expand Down

0 comments on commit fdedb4d

Please sign in to comment.