Skip to content

Commit

Permalink
finished copy button for DNA and protein sequences (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
apiraam96 authored Jan 18, 2024
1 parent 68de174 commit 8273540
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions Eplant/views/GeneInfoView/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import {
import { View, ViewProps } from '../../View'
import { useViewData } from '../../View/viewData'
import { GeneModel } from './GeneModel'
import { Box, Button, ButtonProps, LinearProgress } from '@mui/material'
import { Alert, Box, Button, ButtonProps, LinearProgress, Snackbar } from '@mui/material'
import ContentCopyIcon from '@mui/icons-material/ContentCopy';
import { IconButton } from '@mui/material'

const SecondaryText = styled(Typography)(({ theme }) => ({
color: theme.palette.text.secondary,
Expand Down Expand Up @@ -122,7 +124,11 @@ const GeneSequence = ({
str += char
prevStyle = currentStyle
}
return <CodeBody variant="caption">{spans}</CodeBody>
return (
<>
<CodeBody variant="caption">{spans}</CodeBody>
</>
)
}

const ViewButton = styled(function ViewButton({
Expand Down Expand Up @@ -178,6 +184,13 @@ export default function GeneInfoViewer({
throw new TypeError('Genetic element must be provided for Gene Info View')
}

const [snackBarOpen, setSnackBarOpen] = React.useState(false)
const copyToClipboard = (text: string) => {
setSnackBarOpen(true)
navigator.clipboard.writeText(text)
}


return (
<Stack direction="row" gap={'20px'}>
<ViewSwitcher geneticElement={geneticElement} />
Expand Down Expand Up @@ -235,6 +248,22 @@ export default function GeneInfoViewer({
geneticElement={geneticElement}
activeData={activeData}
></GeneSequence>
<IconButton onClick={() => copyToClipboard(activeData.geneSequence)} color='primary' sx={{ ml: 1 }}>
<ContentCopyIcon />
</IconButton>
<Snackbar
anchorOrigin={
{
vertical: 'top',
horizontal: 'center'
}
}
open={snackBarOpen}
onClose={() => setSnackBarOpen(false)}
autoHideDuration={2000}
>
<Alert severity='success'>Copied to clipboard!</Alert>
</Snackbar>
</div>
</div>
</div>
Expand All @@ -250,11 +279,14 @@ export default function GeneInfoViewer({
<CodeBody variant="caption" style={{ wordBreak: 'break-word' }}>
{activeData.proteinSequence}
</CodeBody>
<IconButton onClick={() => copyToClipboard(activeData.proteinSequence)} color='primary' sx={{ ml: 1 }}>

Check failure on line 282 in Eplant/views/GeneInfoView/component.tsx

View workflow job for this annotation

GitHub Actions / build

Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
<ContentCopyIcon />
</IconButton>
</div>
</div>
) : undefined}
</Stack>
</Stack>
</Stack >
)
}
function ViewSwitcher({ geneticElement }: { geneticElement: GeneticElement }) {
Expand Down

0 comments on commit 8273540

Please sign in to comment.