refactor: streamline post sync, fix image gallery, and clean up chat screen
- **Post sync optimization**: Clear store immediately when params change to prevent flashing old posts; replace instead of merge on refresh - **ImageGallery fix**: Use idempotent download option, migrate to Asset.create() API, fix Android file path requirement, ensure proper cleanup - **UserProfileScreen**: Add ImageGallery for post image viewing with consistent implementation - **SearchScreen**: Add entrance animation and empty state - **ChatScreen**: Remove unused state variables (lastSeq, firstSeq, isProgrammaticScrollRef) and dead imports
This commit is contained in:
@@ -236,6 +236,14 @@ export function useDifferentialPosts<T extends PostIdentifier = Post>(
|
||||
const currentState = usePostListStore.getState().getPostsState(listKey);
|
||||
syncFromStore(currentState);
|
||||
|
||||
// listKey 切换时,如果目标列表在 store 中还没有有效数据(首次访问),
|
||||
// 立即进入 loading 态,避免先渲染空列表再切到 loading 造成闪烁。
|
||||
// syncFromStore 会用 store 的 isLoading 覆盖,因此在其之后补设。
|
||||
// 如果已有数据(曾访问过),则保留旧数据,由后续 fetch 静默刷新。
|
||||
if (!currentState.posts || currentState.posts.length === 0) {
|
||||
setLoading(true);
|
||||
}
|
||||
|
||||
const unsubscribe = usePostListStore.subscribe(state => {
|
||||
const postsState = state.postsStateMap.get(listKey);
|
||||
if (postsState) syncFromStore(postsState);
|
||||
@@ -277,6 +285,18 @@ export function useDifferentialPosts<T extends PostIdentifier = Post>(
|
||||
const reset = useCallback(() => {
|
||||
calculatorRef.current?.reset();
|
||||
batcherRef.current?.clearPending();
|
||||
// 同步清空 store 中对应 listKey 的数据,避免 subscribe 回调
|
||||
// 在切换 listKey 时把上一个 key 的残留数据重新同步回本地造成闪烁
|
||||
usePostListStore.getState().updatePostsState(listKey, {
|
||||
posts: [],
|
||||
cursor: null,
|
||||
currentPage: 1,
|
||||
hasMore: true,
|
||||
isLoading: false,
|
||||
isRefreshing: false,
|
||||
error: null,
|
||||
lastParams: undefined,
|
||||
});
|
||||
setPosts([]);
|
||||
setLoading(false);
|
||||
setRefreshing(false);
|
||||
@@ -284,7 +304,7 @@ export function useDifferentialPosts<T extends PostIdentifier = Post>(
|
||||
setHasMore(true);
|
||||
previousPostsRef.current = [];
|
||||
setDiffUpdates({ addedCount: 0, updatedCount: 0, deletedCount: 0, lastUpdateTime: 0 });
|
||||
}, []);
|
||||
}, [listKey]);
|
||||
|
||||
const forceUpdate = useCallback((newPosts: T[]) => {
|
||||
setPosts(newPosts);
|
||||
|
||||
Reference in New Issue
Block a user