+
+
+
{name}
+
+
Share this link with your friends to show them your brand new Emoji!
+
+
+ )
+}
+
+export default Share
\ No newline at end of file
diff --git a/src/index.css b/src/index.css
index 4cdb4e2..07c0862 100644
--- a/src/index.css
+++ b/src/index.css
@@ -232,10 +232,33 @@ body:before {
font-size: 1.2em;
}
+.share {
+ background: white;
+ padding: 0 2rem;
+ font-size: 1.2em;
+}
+
+.share__code {
+ background: #fff9e3;
+ color: #ed217c;
+ padding: 1em;
+ width: 100%;
+ font-weight: bold;
+ resize: none;
+ border: none;
+ font-size: 1em;
+}
+
+.share__preview {
+ width: 50%;
+ text-align: center;
+ margin: 1em auto;
+}
+
.library__code {
background: #fff9e3;
color: #ed217c;
- padding: 0.1em 1em;
+ padding: 0.1em em;
}
.library__preview {
diff --git a/src/utils/__tests__/encode.test.js b/src/utils/__tests__/encode.test.js
new file mode 100644
index 0000000..797cfef
--- /dev/null
+++ b/src/utils/__tests__/encode.test.js
@@ -0,0 +1,28 @@
+import { hashToEmoji, emojiToHash, generateShareUrl } from '../encode'
+
+
+describe('hashToEmoji', () => {
+ it('takes a base64 encoded string and returns textCommands and a name', () => {
+ const emoji = { name: 'testEmoji', textCommands: 'circle()' }
+ const code = 'eyJuYW1lIjoidGVzdEVtb2ppIiwidGV4dENvbW1hbmRzIjoiY2lyY2xlKCkifQ=='
+ expect(hashToEmoji(code)).toEqual(emoji)
+ })
+})
+
+describe('emojiToHash', () => {
+ it('takes an emoji and returns an encoded string', () => {
+ const emoji = { name: 'test', textCommands: 'circle()' }
+ const code = 'eyJuYW1lIjoidGVzdCIsInRleHRDb21tYW5kcyI6ImNpcmNsZSgpIn0='
+ expect(emojiToHash(emoji)).toEqual(code)
+ })
+})
+
+describe('generateShareUrl', () => {
+ it('creates a share URL for an emoji based off the current URL', () => {
+ const url = 'http://localhost:8080#emoji=eyJuYW1lIjoidGVzdCIsInRleHRDb21tYW5kcyI6ImNpcmNsZSgpIn0%3D'
+ expect(generateShareUrl({
+ name: 'test',
+ textCommands: 'circle()',
+ })).toBe(url)
+ })
+})
\ No newline at end of file
diff --git a/src/utils/encode.js b/src/utils/encode.js
new file mode 100644
index 0000000..fcac4b8
--- /dev/null
+++ b/src/utils/encode.js
@@ -0,0 +1,21 @@
+const hashToEmoji = (hash) => {
+ return JSON.parse(atob(hash))
+}
+
+const emojiToHash = ({ name, textCommands }) => {
+ return btoa(JSON.stringify({
+ name,
+ textCommands,
+ }))
+}
+
+const generateShareUrl = (emoji) => {
+ const hash = encodeURIComponent(emojiToHash(emoji))
+ return `${window.location.origin}#emoji=${hash}`
+}
+
+export {
+ emojiToHash,
+ hashToEmoji,
+ generateShareUrl,
+}