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

Add optimistic rendering to article reactions #681

Merged
merged 5 commits into from Nov 7, 2018

Conversation

gatlee
Copy link
Contributor

@gatlee gatlee commented Sep 17, 2018

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Documentation Update

Description

Added optimistic rendering.

I am quite new to to this so I'm not sure how to write tests for it. If any tests should be written I can try to.

Additionally, ESLint tests did not pass after the commit. However, before I started work on the commit, it did not pass either. I have tried to the best of my ability to follow code guidelines in the areas I modified but have not refactored or cleaned up the other parts of the code.

Any suggestions are welcome!
Thanks
Gatlee Kaw

Related Tickets & Documents

#443

Mobile & Desktop Screenshots/Recordings (if there are UI changes)

Image

Added to documentation?

  • docs.dev.to
  • readme
  • no documentation needed

[optional] What gif best describes this PR or how it makes you feel?

alt-text

@CLAassistant
Copy link

CLAassistant commented Sep 17, 2018

CLA assistant check
All committers have signed the CLA.

@gatlee gatlee changed the title Reactions optimistic rendering Add optimistic rendering to article reactions Sep 17, 2018
@gatlee
Copy link
Contributor Author

gatlee commented Sep 19, 2018

I noticed that there is a version of the reaction buttons implemented in Preact which already has optimistic rendering. Is the plan to migrate that component over to that?

@benhalpern
Copy link
Contributor

@gatlee yeah, that is the plan. But I could see us merging this in the meantime.

Since you're already engaged in this, would you be interested in attempting to rewrite the whole article reactions area as a preact component?

It's not an immediate team priority, so we'll review and likely merge the current change unless you want to jump the line and write the preact version. Let me know what your capacity for this is.

@gatlee
Copy link
Contributor Author

gatlee commented Sep 21, 2018

Awesome! I look forward to the feedback.

Also, I'd be happy to work on a preact version of the component. I believe I'd be capable of doing so. I'll get working on it soon!

@gatlee
Copy link
Contributor Author

gatlee commented Oct 2, 2018

Did a minor update to the code to revert the optimistic render on error. Not entirely sure why such a minor change resulted in a test failure however.

@gatlee
Copy link
Contributor Author

gatlee commented Oct 2, 2018

@benhalpern On a side note: I haven't been able to work much on porting it to Preact since I've been quite busy. It might be better to review and merge this since in the meantime I probably won't have time to finish the port very soon

I had a small technical question too. So far I've added a Reactions.jsx which loads with a javascript_pack_tag

Inside the Reactions.jsx I have this.

document.addEventListener('DOMContentLoaded', () => {
  const root = document.getElementById('article-reaction-actions');
  const child = document.getElementById('article-reaction-child');
  render(<Reactions />, root, child);
});

Which only renders my custom Reactions element when the page is refreshed but is not triggered when the user clicks an article (presumably because the DOM isn't reloaded when opening an article). I was wondering if you had some idea of what the best way would be to get the render to occur whenever an article is opened

@maestromac
Copy link
Member

Hey @gatlee , where did you place the javascript_pack_tag? Here my guess for why your Preact component isn't getting triggered:

We use a modified version of instantclick, which changes the way site navigation works. If you place the javascript_pack_tag file in application.html.erb, your Reaction.jsx will only run once and won't detect upcoming DOM changes because instantClick won't fire DOMContentLoaded state (I'm quite certain this is the case but I need to verify). You would have to place the javascript_pack_tag in the view that will definitely get loaded by instantClick.

No need to stress this, as there are probably better ways for this to be handled.

@gatlee
Copy link
Contributor Author

gatlee commented Oct 3, 2018

The javascript_pack_tag is in the _actions.html.erb file which loads each time so that wasn't the problem.

I found the proper event listener to use for InstantClick here which seems to work correctly. I should be good to go ahead now. Thanks for the help!

@pr-triage pr-triage bot added the PR: unreviewed bot applied label for PR's with no review label Nov 2, 2018
Copy link
Member

@maestromac maestromac left a comment

Choose a reason for hiding this comment

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

LGTM and thanks for this PR! Sorry it took us this long to review this. I went ahead and resolved the merge conflict.

@pr-triage pr-triage bot added PR: reviewed-approved bot applied label for PR's where reviewer approves changes and removed PR: unreviewed bot applied label for PR's with no review labels Nov 2, 2018
@maestromac maestromac merged commit b865ad9 into forem:master Nov 7, 2018
@gatlee
Copy link
Contributor Author

gatlee commented Nov 8, 2018

No worries. Glad I could contribute!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: reviewed-approved bot applied label for PR's where reviewer approves changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants