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 all commits
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.

6 changes: 5 additions & 1 deletion packages/i18n/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,11 @@
"play-next": "Play next",
"play-now": "Play now",
"playlist-toast-body": "{{artist}} - {{track}} has been added to playlist.",
"playlist-toast-title": "Track added to playlist"
"playlist-toast-title": "Track added to playlist",
"track-toast-clipboard-success-title": "Copied to clipboard!",
"track-toast-clipboard-success-subtitle": "Track name successfully copied to clipboard.",
"track-toast-clipboard-error-title": "Failed to copy!",
"track-toast-clipboard-error-subtitle": "Oof, something went wrong."
},
"track-table": {
"add-selected-tracks-to-queue": "Add selected to queue",
Expand Down
57 changes: 46 additions & 11 deletions packages/ui/lib/components/TrackInfo/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import React from 'react';
import { Icon } from 'semantic-ui-react';
import { Tooltip } from '@nuclear/ui';
import * as ActionToast from '../../../../app/app/actions/toasts'
import { useDispatch } from 'react-redux'
import { useTranslation } from 'react-i18next';

import Cover from '../Cover';
import styles from './styles.scss';
Expand All @@ -26,16 +30,46 @@ const TrackInfo: React.FC<TrackInfoProps> = ({
removeFromFavorites,
isFavorite = false,
hasTracks = false
}) => (
<div className={styles.track_info}>
<Cover cover={cover} />
{
hasTracks &&
}) => {
const dispatch = useDispatch();
const { t } = useTranslation('track-popup');

const CopyTextToClipboard = async () => {
try {
await navigator.clipboard.writeText(track);
dispatch(ActionToast.
success(t('track-toast-clipboard-success-title'),
t('track-toast-clipboard-success-subtitle'),
null,
{}
)
);
} catch (err) {
dispatch(ActionToast.
error(t('track-toast-clipboard-error-title'),
t('track-toast-clipboard-error-subtitle'),
null,
{}
)
);
}
};

return (
<div className={styles.track_info}>
<Cover cover={cover} />
{
hasTracks &&
<>
<div className={styles.artist_part}>
<div className={styles.track_name} onClick={onTrackClick}>
{track}
</div>
<Tooltip
content='Click to copy'
trigger={
<div data-testid='track_name' id='track_name' className={styles.track_name} onClick={() => CopyTextToClipboard()}>
{track}
</div>
}
/>
<div className={styles.artist_name} onClick={onArtistClick}>
{artist}
</div>
Expand All @@ -51,8 +85,9 @@ const TrackInfo: React.FC<TrackInfoProps> = ({
/>
</div>
</>
}
</div>
);
}
</div>
);
}

export default TrackInfo;
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 {
cursor: pointer;
}
}
Loading