diff --git a/website/src/components/Playground/URLShortener.css b/website/src/components/Playground/URLShortener.css new file mode 100644 index 00000000..2b9f5e12 --- /dev/null +++ b/website/src/components/Playground/URLShortener.css @@ -0,0 +1,7 @@ +.URLShortener { + position: absolute; + bottom: 30px; + left: 30px; + z-index: 4; + box-shadow: 1px 1px 15px rgba(0, 0, 0, 0.2); +} diff --git a/website/src/components/Playground/URLShortener.js b/website/src/components/Playground/URLShortener.js new file mode 100644 index 00000000..b93469b9 --- /dev/null +++ b/website/src/components/Playground/URLShortener.js @@ -0,0 +1,68 @@ +/** + * Copyright (c) 2014-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + * + * @flow + * @format + */ + +import React, {Component} from 'react'; +import {Tooltip, notification, Button, Input} from 'antd'; +import './URLShortener.css'; + +const API_KEY = 'AIzaSyCRvdtNY07SGUokChS8oA9EaYJafFL0zMI'; + +export default class URLShortener extends Component<{}> { + _ref: ?HTMLElement = null; + + onClick = () => { + fetch(`https://www.googleapis.com/urlshortener/v1/url?key=${API_KEY}`, { + method: 'POST', + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + kind: 'urlshortener#url', + longUrl: window.location.href, + }), + }) + .then(res => res.json()) + .then(({id}) => { + notification.open({ + message: 'Created short URL', + description: ( + { + if (ref) { + ref.input.select(); + } + }} + /> + ), + placement: 'bottomLeft', + }); + }); + }; + + render() { + return ( + +