mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-03 21:54:49 -04:00
Fix ssr issue when not logged
This commit is contained in:
parent
21dffc846e
commit
dfe061e611
@ -57,7 +57,7 @@ export const queryFn = async <Data,>(
|
|||||||
kyooApiUrl = url;
|
kyooApiUrl = url;
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
if (!token && context.authenticated !== false) token = await getToken();
|
if (token === undefined && context.authenticated !== false) token = await getToken();
|
||||||
const path = [url]
|
const path = [url]
|
||||||
.concat(
|
.concat(
|
||||||
"path" in context
|
"path" in context
|
||||||
@ -150,10 +150,6 @@ export type QueryIdentifier<T = unknown, Ret = T> = {
|
|||||||
path: (string | undefined)[];
|
path: (string | undefined)[];
|
||||||
params?: { [query: string]: boolean | number | string | string[] | undefined };
|
params?: { [query: string]: boolean | number | string | string[] | undefined };
|
||||||
infinite?: boolean | { value: true; map?: (x: any[]) => Ret[] };
|
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);
|
placeholderData?: T | (() => T);
|
||||||
enabled?: boolean;
|
enabled?: boolean;
|
||||||
@ -195,19 +191,6 @@ export const useFetch = <Data,>(query: QueryIdentifier<Data>) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const useInfiniteFetch = <Data, Ret>(query: QueryIdentifier<Data, Ret>) => {
|
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>({
|
const ret = useInfiniteQuery<Page<Data>, KyooErrors>({
|
||||||
queryKey: toQueryKey(query),
|
queryKey: toQueryKey(query),
|
||||||
queryFn: (ctx) => queryFn({ ...ctx, timeout: query.timeout }, Paged(query.parser)),
|
queryFn: (ctx) => queryFn({ ...ctx, timeout: query.timeout }, Paged(query.parser)),
|
||||||
|
@ -89,7 +89,7 @@ export const InfiniteFetchList = <Data, Props, _>({
|
|||||||
{children({ isLoading: false, ...item } as any, index)}
|
{children({ isLoading: false, ...item } as any, index)}
|
||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
data={hasNextPage || isFetching ? [...(items || []), ...placeholders] : items}
|
data={isFetching ? [...(items || []), ...placeholders] : items}
|
||||||
horizontal={layout.layout === "horizontal"}
|
horizontal={layout.layout === "horizontal"}
|
||||||
keyExtractor={(item: any) => item.id}
|
keyExtractor={(item: any) => item.id}
|
||||||
numColumns={numColumns}
|
numColumns={numColumns}
|
||||||
|
@ -115,7 +115,7 @@ const InfiniteScroll = <Props,>({
|
|||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
{((hasMore && fetchMore) || isFetching) && loader}
|
{isFetching && loader}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user