Dont leave promise unresolved
parent
e1940983a3
commit
fe82257801
|
@ -13,7 +13,7 @@ export async function openCamera(_opts: CameraOpts): Promise<RNImage> {
|
||||||
|
|
||||||
export async function openCropper(opts: CropperOptions): Promise<RNImage> {
|
export async function openCropper(opts: CropperOptions): Promise<RNImage> {
|
||||||
// TODO handle more opts
|
// TODO handle more opts
|
||||||
return new Promise(resolve => {
|
return new Promise((resolve, reject) => {
|
||||||
unstable__openModal({
|
unstable__openModal({
|
||||||
name: 'crop-image',
|
name: 'crop-image',
|
||||||
uri: opts.path,
|
uri: opts.path,
|
||||||
|
@ -24,6 +24,8 @@ export async function openCropper(opts: CropperOptions): Promise<RNImage> {
|
||||||
onSelect: (img?: RNImage) => {
|
onSelect: (img?: RNImage) => {
|
||||||
if (img) {
|
if (img) {
|
||||||
resolve(img)
|
resolve(img)
|
||||||
|
} else {
|
||||||
|
reject(new Error('Canceled'))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -8,6 +8,7 @@ import {msg, Trans} from '@lingui/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
import {useQueryClient} from '@tanstack/react-query'
|
import {useQueryClient} from '@tanstack/react-query'
|
||||||
|
|
||||||
|
import {logger} from '#/logger'
|
||||||
import {usePalette} from 'lib/hooks/usePalette'
|
import {usePalette} from 'lib/hooks/usePalette'
|
||||||
import {
|
import {
|
||||||
useCameraPermission,
|
useCameraPermission,
|
||||||
|
@ -282,15 +283,21 @@ let EditableUserAvatar = ({
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const croppedImage = await openCropper({
|
try {
|
||||||
mediaType: 'photo',
|
const croppedImage = await openCropper({
|
||||||
cropperCircleOverlay: true,
|
mediaType: 'photo',
|
||||||
height: item.height,
|
cropperCircleOverlay: true,
|
||||||
width: item.width,
|
height: item.height,
|
||||||
path: item.path,
|
width: item.width,
|
||||||
})
|
path: item.path,
|
||||||
|
})
|
||||||
|
|
||||||
onSelectNewAvatar(croppedImage)
|
onSelectNewAvatar(croppedImage)
|
||||||
|
} catch (e: any) {
|
||||||
|
if (!String(e).includes('Canceled')) {
|
||||||
|
logger.error('Failed to crop banner', {error: e})
|
||||||
|
}
|
||||||
|
}
|
||||||
}, [onSelectNewAvatar, requestPhotoAccessIfNeeded])
|
}, [onSelectNewAvatar, requestPhotoAccessIfNeeded])
|
||||||
|
|
||||||
const onRemoveAvatar = React.useCallback(() => {
|
const onRemoveAvatar = React.useCallback(() => {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import {ModerationUI} from '@atproto/api'
|
||||||
import {msg, Trans} from '@lingui/macro'
|
import {msg, Trans} from '@lingui/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
|
|
||||||
|
import {logger} from '#/logger'
|
||||||
import {usePalette} from 'lib/hooks/usePalette'
|
import {usePalette} from 'lib/hooks/usePalette'
|
||||||
import {
|
import {
|
||||||
useCameraPermission,
|
useCameraPermission,
|
||||||
|
@ -64,14 +65,20 @@ export function UserBanner({
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
onSelectNewBanner?.(
|
try {
|
||||||
await openCropper({
|
onSelectNewBanner?.(
|
||||||
mediaType: 'photo',
|
await openCropper({
|
||||||
path: items[0].path,
|
mediaType: 'photo',
|
||||||
width: 3000,
|
path: items[0].path,
|
||||||
height: 1000,
|
width: 3000,
|
||||||
}),
|
height: 1000,
|
||||||
)
|
}),
|
||||||
|
)
|
||||||
|
} catch (e: any) {
|
||||||
|
if (!String(e).includes('Canceled')) {
|
||||||
|
logger.error('Failed to crop banner', {error: e})
|
||||||
|
}
|
||||||
|
}
|
||||||
}, [onSelectNewBanner, requestPhotoAccessIfNeeded])
|
}, [onSelectNewBanner, requestPhotoAccessIfNeeded])
|
||||||
|
|
||||||
const onRemoveBanner = React.useCallback(() => {
|
const onRemoveBanner = React.useCallback(() => {
|
||||||
|
|
Loading…
Reference in New Issue