adding copy url functionality to socialshare#417
Conversation
| // if platform is copy button | ||
| if (platform === 'copy') { |
There was a problem hiding this comment.
If there was an award for the most redundant comments, this one would definitely be a candidate to win 😆
There was a problem hiding this comment.
Yeah, thanks for pointing this out, I figured what I was doing something wrong here 😅
Is it because other devs have done the same thing in the past?
|
|
||
| // if platform is copy button | ||
| if (platform === 'copy') { | ||
| await triggerCopyShare(); |
There was a problem hiding this comment.
Jokes aside, this should not be placed here.
You're triggering the copy before even checking if the trigger that was clicked was the copy.
Also, that await here is not needed. Although copying is async, you are not performing any other actions afterwards to it's unnecessary to await for it.
| try { | ||
| await navigator.clipboard.writeText(windowUrl); | ||
| } catch (err) { | ||
| Debug.alert('MESSAGE_TO_SHOW', 'error'); |
There was a problem hiding this comment.
We're deprecating the Debug component in v2.
You can just use console.error.
Also, MESSAGE_TO_SHOW?
packages/socialshare/src/factory.ts
Outdated
| copy() { | ||
| // doesn't need to store any data and instances are irrelevant | ||
| return; |
There was a problem hiding this comment.
Perhaps it would make sense to create the specific callback for each platform inside the creators.
This way you will be able to treat the copy as any other platform.
There was a problem hiding this comment.
I have updated the logic a bit to address this thing. Might be a different approach from what you proposed as I thought it adapted more to how this is built. Let me know your thoughts!
| /** | ||
| * Defines a copy social button | ||
| */ | ||
| copy: generateDynamicAttibuteValue(COPY_ELEMENT_KEY), |
There was a problem hiding this comment.
copy doesn't require interacting with other elements so it's not necessary to be a dynamic attribute.
There was a problem hiding this comment.
How would we get the selectors for the copy button then? @alexiglesias93
|
@ayezinzu @alexiglesias93 this PR is supposed to use v1 or v2? 🤔 |
I believe v1 |
|
Hey team, I will come back with the updates for the feedback provided early this week! |
|
@IftodiRadu is attempting to deploy a commit to the Finsweet Team on Vercel. To accomplish this, @IftodiRadu needs to request access to the Team. Afterwards, an owner of the Team is required to accept their membership request. If you're already a member of the respective Vercel Team, make sure that your Personal Vercel Account is connected to your GitHub account. |
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
@ayezinzu is attempting to deploy a commit to the Finsweet Team on Vercel. To accomplish this, @ayezinzu needs to request access to the Team. Afterwards, an owner of the Team is required to accept their membership request. If you're already a member of the respective Vercel Team, make sure that your Personal Vercel Account is connected to your GitHub account. |
alexiglesias93
left a comment
There was a problem hiding this comment.
@ayezinzu CI is failing
@alexiglesias93 should be fixed now |
alexiglesias93
left a comment
There was a problem hiding this comment.
Also, please add a changeset
| const dataUrlAttribute = await copyLocator.getAttribute('data-url'); | ||
|
|
||
| await expect(dataUrlAttribute).toEqual(currentUrl); |
There was a problem hiding this comment.
this is quite redundant, you should be checking if the clipboard contains the correct text:
const clipboardText = await page.evaluate("navigator.clipboard.readText()");
expect(clipboardText).toEqual(currentUrl);There was a problem hiding this comment.
@alexiglesias93 Firefox only supports reading the clipboard in browser extensions, using the "clipboardRead" extension permission. Thus, we can't access that property on Firefox. That is why we use clipboard.js which seems to be working fine.
There was a problem hiding this comment.
Then you could test by using execCommand to trigger a Paste action into a textarea, and check the contents that were pasted
| }); | ||
|
|
||
| // setting data-url attribute for testing purposes | ||
| copyButton.setAttribute('data-url', copyUrl); |
There was a problem hiding this comment.
this is not necessary, check my other comment for reference
Hi @alexiglesias93 |

No description provided.