Fix ssr issue when not logged

This commit is contained in:
Zoe Roux 2023-12-11 15:33:35 +01:00
parent 21dffc846e
commit dfe061e611
3 changed files with 3 additions and 20 deletions

View File

@ -57,7 +57,7 @@ export const queryFn = async <Data,>(
kyooApiUrl = url;
// @ts-ignore
if (!token && context.authenticated !== false) token = await getToken();
if (token === undefined && context.authenticated !== false) token = await getToken();
const path = [url]
.concat(
"path" in context
@ -150,10 +150,6 @@ export type QueryIdentifier<T = unknown, Ret = T> = {
path: (string | undefined)[];
params?: { [query: string]: boolean | number | string | string[] | undefined };
infinite?: boolean | { value: true; map?: (x: any[]) => Ret[] };
/**
* A custom get next function if the infinite query is not a page.
*/
getNext?: (item: unknown) => string | undefined;
placeholderData?: T | (() => T);
enabled?: boolean;
@ -195,19 +191,6 @@ export const useFetch = <Data,>(query: QueryIdentifier<Data>) => {
};
export const useInfiniteFetch = <Data, Ret>(query: QueryIdentifier<Data, Ret>) => {
if (query.getNext) {
// eslint-disable-next-line react-hooks/rules-of-hooks
const ret = useInfiniteQuery<Data[], KyooErrors>({
queryKey: toQueryKey(query),
queryFn: (ctx) => queryFn({ ...ctx, timeout: query.timeout }, z.array(query.parser)),
getNextPageParam: query.getNext,
initialPageParam: undefined,
placeholderData: query.placeholderData as any,
enabled: query.enabled,
});
return { ...ret, items: ret.data?.pages.flatMap((x) => x) as unknown as Ret[] | undefined };
}
// eslint-disable-next-line react-hooks/rules-of-hooks
const ret = useInfiniteQuery<Page<Data>, KyooErrors>({
queryKey: toQueryKey(query),
queryFn: (ctx) => queryFn({ ...ctx, timeout: query.timeout }, Paged(query.parser)),

View File

@ -89,7 +89,7 @@ export const InfiniteFetchList = <Data, Props, _>({
{children({ isLoading: false, ...item } as any, index)}
</View>
)}
data={hasNextPage || isFetching ? [...(items || []), ...placeholders] : items}
data={isFetching ? [...(items || []), ...placeholders] : items}
horizontal={layout.layout === "horizontal"}
keyExtractor={(item: any) => item.id}
numColumns={numColumns}

View File

@ -115,7 +115,7 @@ const InfiniteScroll = <Props,>({
)}
>
{children}
{((hasMore && fetchMore) || isFetching) && loader}
{isFetching && loader}
</div>
);