mirror of
https://github.com/status-im/nimbus-gui.git
synced 2025-02-27 10:30:31 +00:00
feat: add copy functionality
This commit is contained in:
parent
c63d27528c
commit
92c02068d0
@ -1,6 +1,6 @@
|
|||||||
import { Stack, YStack } from 'tamagui'
|
import { Stack, YStack } from 'tamagui'
|
||||||
import { Text } from '@status-im/components'
|
import { Text } from '@status-im/components'
|
||||||
import { useSelector } from 'react-redux'
|
import { useDispatch, useSelector } from 'react-redux'
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
|
|
||||||
import { RootState } from '../../../../redux/store'
|
import { RootState } from '../../../../redux/store'
|
||||||
@ -8,13 +8,48 @@ import { DOCUMENTATIONS } from './documentations'
|
|||||||
import { MAC } from '../../../../constants'
|
import { MAC } from '../../../../constants'
|
||||||
import OSCards from './OSCards'
|
import OSCards from './OSCards'
|
||||||
import Markdown from '../../../../components/General/Markdown/Markdown'
|
import Markdown from '../../../../components/General/Markdown/Markdown'
|
||||||
|
import { setPinnedMessage } from '../../../../redux/PinnedMessage/slice'
|
||||||
|
|
||||||
|
function extractBashCommands(documentation: any) {
|
||||||
|
const bashCommandRegex = /```bash\n([\s\S]*?)\n```/g
|
||||||
|
const matches = []
|
||||||
|
let match
|
||||||
|
|
||||||
|
while ((match = bashCommandRegex.exec(documentation)) !== null) {
|
||||||
|
matches.push(match[1])
|
||||||
|
}
|
||||||
|
return matches.join('\n\n')
|
||||||
|
}
|
||||||
|
|
||||||
const ValidatorSetupInstall = () => {
|
const ValidatorSetupInstall = () => {
|
||||||
|
const dispatch = useDispatch()
|
||||||
const [selectedOS, setSelectedOS] = useState(MAC)
|
const [selectedOS, setSelectedOS] = useState(MAC)
|
||||||
const selectedClient = useSelector((state: RootState) => state.execClient.selectedClient)
|
const selectedClient = useSelector((state: RootState) => state.execClient.selectedClient)
|
||||||
|
const docText = DOCUMENTATIONS[selectedClient].documentation[selectedOS]
|
||||||
|
const bashCommands = extractBashCommands(docText)
|
||||||
|
|
||||||
const handleOSCardClick = (os: string) => {
|
const handleOSCardClick = (os: string) => {
|
||||||
setSelectedOS(os)
|
setSelectedOS(os)
|
||||||
|
}
|
||||||
|
|
||||||
|
const copyCommands = () => {
|
||||||
|
navigator.clipboard.writeText(bashCommands)
|
||||||
|
dispatch(
|
||||||
|
setPinnedMessage({
|
||||||
|
id: '123',
|
||||||
|
text: 'You have successfully copied the commands to your clipboard.',
|
||||||
|
pinned: true,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
setTimeout(() => {
|
||||||
|
dispatch(
|
||||||
|
setPinnedMessage({
|
||||||
|
id: '123',
|
||||||
|
text: 'You have successfully copied the commands to your clipboard.',
|
||||||
|
pinned: false,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}, 3000)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -39,7 +74,9 @@ const ValidatorSetupInstall = () => {
|
|||||||
<Markdown children={DOCUMENTATIONS[selectedClient].general} />
|
<Markdown children={DOCUMENTATIONS[selectedClient].general} />
|
||||||
<OSCards selectedOS={selectedOS} handleOSCardClick={handleOSCardClick} />
|
<OSCards selectedOS={selectedOS} handleOSCardClick={handleOSCardClick} />
|
||||||
|
|
||||||
<Markdown children={DOCUMENTATIONS[selectedClient].documentation[selectedOS]} />
|
<Stack onPress={() => copyCommands()}>
|
||||||
|
<Markdown children={DOCUMENTATIONS[selectedClient].documentation[selectedOS]} />
|
||||||
|
</Stack>
|
||||||
</Stack>
|
</Stack>
|
||||||
</YStack>
|
</YStack>
|
||||||
</YStack>
|
</YStack>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user