Shadow refactoring and improvements (#1959)

* Make shadow a type-only concept

* Prevent unnecessary init state recalc

* Use derived state instead of effects

* Batch emitter updates

* Use object first seen time instead of dataUpdatedAt

* Stop threading dataUpdatedAt through

* Use same value consistently
This commit is contained in:
dan 2023-11-21 22:42:30 +00:00 committed by GitHub
parent f18b9b32b0
commit 4c4ba553bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 115 additions and 203 deletions

View file

@ -40,7 +40,6 @@ export const ModerationBlockedAccounts = withAuthRequired(
const [isPTRing, setIsPTRing] = React.useState(false)
const {
data,
dataUpdatedAt,
isFetching,
isError,
error,
@ -95,7 +94,6 @@ export const ModerationBlockedAccounts = withAuthRequired(
testID={`blockedAccount-${index}`}
key={item.did}
profile={item}
dataUpdatedAt={dataUpdatedAt}
/>
)
return (

View file

@ -40,7 +40,6 @@ export const ModerationMutedAccounts = withAuthRequired(
const [isPTRing, setIsPTRing] = React.useState(false)
const {
data,
dataUpdatedAt,
isFetching,
isError,
error,
@ -95,7 +94,6 @@ export const ModerationMutedAccounts = withAuthRequired(
testID={`mutedAccount-${index}`}
key={item.did}
profile={item}
dataUpdatedAt={dataUpdatedAt}
/>
)
return (

View file

@ -57,7 +57,6 @@ export const ProfileScreen = withAuthRequired(
} = useResolveDidQuery(name)
const {
data: profile,
dataUpdatedAt,
error: profileError,
refetch: refetchProfile,
isFetching: isFetchingProfile,
@ -100,7 +99,6 @@ export const ProfileScreen = withAuthRequired(
return (
<ProfileScreenLoaded
profile={profile}
dataUpdatedAt={dataUpdatedAt}
moderationOpts={moderationOpts}
hideBackButton={!!route.params.hideBackButton}
/>
@ -125,16 +123,14 @@ export const ProfileScreen = withAuthRequired(
function ProfileScreenLoaded({
profile: profileUnshadowed,
dataUpdatedAt,
moderationOpts,
hideBackButton,
}: {
profile: AppBskyActorDefs.ProfileViewDetailed
dataUpdatedAt: number
moderationOpts: ModerationOpts
hideBackButton: boolean
}) {
const profile = useProfileShadow(profileUnshadowed, dataUpdatedAt)
const profile = useProfileShadow(profileUnshadowed)
const {currentAccount} = useSession()
const setMinimalShellMode = useSetMinimalShellMode()
const {openComposer} = useComposerControls()

View file

@ -111,7 +111,6 @@ function EmptyState({message, error}: {message: string; error?: string}) {
function SearchScreenSuggestedFollows() {
const pal = usePalette('default')
const {currentAccount} = useSession()
const [dataUpdatedAt, setDataUpdatedAt] = React.useState(0)
const [suggestions, setSuggestions] = React.useState<
AppBskyActorDefs.ProfileViewBasic[]
>([])
@ -141,7 +140,6 @@ function SearchScreenSuggestedFollows() {
)
setSuggestions(Array.from(friendsOfFriends.values()))
setDataUpdatedAt(Date.now())
}
try {
@ -151,23 +149,12 @@ function SearchScreenSuggestedFollows() {
error: e,
})
}
}, [
currentAccount,
setSuggestions,
setDataUpdatedAt,
getSuggestedFollowsByActor,
])
}, [currentAccount, setSuggestions, getSuggestedFollowsByActor])
return suggestions.length ? (
<FlatList
data={suggestions}
renderItem={({item}) => (
<ProfileCardWithFollowBtn
profile={item}
noBg
dataUpdatedAt={dataUpdatedAt}
/>
)}
renderItem={({item}) => <ProfileCardWithFollowBtn profile={item} noBg />}
keyExtractor={item => item.did}
// @ts-ignore web only -prf
desktopFixedHeight
@ -205,7 +192,6 @@ function SearchScreenPostResults({query}: {query: string}) {
fetchNextPage,
isFetchingNextPage,
hasNextPage,
dataUpdatedAt,
} = useSearchPostsQuery({query})
const onPullToRefresh = React.useCallback(async () => {
@ -258,7 +244,7 @@ function SearchScreenPostResults({query}: {query: string}) {
data={items}
renderItem={({item}) => {
if (item.type === 'post') {
return <Post post={item.post} dataUpdatedAt={dataUpdatedAt} />
return <Post post={item.post} />
} else {
return <Loader />
}
@ -291,7 +277,6 @@ function SearchScreenPostResults({query}: {query: string}) {
function SearchScreenUserResults({query}: {query: string}) {
const {_} = useLingui()
const [isFetched, setIsFetched] = React.useState(false)
const [dataUpdatedAt, setDataUpdatedAt] = React.useState(0)
const [results, setResults] = React.useState<
AppBskyActorDefs.ProfileViewBasic[]
>([])
@ -302,7 +287,6 @@ function SearchScreenUserResults({query}: {query: string}) {
const searchResults = await search({query, limit: 30})
if (searchResults) {
setDataUpdatedAt(Date.now())
setResults(results)
setIsFetched(true)
}
@ -314,7 +298,7 @@ function SearchScreenUserResults({query}: {query: string}) {
setResults([])
setIsFetched(false)
}
}, [query, setDataUpdatedAt, search, results])
}, [query, search, results])
return isFetched ? (
<>
@ -322,11 +306,7 @@ function SearchScreenUserResults({query}: {query: string}) {
<FlatList
data={results}
renderItem={({item}) => (
<ProfileCardWithFollowBtn
profile={item}
noBg
dataUpdatedAt={dataUpdatedAt}
/>
<ProfileCardWithFollowBtn profile={item} noBg />
)}
keyExtractor={item => item.did}
// @ts-ignore web only -prf