about summary refs log tree commit diff
path: root/src/state
diff options
context:
space:
mode:
Diffstat (limited to 'src/state')
-rw-r--r--src/state/lib/api.ts11
-rw-r--r--src/state/models/profile-view.ts8
-rw-r--r--src/state/models/shell.ts24
3 files changed, 41 insertions, 2 deletions
diff --git a/src/state/lib/api.ts b/src/state/lib/api.ts
index 64a88cdec..3324525bf 100644
--- a/src/state/lib/api.ts
+++ b/src/state/lib/api.ts
@@ -124,6 +124,17 @@ export async function unfollow(
   return numDels > 0
 }
 
+export async function updateProfile(
+  adx: AdxClient,
+  user: string,
+  profile: bsky.Profile.Record,
+) {
+  return await adx
+    .repo(user, true)
+    .collection('blueskyweb.xyz:Profiles')
+    .put('Profile', 'profile', {$type: 'blueskyweb.xyz:Profile', ...profile})
+}
+
 type WherePred = (_record: GetRecordResponseValidated) => Boolean
 async function deleteWhere(
   coll: AdxRepoCollectionClient,
diff --git a/src/state/models/profile-view.ts b/src/state/models/profile-view.ts
index 89c8a75d0..42c3737e9 100644
--- a/src/state/models/profile-view.ts
+++ b/src/state/models/profile-view.ts
@@ -89,6 +89,14 @@ export class ProfileViewModel implements bsky.ProfileView.Response {
     }
   }
 
+  async updateProfile(profile: bsky.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 this.refresh()
+  }
+
   // state transitions
   // =
 
diff --git a/src/state/models/shell.ts b/src/state/models/shell.ts
index c67b474b7..2dddb9a33 100644
--- a/src/state/models/shell.ts
+++ b/src/state/models/shell.ts
@@ -1,4 +1,5 @@
 import {makeAutoObservable} from 'mobx'
+import {ProfileViewModel} from './profile-view'
 
 export class LinkActionsModel {
   name = 'link-actions'
@@ -24,15 +25,34 @@ export class ComposePostModel {
   }
 }
 
+export class EditProfileModel {
+  name = 'edit-profile'
+
+  constructor(public profileView: ProfileViewModel) {
+    makeAutoObservable(this)
+  }
+}
+
 export class ShellModel {
   isModalActive = false
-  activeModal: LinkActionsModel | SharePostModel | ComposePostModel | undefined
+  activeModal:
+    | LinkActionsModel
+    | SharePostModel
+    | ComposePostModel
+    | EditProfileModel
+    | undefined
 
   constructor() {
     makeAutoObservable(this)
   }
 
-  openModal(modal: LinkActionsModel | SharePostModel | ComposePostModel) {
+  openModal(
+    modal:
+      | LinkActionsModel
+      | SharePostModel
+      | ComposePostModel
+      | EditProfileModel,
+  ) {
     this.isModalActive = true
     this.activeModal = modal
   }