chore: finish frontend ESLint migration #18
Enable every plugin recommended preset and replace Biome with ESLint formatting. Preserve API contracts and JSX whitespace; verify source, tests, builds and tooling.
This commit is contained in:
@@ -1,32 +1,51 @@
|
||||
import {
|
||||
type QueryKey,
|
||||
type UseQueryOptions,
|
||||
type UseQueryResult,
|
||||
useQueries,
|
||||
useQuery,
|
||||
type UseQueryOptions,
|
||||
type UseQueryResult,
|
||||
} from "@tanstack/react-query";
|
||||
import { useSyncExternalStore } from "react";
|
||||
|
||||
import {
|
||||
getAuthenticatedSessionSnapshot,
|
||||
subscribeAuthenticatedSession,
|
||||
} from "./client";
|
||||
|
||||
function useAuthenticatedQueries<TData, TError, TQueryKey extends QueryKey>(
|
||||
queries: UseQueryOptions<TData, TError, TData, TQueryKey>[],
|
||||
) {
|
||||
const hasSession = useHasAuthenticatedSession();
|
||||
return useQueries({
|
||||
queries: queries.map(
|
||||
(options): UseQueryOptions<TData, TError, TData, TQueryKey> => ({
|
||||
...options,
|
||||
enabled: query =>
|
||||
hasSession
|
||||
&& (typeof options.enabled === "function"
|
||||
? options.enabled(query)
|
||||
: (options.enabled ?? true)),
|
||||
}),
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
function useAuthenticatedQuery<
|
||||
TQueryFnData = unknown,
|
||||
TQueryFunctionData = unknown,
|
||||
TError = Error,
|
||||
TData = TQueryFnData,
|
||||
TData = TQueryFunctionData,
|
||||
TQueryKey extends QueryKey = QueryKey,
|
||||
>(
|
||||
options: UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,
|
||||
options: UseQueryOptions<TQueryFunctionData, TError, TData, TQueryKey>,
|
||||
): UseQueryResult<TData, TError> {
|
||||
const hasSession = useHasAuthenticatedSession();
|
||||
const enabled = options.enabled;
|
||||
|
||||
return useQuery({
|
||||
...options,
|
||||
enabled: (query) =>
|
||||
hasSession &&
|
||||
(typeof enabled === "function" ? enabled(query) : (enabled ?? true)),
|
||||
enabled: query =>
|
||||
hasSession
|
||||
&& (typeof enabled === "function" ? enabled(query) : (enabled ?? true)),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -38,22 +57,4 @@ function useHasAuthenticatedSession() {
|
||||
);
|
||||
}
|
||||
|
||||
function useAuthenticatedQueries<TData, TError, TQueryKey extends QueryKey>(
|
||||
queries: UseQueryOptions<TData, TError, TData, TQueryKey>[],
|
||||
) {
|
||||
const hasSession = useHasAuthenticatedSession();
|
||||
return useQueries({
|
||||
queries: queries.map(
|
||||
(options): UseQueryOptions<TData, TError, TData, TQueryKey> => ({
|
||||
...options,
|
||||
enabled: (query) =>
|
||||
hasSession &&
|
||||
(typeof options.enabled === "function"
|
||||
? options.enabled(query)
|
||||
: (options.enabled ?? true)),
|
||||
}),
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
export { useAuthenticatedQueries, useAuthenticatedQuery };
|
||||
|
||||
Reference in New Issue
Block a user