Skip to content

Commit

Permalink
Merge pull request #62 from VKCOM/o.shcherbakov/clipboard-control/QA-…
Browse files Browse the repository at this point in the history
…15743

feat(ui): clipboard control
  • Loading branch information
DaniilSmirnov authored Dec 27, 2024
2 parents e0460db + 337cb6c commit 2388e3c
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { useState } from 'react'
import { observer } from 'mobx-react-lite'
import { useTranslation } from 'react-i18next'
import { Icon20RefreshOutline } from '@vkontakte/icons'
import { IconButton, Input, Tooltip } from '@vkontakte/vkui'

import { DeviceControlStore } from '@/store/device-control-store'
import { useServiceLocator } from '@/lib/hooks/use-service-locator.hook'

export const ClipboardControl = observer(() => {
const { t } = useTranslation()
const [clipboardContent, setClipboardContent] = useState('')
const deviceControlStore = useServiceLocator<DeviceControlStore>(DeviceControlStore.name)

const onGetClipboardContent = async () => {
const data = await deviceControlStore?.getClipboardContent()

if (data) {
setClipboardContent(data)
}
}

return (
<Input
placeholder={t('Get clipboard contents')}
type='text'
value={t(clipboardContent)}
after={
<Tooltip appearance='accent' description={t('Get clipboard contents')}>
<IconButton hoverMode='opacity' onClick={() => onGetClipboardContent()}>
<Icon20RefreshOutline />
</IconButton>
</Tooltip>
}
/>
)
})
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { ClipboardControl } from './clipboard-control'
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { BookingService } from '@/services/booking-service'

import { useServiceLocator } from '@/lib/hooks/use-service-locator.hook'

import { ClipboardControl } from './clipboard-control'
import { DeviceButtonsControl } from './device-buttons-control'
import { DeviceBookingControl } from './device-booking-control'

Expand Down Expand Up @@ -65,7 +66,7 @@ export const DashboardTab = observer(() => {
Stub
</DeviceControlCard>
<DeviceControlCard before={<Icon20CopyOutline />} title={t('Clipboard')}>
Stub
<ClipboardControl />
</DeviceControlCard>
<DeviceControlCard
afterTooltipText={t('Extend booking')}
Expand Down
16 changes: 16 additions & 0 deletions ui/src/store/device-control-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@ export class DeviceControlStore extends DeviceControlService {
})
}

async getClipboardContent(): Promise<string> {
try {
const data = await this.copy()

if (typeof data === 'string') {
return data
}

return 'No clipboard data'
} catch (error) {
console.error(error)

return 'Error while getting data'
}
}

setCurrentQuality(quality: number): void {
this.currentQuality = quality
}
Expand Down

0 comments on commit 2388e3c

Please sign in to comment.