diff --git a/src/state/models/feeds/actor.ts b/src/state/models/feeds/algo/actor.ts similarity index 88% rename from src/state/models/feeds/actor.ts rename to src/state/models/feeds/algo/actor.ts index 08b7c2a7..e42df849 100644 --- a/src/state/models/feeds/actor.ts +++ b/src/state/models/feeds/algo/actor.ts @@ -1,11 +1,9 @@ import {makeAutoObservable} from 'mobx' -import { - AppBskyFeedDefs as FeedDefs, - AppBskyFeedGetActorFeeds as GetActorFeeds, -} from '@atproto/api' -import {RootStoreModel} from '../root-store' +import {AppBskyFeedGetActorFeeds as GetActorFeeds} from '@atproto/api' +import {RootStoreModel} from '../../root-store' import {bundleAsync} from 'lib/async/bundle' import {cleanError} from 'lib/strings/errors' +import {AlgoItemModel} from './algo-item' const PAGE_SIZE = 30 @@ -19,7 +17,7 @@ export class ActorFeedsModel { loadMoreCursor?: string // data - feeds: FeedDefs.GeneratorView[] = [] + feeds: AlgoItemModel[] = [] constructor( public rootStore: RootStoreModel, @@ -116,6 +114,8 @@ export class ActorFeedsModel { _appendAll(res: GetActorFeeds.Response) { this.loadMoreCursor = res.data.cursor this.hasMore = !!this.loadMoreCursor - this.feeds = this.feeds.concat(res.data.feeds) + for (const f of res.data.feeds) { + this.feeds.push(new AlgoItemModel(this.rootStore, f)) + } } } diff --git a/src/state/models/feeds/algo/algo-item.ts b/src/state/models/feeds/algo/algo-item.ts new file mode 100644 index 00000000..555d1d56 --- /dev/null +++ b/src/state/models/feeds/algo/algo-item.ts @@ -0,0 +1,56 @@ +import {AppBskyFeedDefs} from '@atproto/api' +import {makeAutoObservable, makeObservable} from 'mobx' +import {RootStoreModel} from 'state/models/root-store' + +// algoitemmodel implemented in mobx +export class AlgoItemModel { + // data + data: AppBskyFeedDefs.GeneratorView + + constructor( + public rootStore: RootStoreModel, + view: AppBskyFeedDefs.GeneratorView, + ) { + this.data = view + makeAutoObservable( + this, + { + rootStore: false, + }, + {autoBind: true}, + ) + } + + set toggleSaved(value: boolean) { + console.log('toggleSaved', this.data.viewer) + if (this.data.viewer) { + this.data.viewer.saved = value + } + } + + async save() { + try { + // runInAction(() => { + this.toggleSaved = true + // }) + const res = await this.rootStore.agent.app.bsky.feed.saveFeed({ + feed: this.data.uri, + }) + } catch (e: any) { + this.rootStore.log.error('Failed to save feed', e) + } + } + + async unsave() { + try { + // runInAction(() => { + this.toggleSaved = false + // }) + const res = await this.rootStore.agent.app.bsky.feed.unsaveFeed({ + feed: this.data.uri, + }) + } catch (e: any) { + this.rootStore.log.error('Failed to unsanve feed', e) + } + } +} diff --git a/src/state/models/feeds/bookmarked.ts b/src/state/models/feeds/algo/saved.ts similarity index 65% rename from src/state/models/feeds/bookmarked.ts rename to src/state/models/feeds/algo/saved.ts index d472f048..fabb75ae 100644 --- a/src/state/models/feeds/bookmarked.ts +++ b/src/state/models/feeds/algo/saved.ts @@ -1,17 +1,13 @@ import {makeAutoObservable} from 'mobx' -import { - AppBskyFeedGetBookmarkedFeeds as GetBookmarkedFeeds, - // AppBskyFeedBookmarkFeed as bookmarkedFeed, - // AppBskyFeedUnbookmarkFeed as unbookmarkFeed, - AppBskyFeedDefs as FeedDefs, -} from '@atproto/api' -import {RootStoreModel} from '../root-store' +import {AppBskyFeedGetSavedFeeds as GetSavedFeeds} from '@atproto/api' +import {RootStoreModel} from '../../root-store' import {bundleAsync} from 'lib/async/bundle' import {cleanError} from 'lib/strings/errors' +import {AlgoItemModel} from './algo-item' const PAGE_SIZE = 30 -export class BookmarkedFeedsModel { +export class SavedFeedsModel { // state isLoading = false isRefreshing = false @@ -21,7 +17,7 @@ export class BookmarkedFeedsModel { loadMoreCursor?: string // data - feeds: FeedDefs.GeneratorView[] = [] + feeds: AlgoItemModel[] = [] constructor(public rootStore: RootStoreModel) { makeAutoObservable( @@ -68,7 +64,7 @@ export class BookmarkedFeedsModel { } this._xLoading(replace) try { - const res = await this.rootStore.agent.app.bsky.feed.getBookmarkedFeeds({ + const res = await this.rootStore.agent.app.bsky.feed.getSavedFeeds({ limit: PAGE_SIZE, cursor: replace ? undefined : this.loadMoreCursor, }) @@ -83,22 +79,6 @@ export class BookmarkedFeedsModel { } }) - async bookmark(feed: FeedDefs.GeneratorView) { - try { - await this.rootStore.agent.app.bsky.feed.bookmarkFeed({feed: feed.uri}) - } catch (e: any) { - this.rootStore.log.error('Failed to bookmark feed', e) - } - } - - async unbookmark(feed: FeedDefs.GeneratorView) { - try { - await this.rootStore.agent.app.bsky.feed.unbookmarkFeed({feed: feed.uri}) - } catch (e: any) { - this.rootStore.log.error('Failed to unbookmark feed', e) - } - } - // state transitions // = @@ -121,14 +101,16 @@ export class BookmarkedFeedsModel { // helper functions // = - _replaceAll(res: GetBookmarkedFeeds.Response) { + _replaceAll(res: GetSavedFeeds.Response) { this.feeds = [] this._appendAll(res) } - _appendAll(res: GetBookmarkedFeeds.Response) { + _appendAll(res: GetSavedFeeds.Response) { this.loadMoreCursor = res.data.cursor this.hasMore = !!this.loadMoreCursor - this.feeds = this.feeds.concat(res.data.feeds) + for (const f of res.data.feeds) { + this.feeds.push(new AlgoItemModel(f)) + } } } diff --git a/src/state/models/ui/profile.ts b/src/state/models/ui/profile.ts index 86199108..855955d1 100644 --- a/src/state/models/ui/profile.ts +++ b/src/state/models/ui/profile.ts @@ -2,7 +2,7 @@ import {makeAutoObservable} from 'mobx' import {RootStoreModel} from '../root-store' import {ProfileModel} from '../content/profile' import {PostsFeedModel} from '../feeds/posts' -import {ActorFeedsModel} from '../feeds/actor' +import {ActorFeedsModel} from '../feeds/algo/actor' import {AppBskyFeedDefs} from '@atproto/api' export enum Sections { diff --git a/src/view/com/algos/AlgoItem.tsx b/src/view/com/algos/AlgoItem.tsx index 979518f1..987bfd68 100644 --- a/src/view/com/algos/AlgoItem.tsx +++ b/src/view/com/algos/AlgoItem.tsx @@ -1,41 +1,62 @@ import React from 'react' import {StyleProp, StyleSheet, View, ViewStyle} from 'react-native' import {Text} from '../util/text/Text' -import {AppBskyFeedDefs} from '@atproto/api' import {usePalette} from 'lib/hooks/usePalette' import {s} from 'lib/styles' import {UserAvatar} from '../util/UserAvatar' +import {Button} from '../util/forms/Button' +import {observer} from 'mobx-react-lite' +import {AlgoItemModel} from 'state/models/feeds/algo/algo-item' -const AlgoItem = ({ - item, - style, -}: { - item: AppBskyFeedDefs.GeneratorView - style?: StyleProp -}) => { - const pal = usePalette('default') - return ( - - - - +const AlgoItem = observer( + ({item, style}: {item: AlgoItemModel; style?: StyleProp}) => { + const pal = usePalette('default') + return ( + + + + + + + + {item.data.displayName ?? 'Feed name'} + + + {item.data.description ?? + 'THIS IS A FEED DESCRIPTION, IT WILL TELL YOU WHAT THE FEED IS ABOUT. THIS IS A COOL FEED ABOUT COOL PEOPLE.'} + + - - - {item.displayName ?? 'Feed name'} - - - {item.description ?? - 'THIS IS A FEED DESCRIPTION, IT WILL TELL YOU WHAT THE FEED IS ABOUT. THIS IS A COOL FEED ABOUT COOL PEOPLE.'} - + + {/* TODO: this feed is like by *3* people UserAvatars and others */} + + + + + + + + + Liked by 3 others + + +