about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/state/lib/api.ts28
-rw-r--r--src/state/models/profile-view.ts4
-rw-r--r--src/view/com/modals/EditProfile.tsx18
3 files changed, 39 insertions, 11 deletions
diff --git a/src/state/lib/api.ts b/src/state/lib/api.ts
index ad81301ff..f2418ef31 100644
--- a/src/state/lib/api.ts
+++ b/src/state/lib/api.ts
@@ -5,7 +5,7 @@
 
 // import {ReactNativeStore} from './auth'
 import AdxApi from '../../third-party/api'
-import {ServiceClient} from '../../third-party/api/src/index'
+import * as Profile from '../../third-party/api/src/types/todo/social/profile'
 import {AdxUri} from '../../third-party/uri'
 import {RootStoreModel} from '../models/root-store'
 import {extractEntities} from '../../view/lib/strings'
@@ -100,11 +100,29 @@ export async function unfollow(store: RootStoreModel, followUri: string) {
 }
 
 export async function updateProfile(
-  adx: ServiceClient,
-  user: string,
-  profile: bsky.Profile.Record,
+  store: RootStoreModel,
+  modifyFn: (existing?: Profile.Record) => Profile.Record,
 ) {
-  throw new Error('TODO')
+  const res = await store.api.todo.social.profile.list({
+    nameOrDid: store.me.did || '',
+  })
+  const existing = res.records[0]
+  if (existing) {
+    await store.api.todo.social.profile.put(
+      {
+        did: store.me.did || '',
+        tid: new AdxUri(existing.uri).recordKey,
+      },
+      modifyFn(existing.value),
+    )
+  } else {
+    await store.api.todo.social.profile.create(
+      {
+        did: store.me.did || '',
+      },
+      modifyFn(),
+    )
+  }
 }
 
 interface FetchHandlerResponse {
diff --git a/src/state/models/profile-view.ts b/src/state/models/profile-view.ts
index a7b8a7c7f..aa0040d65 100644
--- a/src/state/models/profile-view.ts
+++ b/src/state/models/profile-view.ts
@@ -88,11 +88,11 @@ export class ProfileViewModel {
     }
   }
 
-  async updateProfile(profile: Profile.Record) {
+  async updateProfile(fn: (existing?: Profile.Record) => Profile.Record) {
     if (this.did !== this.rootStore.me.did) {
       throw new Error('Not your profile!')
     }
-    await apilib.updateProfile(this.rootStore.api, this.did, profile)
+    await apilib.updateProfile(this.rootStore, fn)
     await this.refresh()
   }
 
diff --git a/src/view/com/modals/EditProfile.tsx b/src/view/com/modals/EditProfile.tsx
index 72cbd4119..740d81895 100644
--- a/src/view/com/modals/EditProfile.tsx
+++ b/src/view/com/modals/EditProfile.tsx
@@ -6,6 +6,7 @@ import {ErrorMessage} from '../util/ErrorMessage'
 import {useStores} from '../../../state'
 import {ProfileViewModel} from '../../../state/models/profile-view'
 import {s, colors, gradients} from '../../lib/styles'
+import * as Profile from '../../../third-party/api/src/types/todo/social/profile'
 
 export const snapPoints = ['80%']
 
@@ -23,10 +24,19 @@ export function Component({profileView}: {profileView: ProfileViewModel}) {
       setError('')
     }
     try {
-      await profileView.updateProfile({
-        displayName,
-        description,
-      })
+      await profileView.updateProfile(
+        (existing?: Profile.Record): Profile.Record => {
+          if (existing) {
+            existing.displayName = displayName
+            existing.description = description
+            return existing
+          }
+          return {
+            displayName,
+            description,
+          }
+        },
+      )
       Toast.show('Profile updated', {
         position: Toast.positions.TOP,
       })