about summary refs log tree commit diff
path: root/src/state/queries
diff options
context:
space:
mode:
authordan <dan.abramov@gmail.com>2024-05-11 19:54:58 +0100
committerGitHub <noreply@github.com>2024-05-11 19:54:58 +0100
commit51b4b22dec9eb48a10befddd30ebff0bd999dc40 (patch)
tree8e4c11bed90e5e1b8707b33c4333ac7bd7f839c9 /src/state/queries
parent6f5b551bdaa133ec6fa0f91f3f9621542b4217a8 (diff)
downloadvoidsky-51b4b22dec9eb48a10befddd30ebff0bd999dc40.tar.zst
Onboarding fixes (#3966)
* Ensure prefs are up-to-date before leaving onboarding

* Parallelize upsertProfile call

* Don't upsertProfile if no image

* Don't waterfall blob upload

* Fix useProfileUpdateMutation to parallelize uploads

* Invalidate user profile before leaving onboarding

* Ungate setting the pic
Diffstat (limited to 'src/state/queries')
-rw-r--r--src/state/queries/profile.ts37
1 files changed, 25 insertions, 12 deletions
diff --git a/src/state/queries/profile.ts b/src/state/queries/profile.ts
index 103d34733..3e2535916 100644
--- a/src/state/queries/profile.ts
+++ b/src/state/queries/profile.ts
@@ -6,6 +6,7 @@ import {
   AppBskyActorProfile,
   AtUri,
   BskyAgent,
+  ComAtprotoRepoUploadBlob,
 } from '@atproto/api'
 import {
   QueryClient,
@@ -124,6 +125,26 @@ export function useProfileUpdateMutation() {
       newUserBanner,
       checkCommitted,
     }) => {
+      let newUserAvatarPromise:
+        | Promise<ComAtprotoRepoUploadBlob.Response>
+        | undefined
+      if (newUserAvatar) {
+        newUserAvatarPromise = uploadBlob(
+          getAgent(),
+          newUserAvatar.path,
+          newUserAvatar.mime,
+        )
+      }
+      let newUserBannerPromise:
+        | Promise<ComAtprotoRepoUploadBlob.Response>
+        | undefined
+      if (newUserBanner) {
+        newUserBannerPromise = uploadBlob(
+          getAgent(),
+          newUserBanner.path,
+          newUserBanner.mime,
+        )
+      }
       await getAgent().upsertProfile(async existing => {
         existing = existing || {}
         if (typeof updates === 'function') {
@@ -132,22 +153,14 @@ export function useProfileUpdateMutation() {
           existing.displayName = updates.displayName
           existing.description = updates.description
         }
-        if (newUserAvatar) {
-          const res = await uploadBlob(
-            getAgent(),
-            newUserAvatar.path,
-            newUserAvatar.mime,
-          )
+        if (newUserAvatarPromise) {
+          const res = await newUserAvatarPromise
           existing.avatar = res.data.blob
         } else if (newUserAvatar === null) {
           existing.avatar = undefined
         }
-        if (newUserBanner) {
-          const res = await uploadBlob(
-            getAgent(),
-            newUserBanner.path,
-            newUserBanner.mime,
-          )
+        if (newUserBannerPromise) {
+          const res = await newUserBannerPromise
           existing.banner = res.data.blob
         } else if (newUserBanner === null) {
           existing.banner = undefined