<commit_before>﻿import React from 'react'
import { browserHistory } from 'react-router'
import { iOS } from '../models/ios.js'
import Clipboard from 'clipboard'

let clipboard = undefined
class Pin extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
      email: '',
      copied: false,
      hide: false,
      emailSent: false
    }
    this.triggerClose = this.triggerClose.bind(this)
    this.triggerClipboard = this.triggerClipboard.bind(this)
    this.sendEmail = this.sendEmail.bind(this)
    this.triggerChange = this.triggerChange.bind(this)
  }
  componentDidMount() {
    clipboard = new Clipboard('.clipboardcopy');
  }
  componentWillUnmount() {
    clipboard.destroy()
  }
  triggerClose(e) {
    if (e) {
      e.preventDefault()
    }
    
    this.setState({
      hide: true
    })

    setTimeout(() => {
      this.props.onHide()
    }, 400)
  }
  triggerClipboard() {
    if (this.state.copied) {
      this.triggerClose()
    } else {
      this.setState({
        copied: true
      })
    }
  }
  doNothing(e) {
    e.preventDefault()
  }

  sendEmail(e){
    e.preventDefault()
    fetch('/a/email', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        email: this.state.email
      })
    })
    this.setState({
      emailSent: true
    })
  }
  triggerChange(e) {
    this.setState({
      email: e.currentTarget.value
    })
  }
  render() {
    var userAgent = window.navigator.userAgent.toLowerCase()
    var output = <div className="other">
      <p>We don't know what browser you're using. 😕😕😕</p>
      <button className="primary" onTouchTap={this.triggerClose}>Maybe next time.</button>
    </div>
    var linktext = 'Copy Link'
    if (this.state.copied) {
      linktext = 'Copied!'
    }
    if (iOS.detect()) {
      // jfc why is everything a uawebview in ios
      if (/crios/.test(userAgent) || /fxios/.test(userAgent) ||
          /fbios/.test(userAgent) || /twitter/.test(userAgent)) {
        output = <div className="ios-other">
          <p>You’ll need to open this app in Safari first!</p>
          <button className="primary clipboardcopy" data-clipboard-text="https://transit.dymajo.com" onTouchTap={this.triggerClipboard}>{linktext}</button>
        </div>
      } else if (/safari/.test(userAgent)) {
        output = <div className="ios-safari">
          <p>Tap the <img src="/icons/ios-share.png" alt="share" /> button, then tap <strong>add to home screen</strong>.</p>
          <button className="primary" onTouchTap={this.triggerClose}>Thanks!</button>
        </div>
      // yeah so chrome and ff both identy themselves as safari like wtf
      } else {
        output = <div className="ios-other">
          <p>You’ll need to open this app in Safari first!</p>
          <p><a href="https://transit.dymajo.com" onClick={this.doNothing}>transit.dymajo.com</a></p>
          <button className="primary clipboardcopy" data-clipboard-text="https://transit.dymajo.com" onTouchTap={this.triggerClipboard}>{linktext}</button>
        </div><commit_msg>Small fix for iOS Facebook Webview<commit_after>﻿import React from 'react'
import { browserHistory } from 'react-router'
import { iOS } from '../models/ios.js'
import Clipboard from 'clipboard'

let clipboard = undefined
class Pin extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
      email: '',
      copied: false,
      hide: false,
      emailSent: false
    }
    this.triggerClose = this.triggerClose.bind(this)
    this.triggerClipboard = this.triggerClipboard.bind(this)
    this.sendEmail = this.sendEmail.bind(this)
    this.triggerChange = this.triggerChange.bind(this)
  }
  componentDidMount() {
    clipboard = new Clipboard('.clipboardcopy');
  }
  componentWillUnmount() {
    clipboard.destroy()
  }
  triggerClose(e) {
    if (e) {
      e.preventDefault()
    }
    
    this.setState({
      hide: true
    })

    setTimeout(() => {
      this.props.onHide()
    }, 400)
  }
  triggerClipboard() {
    if (this.state.copied) {
      this.triggerClose()
    } else {
      this.setState({
        copied: true
      })
    }
  }
  doNothing(e) {
    e.preventDefault()
  }

  sendEmail(e){
    e.preventDefault()
    fetch('/a/email', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        email: this.state.email
      })
    })
    this.setState({
      emailSent: true
    })
  }
  triggerChange(e) {
    this.setState({
      email: e.currentTarget.value
    })
  }
  render() {
    var userAgent = window.navigator.userAgent.toLowerCase()
    var output = <div className="other">
      <p>We don't know what browser you're using. 😕😕😕</p>
      <button className="primary" onTouchTap={this.triggerClose}>Maybe next time.</button>
    </div>
    var linktext = 'Copy Link'
    if (this.state.copied) {
      linktext = 'Copied!'
    }
    if (iOS.detect()) {
      // jfc why is everything a uawebview in ios
      if (/crios/.test(userAgent) || /fxios/.test(userAgent) ||
          /fbios/.test(userAgent) || /twitter/.test(userAgent)) {
        output = <div className="ios-other">
          <p>You’ll need to open this app in Safari first!</p>
          <button className="primary clipboardcopy" data-clipboard-text="https://transit.dymajo.com" onTouchTap={this.triggerClipboard}>{linktext}</button>
          <br /><br />
        </div>
      } else if (/safari/.test(userAgent)) {
        output = <div className="ios-safari">
          <p>Tap the <img src="/icons/ios-share.png" alt="share" /> button, then tap <strong>add to home screen</strong>.</p>
          <button className="primary" onTouchTap={this.triggerClose}>Thanks!</button>
        </div>
      // yeah so chrome and ff both identy themselves as safari like wtf
      } else {
        output = <div className="ios-other">
          <p>You’ll need to open this app in Safari first!</p>
          <p><a href="https://transit.dymajo.com" onClick={this.doNothing}>transit.dymajo.com</a></p>
          <button className="primary clipboardcopy" data-clipboard-text="https://transit.dymajo.com" onTouchTap={this.triggerClipboard}>{linktext}</button>
        </div>
{'fraction_non_alphanumeric': 0.14777070063694267, 'fraction_numerical': 0.0009554140127388535, 'mean_word_length': 2.578917378917379, 'pattern_counts': {'":': 0, '<': 67, '<?xml version=': 0, '>': 69, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3464227', 'n_tokens_mistral': 2034, 'n_tokens_neox': 2020, 'n_words': 416}