Skip to content

Commit 7767796

Browse files
Add button to download avatar (#255)
#255 * import path fix for importing Screenshot.style * add download avatar button for avatar generator action * add patch changeset * add copy url option for avatars url * Avatar section UI fixes Co-authored-by: Dinesh Singh <[email protected]>
1 parent 06c0cb6 commit 7767796

File tree

6 files changed

+67
-12
lines changed

6 files changed

+67
-12
lines changed

.changeset/selfish-ravens-dance.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'mexit': patch
3+
---
4+
5+
Added download button for avatar generator action

apps/extension/src/Components/Form/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { formToBlocks } from '../../Utils/getProfileData'
1717
import { Title } from '../Action/styled'
1818
import { Dialog } from '../Floating/Dialog'
1919
import NoteSelector from '../Floating/NoteSelector'
20-
import { Controls } from '../Screenshot/Screenshot.style'
20+
import { Controls } from '../Renderers/Screenshot/Screenshot.style'
2121
import Field from './Field'
2222
import { ExcludeFormFieldsContainer, StyledForm, StyledRowItem, UserPreferedFieldsContainer } from './styled'
2323

apps/extension/src/Components/Form/styled.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import styled from 'styled-components'
22

33
import { TextAreaBlock } from '@mexit/shared'
44

5-
import { Controls } from '../Screenshot/Screenshot.style'
5+
import { Controls } from '../Renderers/Screenshot/Screenshot.style'
66

77
export const StyledForm = styled.form`
88
display: flex;

apps/extension/src/Components/Renderers/AvatarRenderer.tsx

+52-9
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,79 @@
11
import React from 'react'
22

3-
import { Icon } from '@iconify/react'
4-
import styled from 'styled-components'
3+
import styled, { useTheme } from 'styled-components'
54

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'
79

810
import { useSputlitStore } from '../../Stores/useSputlitStore'
911
import { generateAvatar } from '../../Utils/generateAvatar'
12+
import { Controls } from './Screenshot/Screenshot.style'
1013

1114
const Container = styled.div`
1215
display: flex;
13-
flex-direction: row;
16+
flex-direction: column;
1417
align-items: center;
18+
gap: ${({ theme }) => theme.spacing.large};
19+
margin: ${({ theme }) => theme.spacing.medium} 0;
1520
justify-content: center;
1621
`
1722

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+
1828
const AvatarRenderer = () => {
29+
const theme = useTheme()
1930
const { screenshot, setScreenshot } = useSputlitStore()
2031

2132
const randomizeAvatar = () => {
2233
const imgData = generateAvatar()
2334

2435
setScreenshot(imgData)
2536
}
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+
}
2659

2760
return (
2861
<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>
3477
</Container>
3578
)
3679
}

apps/extension/src/background.ts

+7
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
101101
})()
102102
return true
103103
}
104+
case 'DOWNLOAD_AVATAR': {
105+
chrome.downloads.download({
106+
url: request.data.url,
107+
filename: 'avatar.svg'
108+
})
109+
return true
110+
}
104111

105112
case 'PUBLIC_SHARING': {
106113
;(async () => {

apps/extension/src/manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
"background": { "service_worker": "background.js", "type": "module" },
1515
"omnibox": { "keyword": "[[" },
1616
"content_scripts": [{ "matches": ["http://*/*", "https://*/*"], "js": ["content.js"], "css": ["Assets/global.css"] }],
17-
"permissions": ["contextMenus", "storage", "tabs", "activeTab", "search", "notifications"],
17+
"permissions": ["contextMenus", "storage", "tabs", "activeTab", "search", "notifications" , "downloads"],
1818
"web_accessible_resources": [{ "resources": ["Assets/*"], "matches": ["http://*/*", "https://*/*"] }]
1919
}

0 commit comments

Comments
 (0)