-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Image upload #18
base: master
Are you sure you want to change the base?
Image upload #18
Conversation
…to 'window manager'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You also created a branch from the branch you used to your other PR so you send the whole code of that PR here.
renderer/pages/index.js
Outdated
@@ -70,7 +71,7 @@ export default class extends Component { | |||
) | |||
} | |||
|
|||
handleDrop = event => event.preventDefault() | |||
handleDrop = e => imageDrop(e, this) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't do this, be explicit, e
could be event
or error
or whatever.
renderer/components/image-drop.js
Outdated
@@ -0,0 +1,57 @@ | |||
// validate file format with a list of format supports imgur | |||
let validateFile = (file) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use const, only use let if you realize you need to change this variable later (tip: never do it, use immutable code)
renderer/components/image-drop.js
Outdated
@@ -0,0 +1,57 @@ | |||
// validate file format with a list of format supports imgur | |||
let validateFile = (file) => { | |||
let imageFormat = ['jpeg', 'png', 'gif', 'peg', 'apng', 'tiff', 'pdf', 'xcf'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use const, only use let if you realize you need to change this variable later (tip: never do it, use immutable code)
renderer/components/image-drop.js
Outdated
let validateFile = (file) => { | ||
let imageFormat = ['jpeg', 'png', 'gif', 'peg', 'apng', 'tiff', 'pdf', 'xcf'] | ||
return imageFormat.filter((kind) => { | ||
let res = new RegExp("\\b(" + kind + ")\\b") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use const, only use let if you realize you need to change this variable later (tip: never do it, use immutable code)
renderer/components/image-drop.js
Outdated
|
||
// send file via XMLHTTP | ||
let sendData = (_this, file) => { | ||
let fd = new FormData() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use const, only use let if you realize you need to change this variable later (tip: never do it, use immutable code)
Be explicit, use formData not fd, fd doesn't say anything about what's inside
renderer/components/image-drop.js
Outdated
// without 'preventDefault', when you drop the image, change the whole editor view | ||
e.preventDefault() | ||
let event = {} | ||
let file = e.dataTransfer.files[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use const, only use let if you realize you need to change this variable later (tip: never do it, use immutable code)
renderer/components/image-drop.js
Outdated
let valido = validateFile(file) | ||
if (!!valido && valido.length !== 0) { | ||
sendData(_this, file) | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use else
, just return
inside the if
renderer/components/image-drop.js
Outdated
if (!!valido && valido.length !== 0) { | ||
sendData(_this, file) | ||
} else { | ||
event.target = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid mutations
renderer/components/image-drop.js
Outdated
@@ -0,0 +1,57 @@ | |||
// validate file format with a list of format supports imgur |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole file is not a component, is a lib, move it to another directory.
renderer/pages/index.js
Outdated
@@ -21,6 +21,8 @@ import Save from '../components/save-button' | |||
import Open from '../components/open-button' | |||
import New from '../components/new-button' | |||
import Export from '../components/export-button' | |||
import Create from '../components/window-button' | |||
import imageDrop from '../components/image-drop' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside of that file not being a component it's only used inside this page so it doesn't need to be externalized
Sergio, I have a doubt. |
renderer/pages/index.js
Outdated
'Authorization': `Client-ID e3f6a51d5c12580` | ||
}, | ||
body: imageData}) | ||
.then(response => response.json()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Async/Await
@demian-arenas each feature should be a PR |
Now, Pulse can upload an image with only Drop a local image onto the editor, this image upload to Imgur and automatically sets the image in the Markdown file.
If the file who drops onto editor isn't supported by Imgur, it inserts schema of an image but with message 'Problem with the format file'. like this
![Problem with the format file](url)