Skip to content

Commit

Permalink
Bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
coddingtonjoel committed Sep 21, 2020
1 parent be96aaa commit cdaebd9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
23 changes: 12 additions & 11 deletions src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,32 @@ const App = () => {
const [redir, setRedir] = useState(false);
const [list, setList] = useContext(ListContext);

const getTotalSaved = (amount) => {
const getTotalSaved = amount => {
setTotalSaved(amount);
};

const getFinalPath = (path) => {
const getFinalPath = path => {
setFinalPath(path);
};

// counter for amount of incompatible types for each batch of dragged files
let incompatibleFiles = 0;

const sendFiles = (files) => {
const sendFiles = files => {
for (let file of files) {
file = file.path || file;

// if file is a folder, recursively check each file in the nested folders
if (fs.lstatSync(file).isDirectory()) {
// rename for clarity
let folder = file;
let files = fs.readdirSync(folder).map((fileName) => {
let files = fs.readdirSync(folder).map(fileName => {
return path.join(folder, fileName);
});
sendFiles(files);
} else {
// don't add duplicate files to list TODO THIS ISNT WORKING
if (list.some((item) => item.oPath === file.path)) {
if (list.some(item => item.oPath === file.path)) {
return false;
}
if (
Expand All @@ -61,7 +61,7 @@ const App = () => {
}
};

const handleFiles = (files) => {
const handleFiles = files => {
setRedir(<Redirect to="/list" />);
setLoading(
<div className="base-loader">
Expand Down Expand Up @@ -94,13 +94,13 @@ const App = () => {
}, 300);
};

document.ondragover = (e) => {
document.ondragover = e => {
e.preventDefault();
e.stopPropagation();
e.dataTransfer.dropEffect = "copy";
};

document.ondrop = (e) => {
document.ondrop = e => {
e.preventDefault();
e.stopPropagation();
handleFiles(e.dataTransfer.files);
Expand All @@ -110,6 +110,7 @@ const App = () => {
if (data.files !== undefined) {
console.log("success");
handleFiles(data.files);
setRedir(<Redirect to="/list" />);
}
});

Expand All @@ -129,7 +130,7 @@ const App = () => {
ipcRenderer.on("file:minified", (e, data) => {
// if item's path already exists on list, don't add it
// TODO: currently affected by memory leak bug if this if statement isn't here
if (list.some((item) => item.path === data.path)) {
if (list.some(item => item.path === data.path)) {
return false;
} else {
let newList = list;
Expand All @@ -152,10 +153,10 @@ const App = () => {
<Switch>
<Route exact path="/list">
<List
totalSaved={(amount) => {
totalSaved={amount => {
setTotalSaved(amount);
}}
finalPath={(path) => {
finalPath={path => {
setFinalPath(path);
}}
loading={loading}
Expand Down
10 changes: 1 addition & 9 deletions src/components/Start.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import drop from "../../assets/images/drop.svg";
import { ipcRenderer } from "electron";
import { ListContext } from "../context/ListContext";

const Start = (props) => {
const Start = props => {
const [list, setList] = useContext(ListContext);
const [redir, setRedir] = useState(false);

Expand All @@ -21,14 +21,6 @@ const Start = (props) => {
<div className="start-drop">
<img src={drop} draggable={false} alt="" />
<p>Drop files or folders here to minify.</p>
<div>
<p>or alternatively,</p>
<button
onClick={handleOpen}
className="btn waves-effect black-text list-button z-depth-1 start-open">
OPEN FILES
</button>
</div>
</div>
{redir}
</div>
Expand Down

0 comments on commit cdaebd9

Please sign in to comment.