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

Feature: implement button for GitHub and Stack Overflow #3

Merged
merged 8 commits into from
Oct 9, 2019

Conversation

kaicataldo
Copy link
Member

@kaicataldo kaicataldo commented Oct 9, 2019

I took a crack at implementing this! To get this working, I downloaded and added the standalone build and the parsers from https://prettier.io/lib/*.js. This obviously isn't ideal, but I figured the team would know best how to go about getting the standalone build in the extension!

Some other notes:

  1. ext/_locales/en/messages.json is necessary because a default_locale is listed in manifest.json. So far, this is a very easy thing to translate (there's only one string to display!), and it seems like it would be worthwhile.
  2. GitHub was easy because comments are all markdown!
  3. Stack Overflow is trickier because it uses a different syntax to denote the language of code snippets.
  4. It would be great to have some kind of icon that fits the Stack Overflow design better, but I think this is a good MVP!

For reference, here's what it currently looks like:

Stack Overflow:
Screen Shot 2019-10-09 at 1 28 48 AM

GitHub:
Screen Shot 2019-10-09 at 1 28 58 AM

@kaicataldo kaicataldo force-pushed the add-button branch 2 times, most recently from 0d70884 to 3f660a7 Compare October 9, 2019 06:37
ext/src/content/content.js Outdated Show resolved Hide resolved
ext/src/content/content.js Outdated Show resolved Hide resolved
@LOLdevelopr
Copy link

Great. This extension is really going to help a lot in these website.

"node": true
},
"plugins": ["prettier"],
"extends": ["prettier"],
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module",
"sourceType": "script",
Copy link
Member Author

Choose a reason for hiding this comment

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

We're not currently using modules, so I think this is safer?

{
"files": ["ext/**/*"],
"env": {
"browser": true
Copy link
Member Author

@kaicataldo kaicataldo Oct 9, 2019

Choose a reason for hiding this comment

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

Scoping the browser env to just the files that are executed by the browser.

"no-else-return": 2,
"no-inner-declarations": 2,
"no-lonely-if": 2,
"curly": "error",
Copy link
Member Author

@kaicataldo kaicataldo Oct 9, 2019

Choose a reason for hiding this comment

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

I'm a maintainer of ESLint, and we generally recommend using "error"|"warn"|"off" instead of numbers for clarity!

@kaicataldo
Copy link
Member Author

Sorry, diff got a little weird with the renamed files after the rebase. I realized that this doesn't implement the button for the GitHub Issues view, but I think it would be nice to land this and follow up with that if the team is amenable to that.

@lipis
Copy link
Member

lipis commented Oct 9, 2019

So what works now?! (Will be able to test in few)

@kaicataldo
Copy link
Member Author

kaicataldo commented Oct 9, 2019

Should work on StackOverflow and GitHub Pull Requests (both the conversation and code diff views) and Commit views.

@kaicataldo
Copy link
Member Author

I'd like to figure out a better way to detect the when to render the buttons for the GitHub view (since editable comments can be created on the fly) so that we can render it immediately (instead of waiting until the user inputs text), but I think this is a good MVP to build on.

@lipis
Copy link
Member

lipis commented Oct 9, 2019

It didn't work for me.. On SO I can see the button, but it doesn't seem to do anything, and can't see it on GitHub..

@kaicataldo
Copy link
Member Author

Hmmm strange - here's what I'm seeing:
2019-10-09 14 07 03

@lipis
Copy link
Member

lipis commented Oct 9, 2019

are you sure you committed all the files?

@kaicataldo
Copy link
Member Author

Ah, I'm seeing it go in and out on GitHub - sometimes it works and sometimes it doesn't. I assumed it was all prerendered because it feels blazing fast to me and I was seeing it work locally all the time, but it's most likely that sometimes the element it's binding to isn't on the page when it runs. Will probably have to do something similar to the SO one and poll for the element to be in the document.

@lipis
Copy link
Member

lipis commented Oct 9, 2019

It's a great start for sure 😊

@kaicataldo
Copy link
Member Author

kaicataldo commented Oct 9, 2019

For reference, here's what it looks like on GitHub for me (when it works 😄):

2019-10-09 14 13 55

@kaicataldo
Copy link
Member Author

Can you see if that fixes it for you? The Prettier button should appear when you start editing a comment. I think we can definitely come up with a better check that makes the button appear when the comment appears (would be a nicer UX), but I thought this was a good first pass to get the basic functionality :)

@lipis
Copy link
Member

lipis commented Oct 9, 2019

The button disappears when answering anonymously on SO

@lipis
Copy link
Member

lipis commented Oct 9, 2019

So the button works (on SO) when there is code in the answer.. otherwise it doesn't formats the markdown (for example fixing the links and lists, spaces).

@kaicataldo
Copy link
Member Author

kaicataldo commented Oct 9, 2019

So the button works (on SO) when there is code in the answer.. otherwise it doesn't formats the markdown (for example fixing the links and lists, spaces).

This is fixed! I didn't realize you could post anonymously on SO 😅

@lipis
Copy link
Member

lipis commented Oct 9, 2019

I think it's a pretty solid start.. Merging it if you don't have anything to add at this point.

@kaicataldo
Copy link
Member Author

Sounds good! Definitely lots of room for improvement :)

@lipis lipis merged commit 5e507aa into prettier:master Oct 9, 2019
@kaicataldo kaicataldo deleted the add-button branch October 9, 2019 19:22
@lipis
Copy link
Member

lipis commented Oct 9, 2019

Do you mind adding issues with things needs to be done or improved, optimized whatever you think of so we won't forget anything.

@kaicataldo
Copy link
Member Author

Already on it 😄

@kaicataldo
Copy link
Member Author

Also, thanks for the quick reviews! ❤️

This was referenced Oct 10, 2019
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.

3 participants