Add shutdown message to for you feed (#3776)

This commit is contained in:
Paul Frazee 2024-05-10 21:57:21 -07:00 committed by GitHub
parent d0440d087e
commit 6f5b551bda
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 174 additions and 2 deletions

View file

@ -14,6 +14,7 @@ import {useLingui} from '@lingui/react'
import {useQueryClient} from '@tanstack/react-query'
import {FALLBACK_MARKER_POST} from '#/lib/api/feed/home'
import {KNOWN_SHUTDOWN_FEEDS} from '#/lib/constants'
import {logEvent} from '#/lib/statsig/statsig'
import {logger} from '#/logger'
import {isWeb} from '#/platform/detection'
@ -36,12 +37,14 @@ import {PostFeedLoadingPlaceholder} from '../util/LoadingPlaceholder'
import {LoadMoreRetryBtn} from '../util/LoadMoreRetryBtn'
import {DiscoverFallbackHeader} from './DiscoverFallbackHeader'
import {FeedErrorMessage} from './FeedErrorMessage'
import {FeedShutdownMsg} from './FeedShutdownMsg'
import {FeedSlice} from './FeedSlice'
const LOADING_ITEM = {_reactKey: '__loading__'}
const EMPTY_FEED_ITEM = {_reactKey: '__empty__'}
const ERROR_ITEM = {_reactKey: '__error__'}
const LOAD_MORE_ERROR_ITEM = {_reactKey: '__load_more_error__'}
const FEED_SHUTDOWN_MSG_ITEM = {_reactKey: '__feed_shutdown_msg_item__'}
// DISABLED need to check if this is causing random feed refreshes -prf
// const REFRESH_AFTER = STALE.HOURS.ONE
@ -96,7 +99,7 @@ let Feed = ({
const [isPTRing, setIsPTRing] = React.useState(false)
const checkForNewRef = React.useRef<(() => void) | null>(null)
const lastFetchRef = React.useRef<number>(Date.now())
const feedType = feed.split('|')[0]
const [feedType, feedUri] = feed.split('|')
const opts = React.useMemo(
() => ({enabled, ignoreFilterFor}),
@ -196,6 +199,9 @@ let Feed = ({
const feedItems = React.useMemo(() => {
let arr: any[] = []
if (KNOWN_SHUTDOWN_FEEDS.includes(feedUri)) {
arr = arr.concat([FEED_SHUTDOWN_MSG_ITEM])
}
if (isFetched) {
if (isError && isEmpty) {
arr = arr.concat([ERROR_ITEM])
@ -213,7 +219,7 @@ let Feed = ({
arr.push(LOADING_ITEM)
}
return arr
}, [isFetched, isError, isEmpty, data])
}, [isFetched, isError, isEmpty, data, feedUri])
// events
// =
@ -296,6 +302,8 @@ let Feed = ({
)
} else if (item === LOADING_ITEM) {
return <PostFeedLoadingPlaceholder />
} else if (item === FEED_SHUTDOWN_MSG_ITEM) {
return <FeedShutdownMsg feedUri={feedUri} />
} else if (item.rootUri === FALLBACK_MARKER_POST.post.uri) {
// HACK
// tell the user we fell back to discover
@ -307,6 +315,7 @@ let Feed = ({
},
[
feed,
feedUri,
error,
onPressTryAgain,
onPressRetryLoadMore,