Changeset View
Changeset View
Standalone View
Standalone View
native/avatars/edit-thread-avatar-provider.react.js
Show All 35 Lines | +setThreadAvatar: ( | ||||
threadID: string, | threadID: string, | ||||
avatarRequest: UpdateUserAvatarRequest, | avatarRequest: UpdateUserAvatarRequest, | ||||
) => Promise<void>, | ) => Promise<void>, | ||||
}; | }; | ||||
const EditThreadAvatarContext: React.Context<?EditThreadAvatarContextType> = | const EditThreadAvatarContext: React.Context<?EditThreadAvatarContextType> = | ||||
React.createContext<?EditThreadAvatarContextType>(); | React.createContext<?EditThreadAvatarContextType>(); | ||||
const displayFailureAlert = () => | |||||
Alert.alert( | |||||
'Couldn’t save avatar', | |||||
'Please try again later', | |||||
[{ text: 'OK' }], | |||||
{ cancelable: true }, | |||||
); | |||||
type Props = { | type Props = { | ||||
+children: React.Node, | +children: React.Node, | ||||
}; | }; | ||||
function EditThreadAvatarProvider(props: Props): React.Node { | function EditThreadAvatarProvider(props: Props): React.Node { | ||||
const { children } = props; | const { children } = props; | ||||
const navContext = React.useContext(NavContext); | const navContext = React.useContext(NavContext); | ||||
const activeThreadID = React.useMemo( | const activeThreadID = React.useMemo( | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | async (selection: NativeMediaSelection, threadID: string) => { | ||||
const action = changeThreadSettingsActionTypes.started; | const action = changeThreadSettingsActionTypes.started; | ||||
dispatchActionPromise( | dispatchActionPromise( | ||||
changeThreadSettingsActionTypes, | changeThreadSettingsActionTypes, | ||||
(async () => { | (async () => { | ||||
updateThreadAvatarMediaUploadInProgress(false); | updateThreadAvatarMediaUploadInProgress(false); | ||||
try { | try { | ||||
return await changeThreadSettingsCall(updateThreadRequest); | return await changeThreadSettingsCall(updateThreadRequest); | ||||
} catch (e) { | } catch (e) { | ||||
Alert.alert('Avatar update failed', 'Unable to update avatar.'); | displayFailureAlert(); | ||||
throw e; | throw e; | ||||
} | } | ||||
})(), | })(), | ||||
{ | { | ||||
customKeyName: `${action}:${threadID}:avatar`, | customKeyName: `${action}:${threadID}:avatar`, | ||||
}, | }, | ||||
); | ); | ||||
}, | }, | ||||
Show All 24 Lines | async (threadID: string, avatarRequest: UpdateUserAvatarRequest) => { | ||||
avatar: avatarRequest, | avatar: avatarRequest, | ||||
}, | }, | ||||
}; | }; | ||||
const action = changeThreadSettingsActionTypes.started; | const action = changeThreadSettingsActionTypes.started; | ||||
const promise = (async () => { | const promise = (async () => { | ||||
try { | try { | ||||
return await changeThreadSettingsCall(updateThreadRequest); | return await changeThreadSettingsCall(updateThreadRequest); | ||||
} catch (e) { | } catch (e) { | ||||
Alert.alert('Avatar update failed', 'Unable to update avatar.'); | displayFailureAlert(); | ||||
throw e; | throw e; | ||||
} | } | ||||
})(); | })(); | ||||
dispatchActionPromise(changeThreadSettingsActionTypes, promise, { | dispatchActionPromise(changeThreadSettingsActionTypes, promise, { | ||||
customKeyName: `${action}:${threadID}:avatar`, | customKeyName: `${action}:${threadID}:avatar`, | ||||
}); | }); | ||||
await promise; | await promise; | ||||
}, | }, | ||||
Show All 26 Lines |