-
Notifications
You must be signed in to change notification settings - Fork 4
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
Fix:copy link not working on mobile #378
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ShoeheyOt
Thank you for your work! It worked in my environment!
Could you only adjust the points I commented on before moving on to merging?
@@ -30,23 +30,42 @@ export const InviteMemberDialogContent = ({ | |||
groupId, | |||
}: IInviteMemberDialogContentProps) => { | |||
const [isLinkButtonClicked, setIsLinkButtonClicked] = useState(false); | |||
const [isHash, setHash] = useState(''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't use is
for a string state.
|
||
const hash = result.value.invitationLinkHash; | ||
navigator.clipboard.writeText(`${CLIENT_BASE_URL}/groups/join/${hash}`); | ||
setHash(''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably not set the hash to an empty string. This functionality works without resetting it because it's renewed every time the dialog opens. Since a state change always triggers a component's re-rendering, we should avoid unnecessary state updates.
*/ | ||
useEffect(() => { | ||
const getHash = async () => { | ||
if (isDialogOpen) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!isDialogOpen) return;
If you write the first if statement like this, you can avoid nested multiple if statements.
alert('Something went wrong. Please try again'); | ||
return; | ||
try { | ||
return await navigator.clipboard.writeText(`${CLIENT_BASE_URL}/groups/join/${isHash}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try {
if (!hash) throw new Error('Invitation link hash is not set.');
return await navigator.clipboard.writeText(`${CLIENT_BASE_URL}/groups/join/${isHash}`);
}
It would be better to throw an error if the hash is not set, so the execution will go to the catch
block instead of becoming successful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ShoeheyOt Thank you for the update! LGTM :)
* Feature: Replace OG image (#380) * Fix:copy link not working on mobile (#378) * fix: add await * chore: move the return keyword * fix: put fetch function when the dialog open * chore: reset the hash state when copy button clicked * docs: modify the documentation * chore: typo * fix: update based on given feedback --------- Co-authored-by: Nick Ito <nick.yusuke.ito@gmail.com> --------- Co-authored-by: ShoeheyOt <142355969+ShoeheyOt@users.noreply.github.com>
Changes
putGenerateInvitationLinkHash
function outside ofhandleLinkCopy
Review points
Screen Captures
generateInvitationLinkHash.webm
Assignee Checklist:
Reviewer Checklist: