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] Copy to Clipboard for Answers #1461

Merged

Conversation

chahmedejaz
Copy link
Contributor

@chahmedejaz chahmedejaz commented Nov 11, 2023

Resolves: #1448

  • This PR adds the feature to copy question in the following format to the clipboard:
    • question - answer [link]
  • It also adds the respective specs as well.

Screenshot:
image

image

Copy link

codecov bot commented Nov 11, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (fa0aa59) 95.41% compared to head (93933c2) 95.41%.
Report is 34 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1461   +/-   ##
=======================================
  Coverage   95.41%   95.41%           
=======================================
  Files         174      174           
  Lines        2702     2702           
=======================================
  Hits         2578     2578           
  Misses        124      124           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@chahmedejaz chahmedejaz changed the title Copy to Clipboard [Feature] Copy to Clipboard for Questions Nov 11, 2023
@chahmedejaz chahmedejaz changed the title [Feature] Copy to Clipboard for Questions [Feature] Copy to Clipboard for Answers Nov 11, 2023
Copy link
Member

@pixeldesu pixeldesu left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! This is already a good base, I left some suggestions that you should please take a look at!

Comment on lines 16 to 20

def answer_copy_content(answer)
# copy content template: "question - answer [link]"
"#{answer.question.content} - #{answer.content} [#{answer_share_url(answer)}]"
end
Copy link
Member

Choose a reason for hiding this comment

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

You can just use the SocialHelper::TwitterMethods#prepare_tweet method, which returns exactly the same format.

The [] around the link in the issue were also just for demonstration, they are not required in the actual output ;)

Copy link
Member

Choose a reason for hiding this comment

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

I would suggest making a controller specifically for the clipboard feature, so we can reuse it in other places that don't necessarily have to do with sharing.

Copy link
Member

@pixeldesu pixeldesu left a comment

Choose a reason for hiding this comment

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

I actually meant to request changes instead, sorry! (comments from above still apply)

Comment on lines 17 to 20
def answer_copy_content(answer)
# copy content template: "question - answer [link]"
"#{answer.question.content} - #{answer.content} [#{answer_share_url(answer)}]"
end
Copy link
Contributor

Choose a reason for hiding this comment

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

RDoc comments go above the method instead of inside it.

Suggested change
def answer_copy_content(answer)
# copy content template: "question - answer [link]"
"#{answer.question.content} - #{answer.content} [#{answer_share_url(answer)}]"
end
# copy content template: "question - answer link"
def answer_copy_content(answer)
"#{answer.question.content} - #{answer.content} #{answer_share_url(answer)}"
end

This can also be shortened using end-less method definition like so:

Suggested change
def answer_copy_content(answer)
# copy content template: "question - answer [link]"
"#{answer.question.content} - #{answer.content} [#{answer_share_url(answer)}]"
end
# copy content template: "question - answer link"
def answer_copy_content(answer) = "#{answer.question.content} - #{answer.content} #{answer_share_url(answer)}"

Copy link
Contributor Author

@chahmedejaz chahmedejaz Nov 12, 2023

Choose a reason for hiding this comment

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

  • Thanks for your suggestion. I'd keep this in mind for my future PRs.
  • However, as per this comment, I'll be removing this method. Thanks. :)

@chahmedejaz
Copy link
Contributor Author

Hey @pixeldesu, @raccube - Thanks for your suggestions. I've addressed them. It's ready for review. Thanks :)

@chahmedejaz
Copy link
Contributor Author

Thanks for your suggestions. I've addressed them. It's ready for review. Thanks :)

Hey @pixeldesu - A soft reminder for this. Please let me know if I'm missing anything here. Thanks.

@pixeldesu
Copy link
Member

@chahmedejaz I already had a look at the code, but I want to test it locally before the next review. I am quite busy right now so I'll try to review it by the weekend!

@chahmedejaz
Copy link
Contributor Author

I already had a look at the code, but I want to test it locally before the next review. I am quite busy right now so I'll try to review it by the weekend!

Oh no problem then. 😄

Copy link
Member

@pixeldesu pixeldesu left a comment

Choose a reason for hiding this comment

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

So I reviewed this, and the code looks and works fine! Good job 🎉

After testing, I have two more things that should be addressed:

  • The copy action doesn't really have feedback, it feels like I don't really know pressing the button copied the content to my clipboard, we should probably show a notification toast (using showNotification) here!*
  • The initial feature request was meant to be for the sharing dialog that comes up after answering a question in the inbox. So we should add the button there as well, so people can copy the answer to their clipboard right after answering.

*Some notes for adding translations in the JS:

  • All strings that should be accessible need to be present in the frontend.*.yml file.
  • For it to appear in the frontend, you then need to run rails i18n export before yarn run build, so the new translations are actually packaged.

Sorry again for taking so long with the review, we really appreciate your recent contributions! :)

@chahmedejaz
Copy link
Contributor Author

chahmedejaz commented Nov 19, 2023

Thank you so much for the feedback and the guide, @pixeldesu 😄
No worries, I'll incorporate these as well here.

What's the notification message would you prefer here? I was thinking of:
Content copied to clipboard
and on failure (just to cover all scenarios):
Failed to copy content to clipboard

@raccube
Copy link
Contributor

raccube commented Nov 19, 2023

That reads fine in my opinion.

@chahmedejaz
Copy link
Contributor Author

Hey @pixeldesu - I've addressed your suggestions. Please review and let me know if I'm missing anything. Thanks.

Copy link
Member

@pixeldesu pixeldesu left a comment

Choose a reason for hiding this comment

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

👍 Awesome, everything's in order now! Good work!

@pixeldesu pixeldesu merged commit 8d0288c into Retrospring:main Nov 26, 2023
11 checks passed
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.

Add "Copy to clipboard" sharing option to answers
3 participants