Skip to content

Commit 0fd4bbc

Browse files
committed
faet: Only reload the feed in the shorts page.
1 parent 10b70c2 commit 0fd4bbc

5 files changed

Lines changed: 37 additions & 7 deletions

File tree

.changeset/weak-flowers-dream.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"xlog": patch
3+
---
4+
5+
Only reload the feed in the shorts page.

src/components/FeedList/useFeedList.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,17 @@ export interface Props {
3232
characterId?: number
3333
ListHeaderComponent?: React.ReactNode
3434
visibility?: PageVisibilityEnum
35+
updateFeedAfterPost?: boolean
3536
}
3637

3738
export const useFeedList = <T extends {}>(props: Props & T) => {
38-
const { ListHeaderComponent, visibility, handle, type, searchKeyword, contentContainerStyle = {}, tags = [], topic, daysInterval = 7, onScroll, characterId, ...restProps } = props;
39+
const { ListHeaderComponent, updateFeedAfterPost = false, visibility, handle, type, searchKeyword, contentContainerStyle = {}, tags = [], topic, daysInterval = 7, onScroll, characterId, ...restProps } = props;
3940
const { width } = useWindowDimensions();
4041
const { feedList, feed } = useFeedData(props);
4142
const [isRefetching, setIsRefetching] = useState<boolean>(false);
4243
const listRef = useRef<MasonryFlashListRef<ExpandedNote>>(null);
4344
const { isDarkMode } = useThemeStore();
44-
const { isProcessing } = usePostIndicatorStore();
45+
const { subscribe } = usePostIndicatorStore();
4546
const i18nC = useTranslation("common");
4647

4748
useEffect(() => {
@@ -75,10 +76,20 @@ export const useFeedList = <T extends {}>(props: Props & T) => {
7576
}, [feed.refetch, isRefetching]);
7677

7778
useEffect(() => {
78-
if (!isProcessing) {
79-
onRefetch();
79+
if (!updateFeedAfterPost) {
80+
return;
8081
}
81-
}, [isProcessing]);
82+
83+
const unsubscribe = subscribe((isProcessing) => {
84+
if (!isProcessing) {
85+
onRefetch();
86+
}
87+
});
88+
89+
return () => {
90+
unsubscribe();
91+
};
92+
}, [subscribe, updateFeedAfterPost]);
8293

8394
return useMemo<MasonryFlashListProps<any>>(() => ({
8495
data: feedList,
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1-
import { useContext } from "react";
1+
import { useCallback, useContext } from "react";
22

33
import { PostIndicatorContext } from "@/context/post-indicator-context";
4+
import { postIndicatorSubscribers } from "@/providers/post-indicator-provider";
45

56
export const usePostIndicatorStore = () => {
6-
return useContext(PostIndicatorContext);
7+
const { isProcessing, addPostTask } = useContext(PostIndicatorContext);
8+
9+
const subscribe = useCallback((callback) => {
10+
postIndicatorSubscribers.add(callback);
11+
return () => {
12+
postIndicatorSubscribers.delete(callback);
13+
};
14+
}, []);
15+
16+
return { isProcessing, addPostTask, subscribe };
717
};

src/pages/Feed/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export const FeedPage: FC<NativeStackScreenProps<HomeBottomTabsParamList, "Feed"
9494
<MasonryFeedList
9595
daysInterval={daysInterval}
9696
type={currentFeedType}
97+
updateFeedAfterPost={isShorts}
9798
ListHeaderComponent={!isShorts && <ShortsExplorerBanner/>}
9899
onScroll={onScroll}
99100
contentContainerStyle={{

src/providers/post-indicator-provider.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ interface PostIndicatorProviderProps extends React.PropsWithChildren {
2525

2626
}
2727

28+
export const postIndicatorSubscribers: Set<(isProcessing: boolean) => void> = new Set();
29+
2830
export function PostIndicatorProvider({ children }: PostIndicatorProviderProps) {
2931
const [task, setTask] = React.useState<TaskType>(null);
3032
const [isProcessing, setIsProcessing] = React.useState(false);
@@ -35,6 +37,7 @@ export function PostIndicatorProvider({ children }: PostIndicatorProviderProps)
3537

3638
const onPublish = React.useCallback(() => {
3739
setIsProcessing(false);
40+
postIndicatorSubscribers.forEach(callback => callback(false));
3841
}, []);
3942

4043
const addPostTask = React.useCallback((params: TaskType) => {

0 commit comments

Comments
 (0)