|
1 | 1 | import React from 'react'
|
2 | 2 |
|
3 |
| -import { Icon } from '@iconify/react' |
4 |
| -import styled from 'styled-components' |
| 3 | +import styled, { useTheme } from 'styled-components' |
5 | 4 |
|
6 |
| -import { Button } from '@workduck-io/mex-components' |
| 5 | +import { Button, MexIcon } from '@workduck-io/mex-components' |
| 6 | + |
| 7 | +import { mog } from '@mexit/core' |
| 8 | +import { copyTextToClipboard } from '@mexit/shared' |
7 | 9 |
|
8 | 10 | import { useSputlitStore } from '../../Stores/useSputlitStore'
|
9 | 11 | import { generateAvatar } from '../../Utils/generateAvatar'
|
| 12 | +import { Controls } from './Screenshot/Screenshot.style' |
10 | 13 |
|
11 | 14 | const Container = styled.div`
|
12 | 15 | display: flex;
|
13 |
| - flex-direction: row; |
| 16 | + flex-direction: column; |
14 | 17 | align-items: center;
|
| 18 | + gap: ${({ theme }) => theme.spacing.large}; |
| 19 | + margin: ${({ theme }) => theme.spacing.medium} 0; |
15 | 20 | justify-content: center;
|
16 | 21 | `
|
17 | 22 |
|
| 23 | +const AvatarImage = styled.img` |
| 24 | + border-radius: ${({ theme }) => theme.borderRadius.large}; |
| 25 | + box-shadow: inset 1rem 1.25rem 1.25rem 1.25rem ${({ theme }) => theme.colors.form.button.bg}; |
| 26 | +` |
| 27 | + |
18 | 28 | const AvatarRenderer = () => {
|
| 29 | + const theme = useTheme() |
19 | 30 | const { screenshot, setScreenshot } = useSputlitStore()
|
20 | 31 |
|
21 | 32 | const randomizeAvatar = () => {
|
22 | 33 | const imgData = generateAvatar()
|
23 | 34 |
|
24 | 35 | setScreenshot(imgData)
|
25 | 36 | }
|
| 37 | + const downloadAvatar = () => { |
| 38 | + chrome.runtime.sendMessage( |
| 39 | + { |
| 40 | + type: 'DOWNLOAD_AVATAR', |
| 41 | + data: { |
| 42 | + url: screenshot |
| 43 | + } |
| 44 | + }, |
| 45 | + (response) => { |
| 46 | + const { message, error } = response |
| 47 | + if (error) { |
| 48 | + mog('Avatar Download error', { error }) |
| 49 | + } else { |
| 50 | + mog('Avatar Downloaded') |
| 51 | + } |
| 52 | + } |
| 53 | + ) |
| 54 | + } |
| 55 | + |
| 56 | + const copyAvatarURL = () => { |
| 57 | + copyTextToClipboard(screenshot) |
| 58 | + } |
26 | 59 |
|
27 | 60 | return (
|
28 | 61 | <Container>
|
29 |
| - <img src={screenshot} /> |
30 |
| - <Button onClick={randomizeAvatar}> |
31 |
| - <Icon icon="pepicons:reload" /> |
32 |
| - Randomize Avatar |
33 |
| - </Button> |
| 62 | + <AvatarImage src={screenshot} /> |
| 63 | + <Controls> |
| 64 | + <Button onClick={randomizeAvatar}> |
| 65 | + <MexIcon noHover icon="pepicons:reload" color={theme.colors.primary} /> |
| 66 | + Randomize |
| 67 | + </Button> |
| 68 | + {/* <Button onClick={copyAvatarURL}> |
| 69 | + <Icon icon="pepicons:clipboard" /> |
| 70 | + Copy Avatar URL |
| 71 | + </Button> */} |
| 72 | + <Button onClick={downloadAvatar}> |
| 73 | + <MexIcon noHover icon="pepicons:arrow-down" color={theme.colors.primary} /> |
| 74 | + Download |
| 75 | + </Button> |
| 76 | + </Controls> |
34 | 77 | </Container>
|
35 | 78 | )
|
36 | 79 | }
|
|
0 commit comments