about summary refs log tree commit diff
path: root/src/state/models
diff options
context:
space:
mode:
Diffstat (limited to 'src/state/models')
-rw-r--r--src/state/models/profile-view.ts24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/state/models/profile-view.ts b/src/state/models/profile-view.ts
index bca4c6158..b245335f1 100644
--- a/src/state/models/profile-view.ts
+++ b/src/state/models/profile-view.ts
@@ -1,6 +1,7 @@
-import {makeAutoObservable} from 'mobx'
+import {makeAutoObservable, runInAction} from 'mobx'
 import {bsky} from '@adxp/mock-api'
 import {RootStoreModel} from './root-store'
+import * as apilib from '../lib/api'
 
 export class ProfileViewMyStateModel {
   hasFollowed: boolean = false
@@ -67,6 +68,27 @@ export class ProfileViewModel implements bsky.ProfileView.Response {
     await this._load()
   }
 
+  async toggleFollowing() {
+    if (this.myState.hasFollowed) {
+      await apilib.unfollow(this.rootStore.api, 'alice.com', {
+        did: this.did,
+      })
+      runInAction(() => {
+        this.followersCount--
+        this.myState.hasFollowed = false
+      })
+    } else {
+      await apilib.follow(this.rootStore.api, 'alice.com', {
+        did: this.did,
+        name: this.name,
+      })
+      runInAction(() => {
+        this.followersCount++
+        this.myState.hasFollowed = true
+      })
+    }
+  }
+
   // state transitions
   // =