Skip to content

Added auto fetching web page title when url pasted#411

Closed
ymtdzzz wants to merge 8 commits intoBoostIO:masterfrom
ymtdzzz:feature/auto-fetch-page-title
Closed

Added auto fetching web page title when url pasted#411
ymtdzzz wants to merge 8 commits intoBoostIO:masterfrom
ymtdzzz:feature/auto-fetch-page-title

Conversation

@ymtdzzz
Copy link
Copy Markdown
Contributor

@ymtdzzz ymtdzzz commented Apr 16, 2020

related issue: #410

Description

Added auto fetching web page title when url pasted.
I referred to the old BoostNote source code.

  • Paste handler
  • Setting
  • Translations
  • Tests

Screenshot

Setting
aaa

Behavior
screencast 2020-04-16 13-51-22

@ymtdzzz
Copy link
Copy Markdown
Contributor Author

ymtdzzz commented Apr 16, 2020

I've removed the statement that confirms that editor.origin isn't 'setValue' from the condition that calls the props.onChange(), will this cause any problems?

As far as I did some operations, no problems occured.

https://github.com/BoostIO/BoostNote.next/blob/d1528952a5d20ed8a08538edfac216d4d173d0e5/src/components/atoms/CodeEditor.tsx#L127-L129

@Rokt33r
Copy link
Copy Markdown
Member

Rokt33r commented Apr 16, 2020

#411 (comment) Please roll back it. It is needed for CodeMirror editor to distinguish where changes are from.

@ymtdzzz
Copy link
Copy Markdown
Contributor Author

ymtdzzz commented Apr 16, 2020

@Rokt33r

#411 (comment) Please roll back it. It is needed for CodeMirror editor to distinguish where changes are from.

Oh I understood.
I'm going to find another solution that doesn't use setValue().

- Rollbacked handleCodeMirrorChange()
- Implemented another solution which doesn't use setValue()
@ymtdzzz
Copy link
Copy Markdown
Contributor Author

ymtdzzz commented Apr 16, 2020

@Rokt33r
I rolled back it and implemented another solution which doesn't use setValue.

@ZeroX-DG ZeroX-DG added the awaiting review ❇️ Pull request is awaiting a review. label Apr 18, 2020
Comment thread src/lib/eventHandler/pasteHandler.ts Outdated
ch: change.from.ch + pastedText.length,
})

const response = await fetch(urlToFetch, { method: 'get' })
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm, I wonder if this will work on the web version once it's deployed, because when I test this on my machine there's a cors error.
image

Copy link
Copy Markdown
Contributor Author

@ymtdzzz ymtdzzz Apr 24, 2020

Choose a reason for hiding this comment

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

@ZeroX-DG
Thank you for your advice. That's right.
( I overlooked because I allowed cors in my local development environment ...)

To get this feature working on the web version in production environment I think:

(1) CORS permission setting on the Web server side (Access-Control-Allow-Origin *)
or
(2) Communicate via proxy server that CORS is allowed

(1) is not good for security, I think.
(2) is about the server configuration, so it's a little too complicated to solve here.

How about releasing this feature once as a feature for desktop and mobile apps?
If it's OK, I'll fix this feature so that it cannot be used from the Web version.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@zeroclock sounds good to me. In the future we could do something like this:
https://github.com/Rob--W/cors-anywhere/
But I think we need more discussion on that. Thus, targeting desktop and mobile app is good enough for now and we can disable that feature on web version and take care of it later.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We need a proxy server to deal with the cors issue for web app. And I don't wanna have the proxy server just for this feature because someone have to pay for it. So I think this feature should be available just for desktop app users(And mobile app users one day)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@ZeroX-DG @Rokt33r
I fixed the feature to be only for desktop and (partly) mobile version application.
Mobile platform detection using UserAgent is not perfect, so we may need to improve it in the future.

Copy link
Copy Markdown
Contributor

@Gogowitsch Gogowitsch left a comment

Choose a reason for hiding this comment

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

I am new to this repository. I find it surprising that there is no test coverage in this PR, as having multi-target source code is the holy grail of programming. As an outsider I suggest to stop developing features until adding tests for each new feature is straightforward.

Comment thread src/lib/eventHandler/pasteHandler.ts Outdated
ch: endCursor.ch + 1,
}
)
return prevChar === '](' && nextChar === ')'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe change variable name to prevChars, as it holds 2 characters?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I agree. I'll change prevChar to prevChars.

Comment thread src/lib/platform.ts Outdated
return true
}
return false
} No newline at end of file
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe add a new line at the end of the file? This makes some code viewing/editing experiences easier.

Comment thread src/lib/specs/http.spec.ts Outdated
res.headers.append('content-type', 'text/javascript')
expect(isImageResponse(res)).toBeFalsy()
})
}) No newline at end of file
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe add a new line at the end of the file? This makes some code viewing/editing experiences easier.

Comment thread src/locales/ptBR.ts
'preferences.editorKeymap': 'Funções das teclas',
'preferences.editorPreview': 'Pré visualização',
'preferences.enableAutoFetchWebPageTitle':
'Trazer o título da página da Web ao colar a URL no editor',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
'Trazer o título da página da Web ao colar a URL no editor',
'Trazer o título da página da Web ao colar uma URL no editor',

Copy link
Copy Markdown
Member

@Rokt33r Rokt33r left a comment

Choose a reason for hiding this comment

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

Electron also throws the CORS error too. We should make the http request from nodejs.

@ymtdzzz
Copy link
Copy Markdown
Contributor Author

ymtdzzz commented Jun 6, 2020

@fonata , thank you for your advice and code review!

@Rokt33r

Electron also throws the CORS error too. We should make the http request from nodejs.

I fixed this problem by fetching url on the nodejs side (main process).
Also, I changed the target of this feature to only desktop app.

Reasons:

  • There're possible bug due to incomplete platform detection by user-agent
  • This is only an extra feature
  • Simpler implementation (we only have to take care about desktop app)

Based on @Fonata 's opinion, we should implement this function for single platform first, and if implementing multi-platform features is simpler in the future, we can expand target platform according to people's needs.

Comment thread package.json Outdated
"appId": "com.boostio.boostnote",
"artifactName": "boost-note-${os}.${ext}",
"copyright": "Copyright © 2016-2017 BoostIO",
"copyright": "Copyright 2016-2017 BoostIO",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That's strange, can you change the new character back to the old © symbol?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe this is also just a good point to update the 2017 to 2020?

Copy link
Copy Markdown
Contributor Author

@ymtdzzz ymtdzzz Jun 10, 2020

Choose a reason for hiding this comment

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

It might have been mixed in when I temporarily worked on Windows...I'll fix it.

Maybe this is also just a good point to update the 2017 to 2020?

It sounds good to me, but I don't know if it's okay to deal with it here.
@ZeroX-DG , how do you think?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yea, I think it will be alright:) it's just updating the year, it's not gonna break anything I think:)

Comment thread src/lib/eventHandler/pasteHandler.ts Outdated
if (ipcRenderer !== null) {
ipcRenderer.on('fetch-page-title-response', async (_, fetchResult: FetchResult) => {
let replacement = info.pastedText
if (!isImageResponse(fetchResult.contentType)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of checking if the response is a image response. Why don't we check for text/html content type only? This will cover other cases for other files such as video and audio.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think you're right. I'll change it to check if contentType is simply 'text/html'.

@ZeroX-DG ZeroX-DG added awaiting changes 🖊️ Pull request has been reviewed, but contributor needs to make changes. and removed awaiting review ❇️ Pull request is awaiting a review. labels Jun 8, 2020
@Flexo013 Flexo013 added awaiting review ❇️ Pull request is awaiting a review. and removed awaiting changes 🖊️ Pull request has been reviewed, but contributor needs to make changes. labels Jun 10, 2020
@Rokt33r Rokt33r force-pushed the feature/auto-fetch-page-title branch from 6a9adf4 to 21bc392 Compare August 14, 2020 07:49
@Rokt33r
Copy link
Copy Markdown
Member

Rokt33r commented Nov 3, 2020

This will be reworked on Nov 11th

@Rokt33r Rokt33r closed this Aug 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review ❇️ Pull request is awaiting a review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants