Dont leave promise unresolved

zio/stable
Paul Frazee 2024-05-06 15:44:19 -07:00
parent e1940983a3
commit fe82257801
3 changed files with 33 additions and 17 deletions

View File

@ -13,7 +13,7 @@ export async function openCamera(_opts: CameraOpts): Promise<RNImage> {
export async function openCropper(opts: CropperOptions): Promise<RNImage> {
// TODO handle more opts
return new Promise(resolve => {
return new Promise((resolve, reject) => {
unstable__openModal({
name: 'crop-image',
uri: opts.path,
@ -24,6 +24,8 @@ export async function openCropper(opts: CropperOptions): Promise<RNImage> {
onSelect: (img?: RNImage) => {
if (img) {
resolve(img)
} else {
reject(new Error('Canceled'))
}
},
})

View File

@ -8,6 +8,7 @@ import {msg, Trans} from '@lingui/macro'
import {useLingui} from '@lingui/react'
import {useQueryClient} from '@tanstack/react-query'
import {logger} from '#/logger'
import {usePalette} from 'lib/hooks/usePalette'
import {
useCameraPermission,
@ -282,6 +283,7 @@ let EditableUserAvatar = ({
return
}
try {
const croppedImage = await openCropper({
mediaType: 'photo',
cropperCircleOverlay: true,
@ -291,6 +293,11 @@ let EditableUserAvatar = ({
})
onSelectNewAvatar(croppedImage)
} catch (e: any) {
if (!String(e).includes('Canceled')) {
logger.error('Failed to crop banner', {error: e})
}
}
}, [onSelectNewAvatar, requestPhotoAccessIfNeeded])
const onRemoveAvatar = React.useCallback(() => {

View File

@ -6,6 +6,7 @@ import {ModerationUI} from '@atproto/api'
import {msg, Trans} from '@lingui/macro'
import {useLingui} from '@lingui/react'
import {logger} from '#/logger'
import {usePalette} from 'lib/hooks/usePalette'
import {
useCameraPermission,
@ -64,6 +65,7 @@ export function UserBanner({
return
}
try {
onSelectNewBanner?.(
await openCropper({
mediaType: 'photo',
@ -72,6 +74,11 @@ export function UserBanner({
height: 1000,
}),
)
} catch (e: any) {
if (!String(e).includes('Canceled')) {
logger.error('Failed to crop banner', {error: e})
}
}
}, [onSelectNewBanner, requestPhotoAccessIfNeeded])
const onRemoveBanner = React.useCallback(() => {