Implement follow/unfollow

This commit is contained in:
Paul Frazee 2022-07-26 10:29:59 -05:00
parent adc25ce468
commit 1504d144d9
5 changed files with 83 additions and 6 deletions

View file

@ -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
// =