From d7b0eaed1f1ce7d549a5a226a31de7f123ee0cbc Mon Sep 17 00:00:00 2001 From: Greg Fodor <gfodor@gmail.com> Date: Mon, 1 Oct 2018 06:19:55 +0000 Subject: [PATCH] New link redirect --- src/assets/stylesheets/link.scss | 2 +- src/link.js | 13 +--------- src/react-components/link-root.js | 41 +++++++++---------------------- 3 files changed, 14 insertions(+), 42 deletions(-) diff --git a/src/assets/stylesheets/link.scss b/src/assets/stylesheets/link.scss index b94325c50..accfb2be2 100644 --- a/src/assets/stylesheets/link.scss +++ b/src/assets/stylesheets/link.scss @@ -169,7 +169,7 @@ a { background: transparent; color: white; margin: 0; - font-size: 64pt; + font-size: 52pt; border: 0; width: 295px; letter-spacing: 0.08em; diff --git a/src/link.js b/src/link.js index 401fe54d9..908f7f64d 100644 --- a/src/link.js +++ b/src/link.js @@ -3,18 +3,7 @@ import React from "react"; import ReactDOM from "react-dom"; import registerTelemetry from "./telemetry"; import LinkRoot from "./react-components/link-root"; -import LinkChannel from "./utils/link-channel"; -import { connectToReticulum } from "./utils/phoenix-utils"; -import Store from "./storage/store"; registerTelemetry(); -const socket = connectToReticulum(); -const store = new Store(); -store.init(); - -const linkChannel = new LinkChannel(store); - -linkChannel.setSocket(socket); - -ReactDOM.render(<LinkRoot store={store} linkChannel={linkChannel} />, document.getElementById("link-root")); +ReactDOM.render(<LinkRoot />, document.getElementById("link-root")); diff --git a/src/react-components/link-root.js b/src/react-components/link-root.js index 84b710163..f9aab014b 100644 --- a/src/react-components/link-root.js +++ b/src/react-components/link-root.js @@ -8,16 +8,14 @@ import classNames from "classnames"; import styles from "../assets/stylesheets/link.scss"; import { disableiOSZoom } from "../utils/disable-ios-zoom"; -const MAX_DIGITS = 4; +const MAX_DIGITS = 6; addLocaleData([...en]); disableiOSZoom(); class LinkRoot extends Component { static propTypes = { - intl: PropTypes.object, - store: PropTypes.object, - linkChannel: PropTypes.object + intl: PropTypes.object }; state = { @@ -62,30 +60,15 @@ class LinkRoot extends Component { this.setState({ enteredDigits: enteredDigits.substring(0, enteredDigits.length - 1) }); }; - attemptLink = code => { - this.props.linkChannel - .attemptLink(code) - .then(response => { - // If there is a profile from the linked device, copy it over if we don't have one yet. - if (response.profile) { - const { hasChangedName } = this.props.store.state.activity; - - if (!hasChangedName) { - this.props.store.update({ activity: { hasChangedName: true }, profile: response.profile }); - } - } - - if (response.path) { - window.location.href = response.path; - } - }) - .catch(e => { - this.setState({ failedAtLeastOnce: true, enteredDigits: "" }); - - if (!(e instanceof Error && (e.message === "in_use" || e.message === "failed"))) { - throw e; - } - }); + attemptLink = async code => { + const url = "https://hub.link/" + code; + const res = await fetch(url); + + if (res.status >= 400) { + this.setState({ failedAtLeastOnce: true, enteredDigits: "" }); + } else { + document.location = url; + } }; render() { @@ -119,7 +102,7 @@ class LinkRoot extends Component { onChange={ev => { this.setState({ enteredDigits: ev.target.value }); }} - placeholder="- - - -" + placeholder="- - - - - -" /> </div> -- GitLab