view all saved algos in settings
parent
047024a5ac
commit
8948118d5c
|
@ -1,8 +1,7 @@
|
||||||
import {AppBskyFeedDefs} from '@atproto/api'
|
import {AppBskyFeedDefs} from '@atproto/api'
|
||||||
import {makeAutoObservable, makeObservable} from 'mobx'
|
import {makeAutoObservable} from 'mobx'
|
||||||
import {RootStoreModel} from 'state/models/root-store'
|
import {RootStoreModel} from 'state/models/root-store'
|
||||||
|
|
||||||
// algoitemmodel implemented in mobx
|
|
||||||
export class AlgoItemModel {
|
export class AlgoItemModel {
|
||||||
// data
|
// data
|
||||||
data: AppBskyFeedDefs.GeneratorView
|
data: AppBskyFeedDefs.GeneratorView
|
||||||
|
@ -21,6 +20,8 @@ export class AlgoItemModel {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// local actions
|
||||||
|
// =
|
||||||
set toggleSaved(value: boolean) {
|
set toggleSaved(value: boolean) {
|
||||||
console.log('toggleSaved', this.data.viewer)
|
console.log('toggleSaved', this.data.viewer)
|
||||||
if (this.data.viewer) {
|
if (this.data.viewer) {
|
||||||
|
@ -28,12 +29,12 @@ export class AlgoItemModel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public apis
|
||||||
|
// =
|
||||||
async save() {
|
async save() {
|
||||||
try {
|
try {
|
||||||
// runInAction(() => {
|
|
||||||
this.toggleSaved = true
|
this.toggleSaved = true
|
||||||
// })
|
await this.rootStore.agent.app.bsky.feed.saveFeed({
|
||||||
const res = await this.rootStore.agent.app.bsky.feed.saveFeed({
|
|
||||||
feed: this.data.uri,
|
feed: this.data.uri,
|
||||||
})
|
})
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
@ -43,10 +44,8 @@ export class AlgoItemModel {
|
||||||
|
|
||||||
async unsave() {
|
async unsave() {
|
||||||
try {
|
try {
|
||||||
// runInAction(() => {
|
|
||||||
this.toggleSaved = false
|
this.toggleSaved = false
|
||||||
// })
|
await this.rootStore.agent.app.bsky.feed.unsaveFeed({
|
||||||
const res = await this.rootStore.agent.app.bsky.feed.unsaveFeed({
|
|
||||||
feed: this.data.uri,
|
feed: this.data.uri,
|
||||||
})
|
})
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
|
|
@ -110,7 +110,7 @@ export class SavedFeedsModel {
|
||||||
this.loadMoreCursor = res.data.cursor
|
this.loadMoreCursor = res.data.cursor
|
||||||
this.hasMore = !!this.loadMoreCursor
|
this.hasMore = !!this.loadMoreCursor
|
||||||
for (const f of res.data.feeds) {
|
for (const f of res.data.feeds) {
|
||||||
this.feeds.push(new AlgoItemModel(f))
|
this.feeds.push(new AlgoItemModel(this.rootStore, f))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import {PostsFeedModel} from './feeds/posts'
|
||||||
import {NotificationsFeedModel} from './feeds/notifications'
|
import {NotificationsFeedModel} from './feeds/notifications'
|
||||||
import {MyFollowsCache} from './cache/my-follows'
|
import {MyFollowsCache} from './cache/my-follows'
|
||||||
import {isObj, hasProp} from 'lib/type-guards'
|
import {isObj, hasProp} from 'lib/type-guards'
|
||||||
|
import {SavedFeedsModel} from './feeds/algo/saved'
|
||||||
|
|
||||||
const PROFILE_UPDATE_INTERVAL = 10 * 60 * 1e3 // 10min
|
const PROFILE_UPDATE_INTERVAL = 10 * 60 * 1e3 // 10min
|
||||||
const NOTIFS_UPDATE_INTERVAL = 30 * 1e3 // 30sec
|
const NOTIFS_UPDATE_INTERVAL = 30 * 1e3 // 30sec
|
||||||
|
@ -21,6 +22,7 @@ export class MeModel {
|
||||||
followsCount: number | undefined
|
followsCount: number | undefined
|
||||||
followersCount: number | undefined
|
followersCount: number | undefined
|
||||||
mainFeed: PostsFeedModel
|
mainFeed: PostsFeedModel
|
||||||
|
savedFeeds: SavedFeedsModel
|
||||||
notifications: NotificationsFeedModel
|
notifications: NotificationsFeedModel
|
||||||
follows: MyFollowsCache
|
follows: MyFollowsCache
|
||||||
invites: ComAtprotoServerDefs.InviteCode[] = []
|
invites: ComAtprotoServerDefs.InviteCode[] = []
|
||||||
|
@ -43,12 +45,14 @@ export class MeModel {
|
||||||
})
|
})
|
||||||
this.notifications = new NotificationsFeedModel(this.rootStore)
|
this.notifications = new NotificationsFeedModel(this.rootStore)
|
||||||
this.follows = new MyFollowsCache(this.rootStore)
|
this.follows = new MyFollowsCache(this.rootStore)
|
||||||
|
this.savedFeeds = new SavedFeedsModel(this.rootStore)
|
||||||
}
|
}
|
||||||
|
|
||||||
clear() {
|
clear() {
|
||||||
this.mainFeed.clear()
|
this.mainFeed.clear()
|
||||||
this.notifications.clear()
|
this.notifications.clear()
|
||||||
this.follows.clear()
|
this.follows.clear()
|
||||||
|
this.savedFeeds.clear()
|
||||||
this.did = ''
|
this.did = ''
|
||||||
this.handle = ''
|
this.handle = ''
|
||||||
this.displayName = ''
|
this.displayName = ''
|
||||||
|
@ -110,6 +114,7 @@ export class MeModel {
|
||||||
/* dont await */ this.notifications.setup().catch(e => {
|
/* dont await */ this.notifications.setup().catch(e => {
|
||||||
this.rootStore.log.error('Failed to setup notifications model', e)
|
this.rootStore.log.error('Failed to setup notifications model', e)
|
||||||
})
|
})
|
||||||
|
/* dont await */ this.savedFeeds.refresh()
|
||||||
this.rootStore.emitSessionLoaded()
|
this.rootStore.emitSessionLoaded()
|
||||||
await this.fetchInviteCodes()
|
await this.fetchInviteCodes()
|
||||||
await this.fetchAppPasswords()
|
await this.fetchAppPasswords()
|
||||||
|
|
|
@ -1,27 +1,97 @@
|
||||||
|
import React, {useCallback, useMemo} from 'react'
|
||||||
|
import {
|
||||||
|
RefreshControl,
|
||||||
|
StyleSheet,
|
||||||
|
View,
|
||||||
|
FlatList,
|
||||||
|
ActivityIndicator,
|
||||||
|
} from 'react-native'
|
||||||
|
import {useFocusEffect} from '@react-navigation/native'
|
||||||
import {NativeStackScreenProps} from '@react-navigation/native-stack'
|
import {NativeStackScreenProps} from '@react-navigation/native-stack'
|
||||||
|
import {useAnalytics} from 'lib/analytics'
|
||||||
import {usePalette} from 'lib/hooks/usePalette'
|
import {usePalette} from 'lib/hooks/usePalette'
|
||||||
import {CommonNavigatorParams} from 'lib/routes/types'
|
import {CommonNavigatorParams} from 'lib/routes/types'
|
||||||
import {observer} from 'mobx-react-lite'
|
import {observer} from 'mobx-react-lite'
|
||||||
import React from 'react'
|
import {useStores} from 'state/index'
|
||||||
import {StyleSheet, View} from 'react-native'
|
import {SavedFeedsModel} from 'state/models/feeds/algo/saved'
|
||||||
|
import AlgoItem from 'view/com/algos/AlgoItem'
|
||||||
import {withAuthRequired} from 'view/com/auth/withAuthRequired'
|
import {withAuthRequired} from 'view/com/auth/withAuthRequired'
|
||||||
import {ViewHeader} from 'view/com/util/ViewHeader'
|
import {ViewHeader} from 'view/com/util/ViewHeader'
|
||||||
|
import {CenteredView} from 'view/com/util/Views'
|
||||||
import {Text} from 'view/com/util/text/Text'
|
import {Text} from 'view/com/util/text/Text'
|
||||||
|
import {isDesktopWeb} from 'platform/detection'
|
||||||
|
import {s} from 'lib/styles'
|
||||||
|
|
||||||
type Props = NativeStackScreenProps<CommonNavigatorParams, 'CustomAlgorithms'>
|
type Props = NativeStackScreenProps<CommonNavigatorParams, 'CustomAlgorithms'>
|
||||||
|
|
||||||
const CustomAlgorithms = withAuthRequired(
|
const CustomAlgorithms = withAuthRequired(
|
||||||
observer((props: Props) => {
|
observer(({}: Props) => {
|
||||||
const pal = usePalette('default')
|
const pal = usePalette('default')
|
||||||
|
const rootStore = useStores()
|
||||||
|
const {screen} = useAnalytics()
|
||||||
|
|
||||||
|
const savedFeeds = useMemo(
|
||||||
|
() => new SavedFeedsModel(rootStore),
|
||||||
|
[rootStore],
|
||||||
|
)
|
||||||
|
|
||||||
|
useFocusEffect(
|
||||||
|
useCallback(() => {
|
||||||
|
screen('SavedFeeds')
|
||||||
|
rootStore.shell.setMinimalShellMode(false)
|
||||||
|
savedFeeds.refresh()
|
||||||
|
}, [screen, rootStore, savedFeeds]),
|
||||||
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View>
|
<CenteredView style={{flex: 1}}>
|
||||||
<ViewHeader title="Custom Algorithms" showOnDesktop />
|
<ViewHeader title="Custom Algorithms" showOnDesktop />
|
||||||
<Text>CustomAlgorithms</Text>
|
{!savedFeeds.hasContent || savedFeeds.isEmpty ? (
|
||||||
</View>
|
<View style={[pal.border, !isDesktopWeb && s.flex1]}>
|
||||||
|
<View style={[pal.viewLight]}>
|
||||||
|
<Text type="lg" style={[pal.text]}>
|
||||||
|
You don't have any saved feeds. To save a feed, click the save
|
||||||
|
button when a custom feed or algorithm shows up.
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
) : (
|
||||||
|
<FlatList
|
||||||
|
style={[!isDesktopWeb && s.flex1]}
|
||||||
|
data={savedFeeds.feeds}
|
||||||
|
keyExtractor={item => item.data.uri}
|
||||||
|
refreshControl={
|
||||||
|
<RefreshControl
|
||||||
|
refreshing={savedFeeds.isRefreshing}
|
||||||
|
onRefresh={() => savedFeeds.refresh()}
|
||||||
|
tintColor={pal.colors.text}
|
||||||
|
titleColor={pal.colors.text}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
onEndReached={() => savedFeeds.loadMore()}
|
||||||
|
renderItem={({item}) => (
|
||||||
|
<AlgoItem key={item.data.uri} item={item} />
|
||||||
|
)}
|
||||||
|
initialNumToRender={15}
|
||||||
|
ListFooterComponent={() => (
|
||||||
|
<View style={styles.footer}>
|
||||||
|
{savedFeeds.isLoading && <ActivityIndicator />}
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
extraData={savedFeeds.isLoading}
|
||||||
|
// @ts-ignore our .web version only -prf
|
||||||
|
desktopFixedHeight
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</CenteredView>
|
||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
export default CustomAlgorithms
|
export default CustomAlgorithms
|
||||||
|
|
||||||
const styles = StyleSheet.create({})
|
const styles = StyleSheet.create({
|
||||||
|
footer: {
|
||||||
|
paddingVertical: 20,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
|
@ -97,7 +97,7 @@ export const MutedAccounts = withAuthRequired(
|
||||||
<FlatList
|
<FlatList
|
||||||
style={[!isDesktopWeb && styles.flex1]}
|
style={[!isDesktopWeb && styles.flex1]}
|
||||||
data={mutedAccounts.mutes}
|
data={mutedAccounts.mutes}
|
||||||
keyExtractor={(item: ActorDefs.ProfileView) => item.did}
|
keyExtractor={item => item.did}
|
||||||
refreshControl={
|
refreshControl={
|
||||||
<RefreshControl
|
<RefreshControl
|
||||||
refreshing={mutedAccounts.isRefreshing}
|
refreshing={mutedAccounts.isRefreshing}
|
||||||
|
|
Loading…
Reference in New Issue