Skip to content

Commit

Permalink
feat(home): add copy link action
Browse files Browse the repository at this point in the history
  • Loading branch information
AXeL-dev committed Sep 11, 2022
1 parent b8d934e commit 4b122d1
Show file tree
Hide file tree
Showing 5 changed files with 10,900 additions and 8,442 deletions.
27 changes: 27 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@types/node": "^17.0.9",
"@types/react": "^17.0.38",
"@types/react-dom": "^17.0.11",
"copy-to-clipboard": "^3.3.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-redux": "^7.2.6",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React, { useState } from 'react';
import { Grow, IconButton, Tooltip } from '@mui/material';
import { Video } from 'types';
import LinkIcon from '@mui/icons-material/Link';
import CheckIcon from '@mui/icons-material/Check';
import copy from 'copy-to-clipboard';

interface CopyLinkActionProps {
video: Video;
}

function CopyLinkAction(props: CopyLinkActionProps) {
const { video } = props;
const [isShown, setIsShown] = useState(true);
const [copied, setCopied] = useState(false);

const handleClick = () => {
if (copied) return;
copy(video.url);
setCopied(true);
setTimeout(() => {
setIsShown(false);
}, 1000);
};

return (
<Grow in={isShown}>
<Tooltip
title={copied ? 'Copied!' : 'Copy link to clipboard'}
aria-label="copy-link"
>
<IconButton
sx={{
color: '#eee',
backgroundColor: 'rgba(0, 0, 0, 0.8)',
padding: '4px',
borderRadius: '2px',
'&:hover': {
color: '#fff',
},
}}
size="small"
onClick={handleClick}
>
{copied ? (
<CheckIcon sx={{ fontSize: '1.125rem' }} color="success" />
) : (
<LinkIcon sx={{ fontSize: '1.125rem' }} />
)}
</IconButton>
</Tooltip>
</Grow>
);
}

export default CopyLinkAction;
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import WatchLaterAction from './WatchLaterAction';
import SeenAction from './SeenAction';
import ArchiveAction from './ArchiveAction';
import IgnoreAction from './IgnoreAction';
import CopyLinkAction from './CopyLinkAction';

interface VideoTopActionsProps {
video: Video;
Expand All @@ -25,6 +26,7 @@ function VideoTopActions(props: VideoTopActionsProps) {
gap: '4px',
}}
>
<CopyLinkAction video={video} />
<IgnoreAction video={video} view={view} />
<SeenAction video={video} />
<ArchiveAction video={video} view={view} />
Expand Down
Loading

0 comments on commit 4b122d1

Please sign in to comment.