Skip to content

Commit

Permalink
Merge pull request #286 from Crossbell-Box/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
dohooo authored Dec 16, 2023
2 parents 2f92a5d + 0fd4bbc commit 2cf3d7f
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/five-cows-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"xlog": patch
---

Hide the splash screen after the navigation is rendered.
5 changes: 5 additions & 0 deletions .changeset/weak-flowers-dream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"xlog": patch
---

Only reload the feed in the shorts page.
21 changes: 16 additions & 5 deletions src/components/FeedList/useFeedList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,17 @@ export interface Props {
characterId?: number
ListHeaderComponent?: React.ReactNode
visibility?: PageVisibilityEnum
updateFeedAfterPost?: boolean
}

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

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

useEffect(() => {
if (!isProcessing) {
onRefetch();
if (!updateFeedAfterPost) {
return;
}
}, [isProcessing]);

const unsubscribe = subscribe((isProcessing) => {
if (!isProcessing) {
onRefetch();
}
});

return () => {
unsubscribe();
};
}, [subscribe, updateFeedAfterPost]);

return useMemo<MasonryFlashListProps<any>>(() => ({
data: feedList,
Expand Down
14 changes: 12 additions & 2 deletions src/hooks/use-post-indicator-store.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import { useContext } from "react";
import { useCallback, useContext } from "react";

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

export const usePostIndicatorStore = () => {
return useContext(PostIndicatorContext);
const { isProcessing, addPostTask } = useContext(PostIndicatorContext);

const subscribe = useCallback((callback) => {
postIndicatorSubscribers.add(callback);
return () => {
postIndicatorSubscribers.delete(callback);
};
}, []);

return { isProcessing, addPostTask, subscribe };
};
7 changes: 6 additions & 1 deletion src/navigation/root.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React from "react";
import React, { useEffect } from "react";
import { useTranslation } from "react-i18next";
import { useSafeAreaInsets } from "react-native-safe-area-context";

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

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

useEffect(() => {
SplashScreen.hideAsync();
}, []);

return (
<RootStack.Navigator initialRouteName="Home">
{/* Without header */}
Expand Down
1 change: 1 addition & 0 deletions src/pages/Feed/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export const FeedPage: FC<NativeStackScreenProps<HomeBottomTabsParamList, "Feed"
<MasonryFeedList
daysInterval={daysInterval}
type={currentFeedType}
updateFeedAfterPost={isShorts}
ListHeaderComponent={!isShorts && <ShortsExplorerBanner/>}
onScroll={onScroll}
contentContainerStyle={{
Expand Down
3 changes: 3 additions & 0 deletions src/providers/post-indicator-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ interface PostIndicatorProviderProps extends React.PropsWithChildren {

}

export const postIndicatorSubscribers: Set<(isProcessing: boolean) => void> = new Set();

export function PostIndicatorProvider({ children }: PostIndicatorProviderProps) {
const [task, setTask] = React.useState<TaskType>(null);
const [isProcessing, setIsProcessing] = React.useState(false);
Expand All @@ -35,6 +37,7 @@ export function PostIndicatorProvider({ children }: PostIndicatorProviderProps)

const onPublish = React.useCallback(() => {
setIsProcessing(false);
postIndicatorSubscribers.forEach(callback => callback(false));
}, []);

const addPostTask = React.useCallback((params: TaskType) => {
Expand Down
7 changes: 0 additions & 7 deletions src/providers/preload-provider.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { type FC, type PropsWithChildren, useEffect } from "react";

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

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

const allReady = fontsLoadingReady;

useEffect(() => {
if (allReady) {
SplashScreen.hideAsync();
}
}, [allReady]);

if (!allReady)
return null;

Expand Down

0 comments on commit 2cf3d7f

Please sign in to comment.