Create a refresh controller for the home page on android

This commit is contained in:
Zoe Roux 2024-01-10 14:09:07 +01:00
parent c5c527ec10
commit 721d9937e0
2 changed files with 28 additions and 4 deletions

View File

@ -137,7 +137,7 @@ export const InfiniteFetchList = <Data, Props, _, Kind extends number | string>(
estimatedItemSize={size}
onEndReached={fetchMore ? fetchNextPage : undefined}
onEndReachedThreshold={0.5}
onRefresh={refetch}
onRefresh={layout.layout !== "horizontal" ? refetch : null}
refreshing={isRefetching}
ItemSeparatorComponent={divider === true ? HR : divider || null}
ListHeaderComponent={Header}

View File

@ -18,20 +18,44 @@
* along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
*/
import { Genre, QueryPage } from "@kyoo/models";
import { Genre, QueryPage, toQueryKey } from "@kyoo/models";
import { Fetch } from "../fetch";
import { Header } from "./header";
import { DefaultLayout } from "../layout";
import { ScrollView } from "react-native";
import { RefreshControl, ScrollView } from "react-native";
import { GenreGrid } from "./genre";
import { Recommanded } from "./recommanded";
import { VerticalRecommanded } from "./vertical";
import { NewsList } from "./news";
import { WatchlistList } from "./watchlist";
import { useQueryClient } from "@tanstack/react-query";
import { useState } from "react";
export const HomePage: QueryPage<{}, Genre> = ({ randomItems }) => {
const queryClient = useQueryClient();
const [refreshing, setRefreshing] = useState(false);
return (
<ScrollView>
<ScrollView
refreshControl={
<RefreshControl
onRefresh={async () => {
setRefreshing(true);
await Promise.all(
HomePage.getFetchUrls!({}, randomItems).map((query) =>
queryClient.refetchQueries({
queryKey: toQueryKey(query),
type: "active",
exact: true,
}),
),
);
setRefreshing(false);
}}
refreshing={refreshing}
/>
}
>
<Fetch query={Header.query()}>
{(x) => (
<Header