diff options
author | Paul Frazee <pfrazee@gmail.com> | 2023-12-07 10:32:55 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-07 10:32:55 -0800 |
commit | 17c27581b6ca972d473fef5a07a699d6a9e5ac17 (patch) | |
tree | aa122e3eb0a528d0ff9010c20de8d883d7af51e6 /src/state/queries/profile.ts | |
parent | 261a935747019d21981a8f3cf0cfd7d83b320cde (diff) | |
download | voidsky-17c27581b6ca972d473fef5a07a699d6a9e5ac17.tar.zst |
Add PWI opt-out toggle (#2122)
* Add PWI opt-out toggle * Bump @atproto/api@0.7.0 * Tweak copy * Bump lockfile * Fix layout on ios * Tweak copy more * Fix types * Tweak copy some more
Diffstat (limited to 'src/state/queries/profile.ts')
-rw-r--r-- | src/state/queries/profile.ts | 80 |
1 files changed, 50 insertions, 30 deletions
diff --git a/src/state/queries/profile.ts b/src/state/queries/profile.ts index 21e519a0f..5fd0b4e34 100644 --- a/src/state/queries/profile.ts +++ b/src/state/queries/profile.ts @@ -49,18 +49,31 @@ export function useProfileQuery({did}: {did: string | undefined}) { interface ProfileUpdateParams { profile: AppBskyActorDefs.ProfileView - updates: AppBskyActorProfile.Record - newUserAvatar: RNImage | undefined | null - newUserBanner: RNImage | undefined | null + updates: + | AppBskyActorProfile.Record + | ((existing: AppBskyActorProfile.Record) => AppBskyActorProfile.Record) + newUserAvatar?: RNImage | undefined | null + newUserBanner?: RNImage | undefined | null + checkCommitted?: (res: AppBskyActorGetProfile.Response) => boolean } export function useProfileUpdateMutation() { const queryClient = useQueryClient() return useMutation<void, Error, ProfileUpdateParams>({ - mutationFn: async ({profile, updates, newUserAvatar, newUserBanner}) => { + mutationFn: async ({ + profile, + updates, + newUserAvatar, + newUserBanner, + checkCommitted, + }) => { await getAgent().upsertProfile(async existing => { existing = existing || {} - existing.displayName = updates.displayName - existing.description = updates.description + if (typeof updates === 'function') { + existing = updates(existing) + } else { + existing.displayName = updates.displayName + existing.description = updates.description + } if (newUserAvatar) { const res = await uploadBlob( getAgent(), @@ -83,30 +96,37 @@ export function useProfileUpdateMutation() { } return existing }) - await whenAppViewReady(profile.did, res => { - if (typeof newUserAvatar !== 'undefined') { - if (newUserAvatar === null && res.data.avatar) { - // url hasnt cleared yet - return false - } else if (res.data.avatar === profile.avatar) { - // url hasnt changed yet - return false - } - } - if (typeof newUserBanner !== 'undefined') { - if (newUserBanner === null && res.data.banner) { - // url hasnt cleared yet - return false - } else if (res.data.banner === profile.banner) { - // url hasnt changed yet - return false - } - } - return ( - res.data.displayName === updates.displayName && - res.data.description === updates.description - ) - }) + await whenAppViewReady( + profile.did, + checkCommitted || + (res => { + if (typeof newUserAvatar !== 'undefined') { + if (newUserAvatar === null && res.data.avatar) { + // url hasnt cleared yet + return false + } else if (res.data.avatar === profile.avatar) { + // url hasnt changed yet + return false + } + } + if (typeof newUserBanner !== 'undefined') { + if (newUserBanner === null && res.data.banner) { + // url hasnt cleared yet + return false + } else if (res.data.banner === profile.banner) { + // url hasnt changed yet + return false + } + } + if (typeof updates === 'function') { + return true + } + return ( + res.data.displayName === updates.displayName && + res.data.description === updates.description + ) + }), + ) }, onSuccess(data, variables) { // invalidate cache |