Bluesky app fork with some witchin' additions 💫

create Alert.tsx and Alert.web.tsx and replace uses (#513)

authored by

Ansh and committed by
GitHub
01410ad4 b00365c1

+44 -26
+1 -1
src/lib/hooks/usePermissions.ts
··· 1 - import {Alert} from 'react-native' 2 1 import {Camera} from 'expo-camera' 3 2 import * as MediaLibrary from 'expo-media-library' 4 3 import {Linking} from 'react-native' 5 4 import {isWeb} from 'platform/detection' 5 + import {Alert} from 'view/com/util/Alert' 6 6 7 7 const openSettings = () => { 8 8 Linking.openURL('app-settings:')
+1
src/view/com/util/Alert.tsx
··· 1 + export {Alert} from 'react-native'
+23
src/view/com/util/Alert.web.tsx
··· 1 + import {AlertButton, AlertStatic} from 'react-native' 2 + 3 + class WebAlert implements Pick<AlertStatic, 'alert'> { 4 + public alert(title: string, message?: string, buttons?: AlertButton[]): void { 5 + if (buttons === undefined || buttons.length === 0) { 6 + window.alert([title, message].filter(Boolean).join('\n')) 7 + return 8 + } 9 + 10 + const result = window.confirm([title, message].filter(Boolean).join('\n')) 11 + 12 + if (result === true) { 13 + const confirm = buttons.find(({style}) => style !== 'cancel') 14 + confirm?.onPress?.() 15 + return 16 + } 17 + 18 + const cancel = buttons.find(({style}) => style === 'cancel') 19 + cancel?.onPress?.() 20 + } 21 + } 22 + 23 + export const Alert = new WebAlert()
+19 -25
src/view/screens/AppPasswords.tsx
··· 1 1 import React from 'react' 2 - import {Alert, StyleSheet, TouchableOpacity, View} from 'react-native' 2 + import {StyleSheet, TouchableOpacity, View} from 'react-native' 3 + import {Alert} from 'view/com/util/Alert' 3 4 import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' 4 5 import {ScrollView} from 'react-native-gesture-handler' 5 6 import {Text} from '../com/util/text/Text' ··· 159 160 const store = useStores() 160 161 161 162 const onDelete = React.useCallback(async () => { 162 - if (isDesktopWeb) { 163 - if (confirm('Delete app password?')) { 164 - await store.me.deleteAppPassword(name) 165 - Toast.show('App password deleted') 166 - } 167 - } else { 168 - Alert.alert( 169 - 'Delete App Password', 170 - `Are you sure you want to delete the app password "${name}"?`, 171 - [ 172 - { 173 - text: 'Cancel', 174 - style: 'cancel', 163 + Alert.alert( 164 + 'Delete App Password', 165 + `Are you sure you want to delete the app password "${name}"?`, 166 + [ 167 + { 168 + text: 'Cancel', 169 + style: 'cancel', 170 + }, 171 + { 172 + text: 'Delete', 173 + style: 'destructive', 174 + onPress: async () => { 175 + await store.me.deleteAppPassword(name) 176 + Toast.show('App password deleted') 175 177 }, 176 - { 177 - text: 'Delete', 178 - style: 'destructive', 179 - onPress: async () => { 180 - await store.me.deleteAppPassword(name) 181 - Toast.show('App password deleted') 182 - }, 183 - }, 184 - ], 185 - ) 186 - } 178 + }, 179 + ], 180 + ) 187 181 }, [store, name]) 188 182 189 183 return (