create Alert.tsx and Alert.web.tsx and replace uses (#513)
parent
b00365c196
commit
01410ad4bf
|
@ -1,8 +1,8 @@
|
|||
import {Alert} from 'react-native'
|
||||
import {Camera} from 'expo-camera'
|
||||
import * as MediaLibrary from 'expo-media-library'
|
||||
import {Linking} from 'react-native'
|
||||
import {isWeb} from 'platform/detection'
|
||||
import {Alert} from 'view/com/util/Alert'
|
||||
|
||||
const openSettings = () => {
|
||||
Linking.openURL('app-settings:')
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
export {Alert} from 'react-native'
|
|
@ -0,0 +1,23 @@
|
|||
import {AlertButton, AlertStatic} from 'react-native'
|
||||
|
||||
class WebAlert implements Pick<AlertStatic, 'alert'> {
|
||||
public alert(title: string, message?: string, buttons?: AlertButton[]): void {
|
||||
if (buttons === undefined || buttons.length === 0) {
|
||||
window.alert([title, message].filter(Boolean).join('\n'))
|
||||
return
|
||||
}
|
||||
|
||||
const result = window.confirm([title, message].filter(Boolean).join('\n'))
|
||||
|
||||
if (result === true) {
|
||||
const confirm = buttons.find(({style}) => style !== 'cancel')
|
||||
confirm?.onPress?.()
|
||||
return
|
||||
}
|
||||
|
||||
const cancel = buttons.find(({style}) => style === 'cancel')
|
||||
cancel?.onPress?.()
|
||||
}
|
||||
}
|
||||
|
||||
export const Alert = new WebAlert()
|
|
@ -1,5 +1,6 @@
|
|||
import React from 'react'
|
||||
import {Alert, StyleSheet, TouchableOpacity, View} from 'react-native'
|
||||
import {StyleSheet, TouchableOpacity, View} from 'react-native'
|
||||
import {Alert} from 'view/com/util/Alert'
|
||||
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
|
||||
import {ScrollView} from 'react-native-gesture-handler'
|
||||
import {Text} from '../com/util/text/Text'
|
||||
|
@ -159,31 +160,24 @@ function AppPassword({
|
|||
const store = useStores()
|
||||
|
||||
const onDelete = React.useCallback(async () => {
|
||||
if (isDesktopWeb) {
|
||||
if (confirm('Delete app password?')) {
|
||||
await store.me.deleteAppPassword(name)
|
||||
Toast.show('App password deleted')
|
||||
}
|
||||
} else {
|
||||
Alert.alert(
|
||||
'Delete App Password',
|
||||
`Are you sure you want to delete the app password "${name}"?`,
|
||||
[
|
||||
{
|
||||
text: 'Cancel',
|
||||
style: 'cancel',
|
||||
Alert.alert(
|
||||
'Delete App Password',
|
||||
`Are you sure you want to delete the app password "${name}"?`,
|
||||
[
|
||||
{
|
||||
text: 'Cancel',
|
||||
style: 'cancel',
|
||||
},
|
||||
{
|
||||
text: 'Delete',
|
||||
style: 'destructive',
|
||||
onPress: async () => {
|
||||
await store.me.deleteAppPassword(name)
|
||||
Toast.show('App password deleted')
|
||||
},
|
||||
{
|
||||
text: 'Delete',
|
||||
style: 'destructive',
|
||||
onPress: async () => {
|
||||
await store.me.deleteAppPassword(name)
|
||||
Toast.show('App password deleted')
|
||||
},
|
||||
},
|
||||
],
|
||||
)
|
||||
}
|
||||
},
|
||||
],
|
||||
)
|
||||
}, [store, name])
|
||||
|
||||
return (
|
||||
|
|
Loading…
Reference in New Issue