Fix flashes and jumps when opening profile (#2815)
* Don't reset the tree when profile loads fully * Give avatars a background color like placeholders * Prevent jumps due to rich text resolving * Rm log * Rm unused
This commit is contained in:
parent
0d00c7d851
commit
d36b91fe67
6 changed files with 141 additions and 135 deletions
24
src/state/cache/profile-shadow.ts
vendored
24
src/state/cache/profile-shadow.ts
vendored
|
@ -22,15 +22,15 @@ export interface ProfileShadow {
|
|||
blockingUri: string | undefined
|
||||
}
|
||||
|
||||
type ProfileView =
|
||||
| AppBskyActorDefs.ProfileView
|
||||
| AppBskyActorDefs.ProfileViewBasic
|
||||
| AppBskyActorDefs.ProfileViewDetailed
|
||||
|
||||
const shadows: WeakMap<ProfileView, Partial<ProfileShadow>> = new WeakMap()
|
||||
const shadows: WeakMap<
|
||||
AppBskyActorDefs.ProfileView,
|
||||
Partial<ProfileShadow>
|
||||
> = new WeakMap()
|
||||
const emitter = new EventEmitter()
|
||||
|
||||
export function useProfileShadow(profile: ProfileView): Shadow<ProfileView> {
|
||||
export function useProfileShadow<
|
||||
TProfileView extends AppBskyActorDefs.ProfileView,
|
||||
>(profile: TProfileView): Shadow<TProfileView> {
|
||||
const [shadow, setShadow] = useState(() => shadows.get(profile))
|
||||
const [prevPost, setPrevPost] = useState(profile)
|
||||
if (profile !== prevPost) {
|
||||
|
@ -70,10 +70,10 @@ export function updateProfileShadow(
|
|||
})
|
||||
}
|
||||
|
||||
function mergeShadow(
|
||||
profile: ProfileView,
|
||||
function mergeShadow<TProfileView extends AppBskyActorDefs.ProfileView>(
|
||||
profile: TProfileView,
|
||||
shadow: Partial<ProfileShadow>,
|
||||
): Shadow<ProfileView> {
|
||||
): Shadow<TProfileView> {
|
||||
return castAsShadow({
|
||||
...profile,
|
||||
viewer: {
|
||||
|
@ -89,7 +89,9 @@ function mergeShadow(
|
|||
})
|
||||
}
|
||||
|
||||
function* findProfilesInCache(did: string): Generator<ProfileView, void> {
|
||||
function* findProfilesInCache(
|
||||
did: string,
|
||||
): Generator<AppBskyActorDefs.ProfileView, void> {
|
||||
yield* findAllProfilesInListMembersQueryData(queryClient, did)
|
||||
yield* findAllProfilesInMyBlockedAccountsQueryData(queryClient, did)
|
||||
yield* findAllProfilesInMyMutedAccountsQueryData(queryClient, did)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue