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
Next Next commit
Add copy to clipboard feature
  • Loading branch information
shantanusoni72 committed Nov 1, 2023
commit b9bfe146eab84a2d93d1cc0d31eaa9ef12caa5b1
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 { Icon } from 'semantic-ui-react';
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);
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);
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 @@ const TrackInfo: React.FC<TrackInfoProps> = ({
hasTracks &&
<>
<div className={styles.artist_part}>
<div className={styles.track_name} onClick={onTrackClick}>
<div id='track_name' className={styles.track_name} onClick={() => CopyTextToClipboard()}>
{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;
}
}