Skip to content

Commit 2cf3d7f

Browse files
authored
Merge pull request #286 from Crossbell-Box/develop
Develop
2 parents 2f92a5d + 0fd4bbc commit 2cf3d7f

8 files changed

Lines changed: 48 additions & 15 deletions

File tree

.changeset/five-cows-talk.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+
Hide the splash screen after the navigation is rendered.

.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/navigation/root.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import React from "react";
1+
import React, { useEffect } from "react";
22
import { useTranslation } from "react-i18next";
33
import { useSafeAreaInsets } from "react-native-safe-area-context";
44

55
import { HeaderBackButton } from "@react-navigation/elements";
66
import { createNativeStackNavigator } from "@react-navigation/native-stack";
7+
import * as SplashScreen from "expo-splash-screen";
78

89
import { CharacterListPage } from "@/pages/CharacterList";
910
import { ClaimCSBPage } from "@/pages/ClaimCSB";
@@ -34,6 +35,10 @@ export const RootNavigator = () => {
3435
const { bottom } = useSafeAreaInsets();
3536
const i18n = useTranslation("common");
3637

38+
useEffect(() => {
39+
SplashScreen.hideAsync();
40+
}, []);
41+
3742
return (
3843
<RootStack.Navigator initialRouteName="Home">
3944
{/* Without header */}

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) => {

src/providers/preload-provider.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { type FC, type PropsWithChildren, useEffect } from "react";
22

33
import { useFonts } from "expo-font";
4-
import * as SplashScreen from "expo-splash-screen";
54

65
export const PreloadProvider: FC<PropsWithChildren<{}>> = ({ children }) => {
76
const [fontsLoadingReady] = useFonts({
@@ -13,12 +12,6 @@ export const PreloadProvider: FC<PropsWithChildren<{}>> = ({ children }) => {
1312

1413
const allReady = fontsLoadingReady;
1514

16-
useEffect(() => {
17-
if (allReady) {
18-
SplashScreen.hideAsync();
19-
}
20-
}, [allReady]);
21-
2215
if (!allReady)
2316
return null;
2417

0 commit comments

Comments
 (0)