Skip to content

Commit

Permalink
feat: add feedback for copy (#570)
Browse files Browse the repository at this point in the history
Co-authored-by: Расул <[email protected]>
  • Loading branch information
Rassl and Расул authored Nov 6, 2023
1 parent cc8bdc7 commit 7838c7b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/components/App/SideBar/AudioClip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ const _AudioClip = () => {
</TextWrapper>
<StyledDivider />
<TextWrapper>
<Transcript node={selectedNode} stateless />
<Transcript key={id} node={selectedNode} stateless />
</TextWrapper>
</div>
</Wrapper>
Expand Down
69 changes: 48 additions & 21 deletions src/components/App/SideBar/Transcript/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Button } from '@mui/material'
import React, { useState } from 'react'
import { MdClose } from 'react-icons/md'
import styled from 'styled-components'
import CopyIcon from '~/components/Icons/CopyIcon'
Expand All @@ -7,24 +8,7 @@ import { Flex } from '~/components/common/Flex'
import { useAppStore } from '~/stores/useAppStore'
import { NodeExtended } from '~/types'
import { colors } from '~/utils/colors'

const copyNodeText = (text: string | undefined) => {
if (text === undefined) {
return
}

navigator.clipboard.writeText(text)

const copyButton = document.querySelector('.copy-button')

if (copyButton) {
copyButton.classList.add('copied')

setTimeout(() => {
copyButton.classList.remove('copied')
}, 1000)
}
}
import CheckIcon from '../../../Icons/CheckIcon'

type TranscriptProps = {
stateless?: boolean
Expand All @@ -34,10 +18,21 @@ type TranscriptProps = {
export const Transcript = ({ stateless, node }: TranscriptProps) => {
const [transcriptIsOpen, setTranscriptOpen] = useAppStore((s) => [s.transcriptIsOpen, s.setTranscriptOpen])

const [isCopied, setIsCopied] = useState(false)

if (!stateless && !transcriptIsOpen) {
return null
}

const copyNodeText = (text: string | undefined) => {
if (text === undefined) {
return
}

navigator.clipboard.writeText(text)
setIsCopied(true)
}

return (
<Flex grow={1} shrink={1}>
<Header>
Expand All @@ -51,9 +46,25 @@ export const Transcript = ({ stateless, node }: TranscriptProps) => {
)}

{node?.text ? (
<Button endIcon={<CopyIcon />} onPointerDown={() => copyNodeText(node?.text)} size="small" variant="outlined">
Copy
</Button>
<>
{!isCopied ? (
<Button
endIcon={<CopyIcon />}
onPointerDown={() => copyNodeText(node?.text)}
size="small"
variant="outlined"
>
Copy
</Button>
) : (
<CopiedButton align="center" direction="row" justify="flex-start">
<div className="icon">
<CheckIcon />
</div>
<div className="text">Copied</div>
</CopiedButton>
)}
</>
) : (
<div />
)}
Expand Down Expand Up @@ -121,3 +132,19 @@ const Box = styled(Flex)`
font-weight: 400;
line-height: 18px;
`

const CopiedButton = styled(Flex)`
color: ${colors.SECONDARY_BLUE};
font-family: Barlow;
font-size: 13px;
font-weight: 500;
height: 28px;
padding: 0 20px;
.text {
margin-left: 5px;
}
.icon {
font-size: 12px;
}
`
2 changes: 1 addition & 1 deletion src/components/App/SideBar/YouTube/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const YouTube = () => {
</TextWrapper>
<StyledDivider />
<TextWrapper>
<Transcript node={selectedNode} stateless />
<Transcript key={id} node={selectedNode} stateless />
</TextWrapper>
</div>
</Wrapper>
Expand Down

0 comments on commit 7838c7b

Please sign in to comment.