diff options
author | Paul Frazee <pfrazee@gmail.com> | 2022-07-26 10:29:59 -0500 |
---|---|---|
committer | Paul Frazee <pfrazee@gmail.com> | 2022-07-26 10:29:59 -0500 |
commit | 1504d144d9bbb90e4e048702f1e1b3db9d7ce17e (patch) | |
tree | 26e07d3dcfb4881b25edba434d3f4db6e72277ba /src/state/models/profile-view.ts | |
parent | adc25ce468666bf38892cc8251165a6fde37a2e1 (diff) | |
download | voidsky-1504d144d9bbb90e4e048702f1e1b3db9d7ce17e.tar.zst |
Implement follow/unfollow
Diffstat (limited to 'src/state/models/profile-view.ts')
-rw-r--r-- | src/state/models/profile-view.ts | 24 |
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 // = |