view all saved algos in settings

This commit is contained in:
Ansh Nanda 2023-05-13 12:25:06 -07:00
parent 047024a5ac
commit 8948118d5c
5 changed files with 91 additions and 17 deletions

View file

@ -1,8 +1,7 @@
import {AppBskyFeedDefs} from '@atproto/api'
import {makeAutoObservable, makeObservable} from 'mobx'
import {makeAutoObservable} from 'mobx'
import {RootStoreModel} from 'state/models/root-store'
// algoitemmodel implemented in mobx
export class AlgoItemModel {
// data
data: AppBskyFeedDefs.GeneratorView
@ -21,6 +20,8 @@ export class AlgoItemModel {
)
}
// local actions
// =
set toggleSaved(value: boolean) {
console.log('toggleSaved', this.data.viewer)
if (this.data.viewer) {
@ -28,12 +29,12 @@ export class AlgoItemModel {
}
}
// public apis
// =
async save() {
try {
// runInAction(() => {
this.toggleSaved = true
// })
const res = await this.rootStore.agent.app.bsky.feed.saveFeed({
await this.rootStore.agent.app.bsky.feed.saveFeed({
feed: this.data.uri,
})
} catch (e: any) {
@ -43,10 +44,8 @@ export class AlgoItemModel {
async unsave() {
try {
// runInAction(() => {
this.toggleSaved = false
// })
const res = await this.rootStore.agent.app.bsky.feed.unsaveFeed({
await this.rootStore.agent.app.bsky.feed.unsaveFeed({
feed: this.data.uri,
})
} catch (e: any) {

View file

@ -110,7 +110,7 @@ export class SavedFeedsModel {
this.loadMoreCursor = res.data.cursor
this.hasMore = !!this.loadMoreCursor
for (const f of res.data.feeds) {
this.feeds.push(new AlgoItemModel(f))
this.feeds.push(new AlgoItemModel(this.rootStore, f))
}
}
}

View file

@ -8,6 +8,7 @@ import {PostsFeedModel} from './feeds/posts'
import {NotificationsFeedModel} from './feeds/notifications'
import {MyFollowsCache} from './cache/my-follows'
import {isObj, hasProp} from 'lib/type-guards'
import {SavedFeedsModel} from './feeds/algo/saved'
const PROFILE_UPDATE_INTERVAL = 10 * 60 * 1e3 // 10min
const NOTIFS_UPDATE_INTERVAL = 30 * 1e3 // 30sec
@ -21,6 +22,7 @@ export class MeModel {
followsCount: number | undefined
followersCount: number | undefined
mainFeed: PostsFeedModel
savedFeeds: SavedFeedsModel
notifications: NotificationsFeedModel
follows: MyFollowsCache
invites: ComAtprotoServerDefs.InviteCode[] = []
@ -43,12 +45,14 @@ export class MeModel {
})
this.notifications = new NotificationsFeedModel(this.rootStore)
this.follows = new MyFollowsCache(this.rootStore)
this.savedFeeds = new SavedFeedsModel(this.rootStore)
}
clear() {
this.mainFeed.clear()
this.notifications.clear()
this.follows.clear()
this.savedFeeds.clear()
this.did = ''
this.handle = ''
this.displayName = ''
@ -110,6 +114,7 @@ export class MeModel {
/* dont await */ this.notifications.setup().catch(e => {
this.rootStore.log.error('Failed to setup notifications model', e)
})
/* dont await */ this.savedFeeds.refresh()
this.rootStore.emitSessionLoaded()
await this.fetchInviteCodes()
await this.fetchAppPasswords()