Make it possible to open .md files with ation from system #2
Merged
miko
merged 5 commits from feature/open-with
into development
3 years ago
13 changed files with 169 additions and 54 deletions
After Width: | Height: | Size: 1.1 KiB |
@ -0,0 +1,42 @@ |
||||
import React, {useState} from "react"; |
||||
|
||||
const extension = filename => { |
||||
const parts = filename.split('.'); |
||||
|
||||
return parts[parts.length - 1]; |
||||
}; |
||||
|
||||
const withDrop = Component => () => { |
||||
const [drag, setDrag] = useState(false); |
||||
|
||||
const handleDragOver = event => { |
||||
event.preventDefault(); |
||||
event.stopPropagation(); |
||||
setDrag(true); |
||||
}; |
||||
|
||||
const handleDragLeave = event => { |
||||
event.preventDefault(); |
||||
event.stopPropagation(); |
||||
setDrag(false); |
||||
} |
||||
|
||||
const handleDrop = event => { |
||||
event.preventDefault(); |
||||
event.stopPropagation(); |
||||
const file = event.dataTransfer?.items[0].getAsFile(); |
||||
if (extension(file.name.toLowerCase()) === "md") { |
||||
window.api.openFile(file.path); |
||||
} |
||||
setDrag(false); |
||||
}; |
||||
|
||||
return ( |
||||
<section onDragLeave={handleDragLeave} onDragOver={handleDragOver} onDrop={handleDrop} style={{opacity : drag ? 0.2 : 1}}> |
||||
<Component /> |
||||
</section> |
||||
); |
||||
}; |
||||
|
||||
|
||||
export default withDrop; |
@ -1,13 +1,16 @@ |
||||
import React from "react"; |
||||
import ReactDOM from "react-dom/client"; |
||||
|
||||
import Ation from "./components/Ation"; |
||||
import Ation from "./components/Ation"; |
||||
import withDrop from "./higherOrderComponents/withDrop"; |
||||
|
||||
import "./assets/css/ation.scss"; |
||||
|
||||
const App = withDrop(Ation); |
||||
|
||||
const root = ReactDOM.createRoot(document.getElementById("root")); |
||||
root.render( |
||||
<React.StrictMode> |
||||
<Ation /> |
||||
<App /> |
||||
</React.StrictMode> |
||||
); |
Loading…
Reference in new issue