diff --git a/package.json b/package.json index 5b1b405..a4196b8 100644 --- a/package.json +++ b/package.json @@ -60,5 +60,8 @@ "save-svg-as-png": "^1.4.6", "uniquefilename": "^1.1.2", "whatwg-fetch": "^3.0.0" + }, + "jest": { + "testURL": "http://localhost:8080" } -} +} \ No newline at end of file diff --git a/src/components/App.jsx b/src/components/App.jsx index 50ee360..95b3f8d 100644 --- a/src/components/App.jsx +++ b/src/components/App.jsx @@ -4,6 +4,7 @@ import Canvas from './Canvas' import Editor from './Editor' import Library from './Library' import Modal from './Modal' +import Share from './Share' import evaluate from '../utils/evaluate' import mapFuncs from '../utils/mapFuncs' @@ -11,6 +12,7 @@ import getSvgBlob from '../utils/getSvgBlob' import postEmojiToServer from '../utils/postEmojiToServer' import saveSvg from '../utils/saveSvg' import { loadCode, saveCode } from '../utils/localStorage' +import { generateShareUrl, decodeEmojiFromUrl } from '../utils/encode' import functionLibrary from '../library' @@ -30,6 +32,7 @@ class App extends Component { commands: [], errors: [], showLibrary: false, + showShare: false, textCommands: loadCode() || EXAMPLE_CODE, } @@ -39,6 +42,7 @@ class App extends Component { this.onEmojiSubmit = this.onEmojiSubmit.bind(this) this.updateCommands = this.updateCommands.bind(this) this.showLibrary = this.showLibrary.bind(this) + this.shareEmoji = this.shareEmoji.bind(this) this.insertEditorCommand = this.insertEditorCommand.bind(this) } @@ -62,6 +66,8 @@ class App extends Component { }) } + + onChangeName(e) { const { value } = e.target @@ -79,6 +85,10 @@ class App extends Component { this.setState(({ showLibrary }) => ({ showLibrary: !showLibrary })) } + shareEmoji() { + this.setState(({ showShare }) => ({ showShare: !showShare })) + } + insertEditorCommand(command) { this.showLibrary() const commandToInsert = `${command}(50, 50, 100%, 0)` @@ -88,7 +98,7 @@ class App extends Component { } render() { - const { commands, errors, showLibrary, name, textCommands, submitting } = this.state + const { commands, errors, showLibrary, showShare, name, textCommands, submitting } = this.state const { components, errors: cmdErrors } = mapFuncs(commands, functionLibrary) const allErrors = [...errors, ...cmdErrors] @@ -113,6 +123,15 @@ class App extends Component { Save Emoji! + + + + ) } diff --git a/src/components/Share.jsx b/src/components/Share.jsx new file mode 100644 index 0000000..3a5a442 --- /dev/null +++ b/src/components/Share.jsx @@ -0,0 +1,31 @@ +import React, { Fragment } from 'react' +import PropTypes from 'prop-types' + +import Canvas from './Canvas' + +import { generateShareUrl } from '../utils/encode' + + +const Share = ({ + name, + code, + components, +}) => { + return ( +
+
+ +

{name}

+
+

Share this link with your friends to show them your brand new Emoji!

+