about summary refs log tree commit diff
path: root/src/view/com/modals/LinkActions.tsx
blob: deb1518ec4f2a40df63cf7476c88f73980de6448 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import React from 'react'
import Toast from '../util/Toast'
import Clipboard from '@react-native-clipboard/clipboard'
import {StyleSheet, Text, TouchableOpacity, View} from 'react-native'
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
import {useStores} from '../../../state'
import {s, colors} from '../../lib/styles'

export const snapPoints = ['30%']

export function Component({
  title,
  href,
  newTab,
}: {
  title: string
  href: string
  newTab: boolean
}) {
  const store = useStores()

  const onPressOpenNewTab = () => {
    store.shell.closeModal()
    store.nav.newTab(href)
  }

  const onPressCopy = () => {
    Clipboard.setString(href)
    store.shell.closeModal()
    Toast.show('Link copied', {
      position: Toast.positions.TOP,
    })
  }

  return (
    <View>
      <Text style={[s.textCenter, s.bold, s.mb10, s.f16]}>{title || href}</Text>
      <View style={s.p10}>
        {newTab ? (
          <TouchableOpacity onPress={onPressOpenNewTab} style={styles.btn}>
            <FontAwesomeIcon
              icon="arrow-up-right-from-square"
              style={styles.icon}
            />
            <Text style={[s.f16, s.black]}>Open in new tab</Text>
          </TouchableOpacity>
        ) : undefined}
        <TouchableOpacity onPress={onPressCopy} style={styles.btn}>
          <FontAwesomeIcon icon="link" style={styles.icon} />
          <Text style={[s.f16, s.black]}>Copy to clipboard</Text>
        </TouchableOpacity>
      </View>
    </View>
  )
}

const styles = StyleSheet.create({
  btn: {
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'center',
    width: '100%',
    borderColor: colors.gray5,
    borderWidth: 1,
    borderRadius: 4,
    padding: 10,
    marginBottom: 10,
  },
  icon: {
    marginRight: 8,
  },
})