Skip to content
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

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

Conversation

demian-arenas
Copy link

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)

Copy link
Contributor

@sergiodxa sergiodxa left a 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.

@@ -70,7 +71,7 @@ export default class extends Component {
)
}

handleDrop = event => event.preventDefault()
handleDrop = e => imageDrop(e, this)
Copy link
Contributor

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.

@@ -0,0 +1,57 @@
// validate file format with a list of format supports imgur
let validateFile = (file) => {
Copy link
Contributor

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)

@@ -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']
Copy link
Contributor

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)

let validateFile = (file) => {
let imageFormat = ['jpeg', 'png', 'gif', 'peg', 'apng', 'tiff', 'pdf', 'xcf']
return imageFormat.filter((kind) => {
let res = new RegExp("\\b(" + kind + ")\\b")
Copy link
Contributor

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)


// send file via XMLHTTP
let sendData = (_this, file) => {
let fd = new FormData()
Copy link
Contributor

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

// without 'preventDefault', when you drop the image, change the whole editor view
e.preventDefault()
let event = {}
let file = e.dataTransfer.files[0]
Copy link
Contributor

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)

let valido = validateFile(file)
if (!!valido && valido.length !== 0) {
sendData(_this, file)
} else {
Copy link
Contributor

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

if (!!valido && valido.length !== 0) {
sendData(_this, file)
} else {
event.target = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid mutations

@@ -0,0 +1,57 @@
// validate file format with a list of format supports imgur
Copy link
Contributor

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.

@@ -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'
Copy link
Contributor

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

@demian-arenas
Copy link
Author

Sergio, I have a doubt.
I also want to contribute to the issue of 'Dark Mode' and 'Pulse Protocol'. I send that enhancement at once in this PR or in another?

'Authorization': `Client-ID e3f6a51d5c12580`
},
body: imageData})
.then(response => response.json())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Async/Await

@sergiodxa
Copy link
Contributor

@demian-arenas each feature should be a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants