about summary refs log tree commit diff
path: root/src/platform/urls.tsx
blob: 048c92f2eb71204adfddb2abed0cecd175334504 (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
import {Linking} from 'react-native'
import {isIOS, isAndroid, isNative, isWeb} from './detection'

export function makeAppUrl(path = '') {
  if (isIOS) {
    return `pubsqapp://${path}`
  } else if (isAndroid) {
    return `pubsq://app${path}`
  } else {
    // @ts-ignore window exists -prf
    return `${window.location.origin}${path}`
  }
}

export function extractHashFragment(url: string): string {
  return url.split('#')[1] || ''
}

export async function getInitialURL(): Promise<string> {
  if (isNative) {
    const url = await Linking.getInitialURL()
    if (url) {
      return url
    }
    return makeAppUrl()
  } else {
    // @ts-ignore window exists -prf
    return window.location.toString()
  }
}

export function clearHash() {
  if (isWeb) {
    // @ts-ignore window exists -prf
    window.location.hash = ''
  }
}