Checkpoint, placeholder causing issues

This commit is contained in:
Eric Bailey
2024-06-25 21:13:53 -05:00
parent 5eac3277ac
commit 2a93fe4945
+56 -61
View File
@@ -1,6 +1,5 @@
import React from 'react' import React from 'react'
import {Pressable, StyleSheet, View} from 'react-native' import {Pressable, StyleSheet, View} from 'react-native'
import {AppBskyActorDefs} from '@atproto/api'
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
import {msg, Trans} from '@lingui/macro' import {msg, Trans} from '@lingui/macro'
import {useLingui} from '@lingui/react' import {useLingui} from '@lingui/react'
@@ -31,6 +30,7 @@ import {NoSavedFeedsOfAnyType} from '#/screens/Feeds/NoSavedFeedsOfAnyType'
import {atoms as a, useTheme} from '#/alf' import {atoms as a, useTheme} from '#/alf'
import * as FeedCard from '#/components/FeedCard' import * as FeedCard from '#/components/FeedCard'
import {FilterTimeline_Stroke2_Corner0_Rounded as FilterTimeline} from '#/components/icons/FilterTimeline' import {FilterTimeline_Stroke2_Corner0_Rounded as FilterTimeline} from '#/components/icons/FilterTimeline'
import * as ListCard from '#/components/ListCard'
import hairlineWidth = StyleSheet.hairlineWidth import hairlineWidth = StyleSheet.hairlineWidth
const HITSLOP_TOP = { const HITSLOP_TOP = {
@@ -70,19 +70,23 @@ export function SavedFeeds({}: Props) {
* Use optimistic data if exists and no error, otherwise fallback to remote * Use optimistic data if exists and no error, otherwise fallback to remote
* data * data
*/ */
const optimisticCurrentFeeds = const optimisticSavedFeeds: SavedFeedItem[] =
optimisticSavedFeedsResponse && !writeSavedFeedsError optimisticSavedFeedsResponse && !writeSavedFeedsError
? optimisticSavedFeedsResponse ? (optimisticSavedFeedsResponse
: savedFeeds?.feeds?.map(f => f.config) || [] .map(f => {
const pinnedFeeds = optimisticCurrentFeeds.filter(f => f.pinned) return savedFeeds?.feeds.find(sf => sf.config.id === f.id)
const unpinnedFeeds = optimisticCurrentFeeds.filter(f => !f.pinned) })
const noSavedFeedsOfAnyType = pinnedFeeds.length + unpinnedFeeds.length === 0 .filter(Boolean) as SavedFeedItem[])
const noFollowingFeed = : savedFeeds?.feeds?.map(f => f) || []
optimisticCurrentFeeds.every(f => f.type !== 'timeline') &&
!noSavedFeedsOfAnyType
const isSavedFeedsLoading = const isSavedFeedsLoading =
isSavedFeedsPlaceholder && !savedFeeds?.feeds.length isSavedFeedsPlaceholder && !savedFeeds?.feeds.length
const noSavedFeedsOfAnyType = optimisticSavedFeeds.length === 0
const noFollowingFeed =
optimisticSavedFeeds.every(f => f.type !== 'timeline') &&
!noSavedFeedsOfAnyType
const pinnedFeeds = optimisticSavedFeeds.filter(f => f.config.pinned)
const unpinnedFeeds = optimisticSavedFeeds.filter(f => !f.config.pinned)
const numPinnedFeedsPlaceholders = savedFeeds const numPinnedFeedsPlaceholders = savedFeeds
? Math.max(savedFeeds.counts.pinned, 3) ? Math.max(savedFeeds.counts.pinned, 3)
: 3 : 3
@@ -138,18 +142,16 @@ export function SavedFeeds({}: Props) {
)) ))
) : ( ) : (
<> <>
{savedFeeds && savedFeeds.feeds.length ? ( {pinnedFeeds.length ? (
savedFeeds.feeds pinnedFeeds.map(f => (
.filter(f => f.config.pinned) <ListItem
.map(f => ( key={f.key}
<ListItem feed={f}
key={f.key} overwriteSavedFeeds={overwriteSavedFeeds}
feed={f} resetSaveFeedsMutationState={resetSaveFeedsMutationState}
overwriteSavedFeeds={overwriteSavedFeeds} savedFeeds={optimisticSavedFeeds}
resetSaveFeedsMutationState={resetSaveFeedsMutationState} />
currentFeeds={optimisticCurrentFeeds} ))
/>
))
) : ( ) : (
<View <View
style={[ style={[
@@ -198,18 +200,16 @@ export function SavedFeeds({}: Props) {
)) ))
) : ( ) : (
<> <>
{savedFeeds && savedFeeds.feeds.length ? ( {unpinnedFeeds.length ? (
savedFeeds.feeds unpinnedFeeds.map(f => (
.filter(f => !f.config.pinned) <ListItem
.map(f => ( key={f.key}
<ListItem feed={f}
key={f.key} overwriteSavedFeeds={overwriteSavedFeeds}
feed={f} resetSaveFeedsMutationState={resetSaveFeedsMutationState}
overwriteSavedFeeds={overwriteSavedFeeds} savedFeeds={optimisticSavedFeeds}
resetSaveFeedsMutationState={resetSaveFeedsMutationState} />
currentFeeds={optimisticCurrentFeeds} ))
/>
))
) : ( ) : (
<View <View
style={[ style={[
@@ -249,12 +249,12 @@ export function SavedFeeds({}: Props) {
function ListItem({ function ListItem({
feed, feed,
currentFeeds, savedFeeds,
overwriteSavedFeeds, overwriteSavedFeeds,
resetSaveFeedsMutationState, resetSaveFeedsMutationState,
}: { }: {
feed: SavedFeedItem feed: SavedFeedItem
currentFeeds: AppBskyActorDefs.SavedFeed[] savedFeeds: SavedFeedItem[]
overwriteSavedFeeds: ReturnType< overwriteSavedFeeds: ReturnType<
typeof useOverwriteSavedFeedsMutation typeof useOverwriteSavedFeedsMutation
>['mutateAsync'] >['mutateAsync']
@@ -268,6 +268,7 @@ function ListItem({
const {isPending: isUpdatePending, mutateAsync: updateSavedFeeds} = const {isPending: isUpdatePending, mutateAsync: updateSavedFeeds} =
useUpdateSavedFeedsMutation() useUpdateSavedFeedsMutation()
const isPinned = feed.config.pinned const isPinned = feed.config.pinned
const currentFeedConfigs = savedFeeds.map(f => f.config)
const onTogglePinned = React.useCallback(async () => { const onTogglePinned = React.useCallback(async () => {
playHaptic() playHaptic()
@@ -290,8 +291,8 @@ function ListItem({
const onPressUp = React.useCallback(async () => { const onPressUp = React.useCallback(async () => {
if (!isPinned) return if (!isPinned) return
const nextFeeds = currentFeeds.slice() const nextFeeds = currentFeedConfigs.slice()
const ids = currentFeeds.map(f => f.id) const ids = currentFeedConfigs.map(f => f.id)
const index = ids.indexOf(feed.config.id) const index = ids.indexOf(feed.config.id)
const nextIndex = index - 1 const nextIndex = index - 1
@@ -311,13 +312,13 @@ function ListItem({
Toast.show(_(msg`There was an issue contacting the server`)) Toast.show(_(msg`There was an issue contacting the server`))
logger.error('Failed to set pinned feed order', {message: e}) logger.error('Failed to set pinned feed order', {message: e})
} }
}, [feed, isPinned, overwriteSavedFeeds, currentFeeds, _]) }, [feed, isPinned, overwriteSavedFeeds, currentFeedConfigs, _])
const onPressDown = React.useCallback(async () => { const onPressDown = React.useCallback(async () => {
if (!isPinned) return if (!isPinned) return
const nextFeeds = currentFeeds.slice() const nextFeeds = currentFeedConfigs.slice()
const ids = currentFeeds.map(f => f.id) const ids = currentFeedConfigs.map(f => f.id)
const index = ids.indexOf(feed.config.id) const index = ids.indexOf(feed.config.id)
const nextIndex = index + 1 const nextIndex = index + 1
@@ -337,7 +338,7 @@ function ListItem({
Toast.show(_(msg`There was an issue contacting the server`)) Toast.show(_(msg`There was an issue contacting the server`))
logger.error('Failed to set pinned feed order', {message: e}) logger.error('Failed to set pinned feed order', {message: e})
} }
}, [feed, isPinned, overwriteSavedFeeds, currentFeeds, _]) }, [feed, isPinned, overwriteSavedFeeds, currentFeedConfigs, _])
return ( return (
<View style={[styles.itemContainer, pal.border]}> <View style={[styles.itemContainer, pal.border]}>
@@ -346,41 +347,35 @@ function ListItem({
) : ( ) : (
<View style={[a.flex_1]}> <View style={[a.flex_1]}>
{feed.type === 'feed' ? ( {feed.type === 'feed' ? (
<FeedCard.Link view={feed.view} type="feed"> <FeedCard.Link view={feed.view}>
<View style={[a.py_md, a.pl_lg, a.pr_sm, a.flex_1]}> <View style={[a.py_md, a.pl_lg, a.pr_sm, a.flex_1]}>
<FeedCard.Outer> <FeedCard.Outer>
<FeedCard.Header> <FeedCard.Header>
<FeedCard.Avatar src={feed.view.avatar} /> <FeedCard.Avatar size={36} src={feed.view.avatar} />
<FeedCard.TitleAndByline <FeedCard.TitleAndByline
type="feed"
title={feed.view.displayName} title={feed.view.displayName}
creator={feed.view.creator} creator={feed.view.creator}
/> />
{!isPinned && ( {!isPinned && <FeedCard.SaveButton view={feed.view} />}
<FeedCard.Action uri={feed.view.uri} type="feed" />
)}
</FeedCard.Header> </FeedCard.Header>
</FeedCard.Outer> </FeedCard.Outer>
</View> </View>
</FeedCard.Link> </FeedCard.Link>
) : ( ) : (
<FeedCard.Link view={feed.view} type="list"> <ListCard.Link view={feed.view}>
<View style={[a.py_md, a.pl_lg, a.pr_sm, a.flex_1]}> <View style={[a.py_md, a.pl_lg, a.pr_sm, a.flex_1]}>
<FeedCard.Outer> <ListCard.Outer>
<FeedCard.Header> <ListCard.Header>
<FeedCard.Avatar src={feed.view.avatar} /> <ListCard.Avatar size={36} src={feed.view.avatar} />
<FeedCard.TitleAndByline <ListCard.TitleAndByline
type="list"
title={feed.view.name} title={feed.view.name}
creator={feed.view.creator} creator={feed.view.creator}
/> />
{!isPinned && ( {!isPinned && <ListCard.SaveButton view={feed.view} />}
<FeedCard.Action uri={feed.view.uri} type="list" /> </ListCard.Header>
)} </ListCard.Outer>
</FeedCard.Header>
</FeedCard.Outer>
</View> </View>
</FeedCard.Link> </ListCard.Link>
)} )}
</View> </View>
)} )}