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

Fix:copy link not working on mobile #378

Merged
merged 7 commits into from
Mar 27, 2024

Conversation

ShoeheyOt
Copy link
Member

@ShoeheyOt ShoeheyOt commented Mar 27, 2024

Changes

  • put putGenerateInvitationLinkHash function outside of handleLinkCopy

Review points

  • I couldn't check with my iPhone, I would like you to check if it is working.

Screen Captures

generateInvitationLinkHash.webm

Assignee Checklist:

  • The naming convention of the PR title is correct (See the comment at the top of this template)
  • The base branch is correct (See: Types of Branches)
  • The branch name follows the Branch Naming Conventions
  • The correct assignees and reviewers have been designated for this PR
  • The coding style follows the Coding Style Guide
  • All the related issues are associated with this PR
  • All criteria in the associated issues are met (please tick the checkboxes)
  • My changes do not generate new warnings or errors (especially in the console)

Reviewer Checklist:

  • Double-check the "Assignee Checklist"
  • The code follows the generic best practices and our Coding Style Guide
  • The code is well-commented and easy to understand
  • The UI changes accurately reflect the provided design

@ShoeheyOt ShoeheyOt self-assigned this Mar 27, 2024
@ShoeheyOt ShoeheyOt linked an issue Mar 27, 2024 that may be closed by this pull request
@ShoeheyOt ShoeheyOt marked this pull request as ready for review March 27, 2024 06:00
Copy link
Member

@nick-y-ito nick-y-ito left a 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('');
Copy link
Member

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.

https://github.com/kettanaito/naming-cheatsheet#is


const hash = result.value.invitationLinkHash;
navigator.clipboard.writeText(`${CLIENT_BASE_URL}/groups/join/${hash}`);
setHash('');
Copy link
Member

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) {
Copy link
Member

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}`);
Copy link
Member

@nick-y-ito nick-y-ito Mar 27, 2024

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.

Copy link
Member

@nick-y-ito nick-y-ito left a 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 :)

@ShoeheyOt ShoeheyOt merged commit 41c6813 into develop Mar 27, 2024
5 checks passed
@ShoeheyOt ShoeheyOt deleted the fix/375-copy-link-not-working-on-mobile branch March 27, 2024 17:25
@nick-y-ito nick-y-ito mentioned this pull request Mar 27, 2024
nick-y-ito added a commit that referenced this pull request Mar 27, 2024
* 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>
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.

"Copy Link" not working on mobile
2 participants