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

FEAT: Add "copy to clipboard" feature #1521

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion packages/ui/lib/components/TrackInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
import Cover from '../Cover';
import styles from './styles.scss';

const CopyTextToClipboard = async () => {
const track_element = document.getElementById('track_name');
try {
await navigator.clipboard.writeText(track_element.innerHTML);

Check warning on line 10 in packages/ui/lib/components/TrackInfo/index.tsx

View check run for this annotation

Codecov / codecov/patch

packages/ui/lib/components/TrackInfo/index.tsx#L8-L10

Added lines #L8 - L10 were not covered by tests
Copy link
Owner

Choose a reason for hiding this comment

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

This shouldn't be done this way in React. Instead, you can get the title from the redux store.

} catch (err) {
console.error('Failed to copy: ', err);

Check warning on line 12 in packages/ui/lib/components/TrackInfo/index.tsx

View check run for this annotation

Codecov / codecov/patch

packages/ui/lib/components/TrackInfo/index.tsx#L12

Added line #L12 was not covered by tests
Copy link
Owner

Choose a reason for hiding this comment

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

Don't use console.error, instead you can show a notification toast.

}
};

export type TrackInfoProps = {
cover?: string;
track: string;
Expand Down Expand Up @@ -33,7 +42,7 @@
hasTracks &&
<>
<div className={styles.artist_part}>
<div className={styles.track_name} onClick={onTrackClick}>
<div id='track_name' className={styles.track_name} onClick={() => CopyTextToClipboard()}>

Check warning on line 45 in packages/ui/lib/components/TrackInfo/index.tsx

View check run for this annotation

Codecov / codecov/patch

packages/ui/lib/components/TrackInfo/index.tsx#L45

Added line #L45 was not covered by tests
{track}
</div>
<div className={styles.artist_name} onClick={onArtistClick}>
Expand Down
4 changes: 4 additions & 0 deletions packages/ui/lib/components/TrackInfo/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@
cursor: pointer;
}
}

#track_name:hover {
color: green;
}
}
Loading