Add react query devtools

This commit is contained in:
Zoe Roux 2023-12-03 20:37:51 +01:00
parent 0ac4a1daa0
commit 275a892ee1
9 changed files with 36 additions and 17 deletions

View File

@ -20,6 +20,7 @@
"@material-symbols/svg-400": "^0.14.1", "@material-symbols/svg-400": "^0.14.1",
"@radix-ui/react-dropdown-menu": "^2.0.6", "@radix-ui/react-dropdown-menu": "^2.0.6",
"@tanstack/react-query": "^5.12.1", "@tanstack/react-query": "^5.12.1",
"@tanstack/react-query-devtools": "^5.12.2",
"array-shuffle": "^3.0.0", "array-shuffle": "^3.0.0",
"expo-linear-gradient": "^12.5.0", "expo-linear-gradient": "^12.5.0",
"expo-modules-core": "^1.5.12", "expo-modules-core": "^1.5.12",

View File

@ -21,6 +21,7 @@
import "../polyfill"; import "../polyfill";
import { HydrationBoundary, QueryClientProvider } from "@tanstack/react-query"; import { HydrationBoundary, QueryClientProvider } from "@tanstack/react-query";
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
import { HiddenIfNoJs, SkeletonCss, ThemeSelector } from "@kyoo/primitives"; import { HiddenIfNoJs, SkeletonCss, ThemeSelector } from "@kyoo/primitives";
import { WebTooltip } from "@kyoo/primitives/src/tooltip.web"; import { WebTooltip } from "@kyoo/primitives/src/tooltip.web";
import { import {
@ -153,6 +154,7 @@ const App = ({ Component, pageProps }: AppProps) => {
</ThemeSelector> </ThemeSelector>
</HydrationBoundary> </HydrationBoundary>
</AccountProvider> </AccountProvider>
<ReactQueryDevtools initialIsOpen={false} />
</QueryClientProvider> </QueryClientProvider>
</> </>
</YoshikiDebug> </YoshikiDebug>

View File

@ -23,7 +23,6 @@ import {
dehydrate, dehydrate,
QueryClient, QueryClient,
QueryFunctionContext, QueryFunctionContext,
QueryOptions,
useInfiniteQuery, useInfiniteQuery,
useQuery, useQuery,
} from "@tanstack/react-query"; } from "@tanstack/react-query";
@ -73,7 +72,7 @@ export const queryFn = async <Data,>(
? (context.path.filter((x) => x) as string[]) ? (context.path.filter((x) => x) as string[])
: "pageParam" in context && context.pageParam : "pageParam" in context && context.pageParam
? [context.pageParam as string] ? [context.pageParam as string]
: (context.queryKey.filter((x, i) => x && i) as string[]), : (context.queryKey.filter((x) => x) as string[]),
) )
.join("/") .join("/")
.replace("/?", "?"); .replace("/?", "?");
@ -180,11 +179,8 @@ export type QueryPage<Props = {}, Items = unknown> = ComponentType<
}; };
const toQueryKey = <Data, Ret>(query: QueryIdentifier<Data, Ret>) => { const toQueryKey = <Data, Ret>(query: QueryIdentifier<Data, Ret>) => {
const prefix = Platform.OS !== "web" ? [kyooApiUrl] : [""];
if (query.params) { if (query.params) {
return [ return [
...prefix,
...query.path, ...query.path,
"?" + "?" +
Object.entries(query.params) Object.entries(query.params)
@ -193,7 +189,7 @@ const toQueryKey = <Data, Ret>(query: QueryIdentifier<Data, Ret>) => {
.join("&"), .join("&"),
]; ];
} else { } else {
return [...prefix, ...query.path]; return query.path;
} }
}; };

View File

@ -18,7 +18,7 @@
* along with Kyoo. If not, see <https://www.gnu.org/licenses/>. * along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
*/ */
import { Icon, IconButton, tooltip } from "@kyoo/primitives"; import { IconButton, tooltip } from "@kyoo/primitives";
import { ComponentProps } from "react"; import { ComponentProps } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import BookmarkAdd from "@material-symbols/svg-400/rounded/bookmark_add.svg"; import BookmarkAdd from "@material-symbols/svg-400/rounded/bookmark_add.svg";

View File

@ -27,9 +27,9 @@ import { DetailsCollections } from "./collection";
const query = (slug: string): QueryIdentifier<Movie> => ({ const query = (slug: string): QueryIdentifier<Movie> => ({
parser: MovieP, parser: MovieP,
path: ["movies", slug], path: ["movie", slug],
params: { params: {
fields: ["studio"], fields: ["studio", "watchStatus"],
}, },
}); });

View File

@ -90,7 +90,7 @@ export const SeasonHeader = ({
SeasonHeader.query = (slug: string): QueryIdentifier<Season, SeasonProcessed> => ({ SeasonHeader.query = (slug: string): QueryIdentifier<Season, SeasonProcessed> => ({
parser: SeasonP, parser: SeasonP,
path: ["shows", slug, "seasons"], path: ["show", slug, "seasons"],
params: { params: {
// Fetch all seasons at one, there won't be hundred of thems anyways. // Fetch all seasons at one, there won't be hundred of thems anyways.
limit: 0, limit: 0,
@ -159,7 +159,7 @@ EpisodeList.query = (
season: string | number, season: string | number,
): QueryIdentifier<Episode, Episode & { firstOfSeason?: boolean }> => ({ ): QueryIdentifier<Episode, Episode & { firstOfSeason?: boolean }> => ({
parser: EpisodeP, parser: EpisodeP,
path: ["shows", slug, "episode"], path: ["show", slug, "episode"],
params: { params: {
seasonNumber: season ? `gte:${season}` : undefined, seasonNumber: season ? `gte:${season}` : undefined,
}, },

View File

@ -81,9 +81,9 @@ const ShowHeader = forwardRef<View, ViewProps & { slug: string }>(function ShowH
const query = (slug: string): QueryIdentifier<Show> => ({ const query = (slug: string): QueryIdentifier<Show> => ({
parser: ShowP, parser: ShowP,
path: ["shows", slug], path: ["show", slug],
params: { params: {
fields: ["studio", "firstEpisode"], fields: ["studio", "firstEpisode", "watchStatus"],
}, },
}); });

View File

@ -50,6 +50,6 @@
// //
// Staff.query = (slug: string): QueryIdentifier<Person> => ({ // Staff.query = (slug: string): QueryIdentifier<Person> => ({
// parser: PersonP, // parser: PersonP,
// path: ["shows", slug, "people"], // path: ["show", slug, "people"],
// infinite: true, // infinite: true,
// }); // });

View File

@ -4541,6 +4541,25 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"@tanstack/query-devtools@npm:5.12.1":
version: 5.12.1
resolution: "@tanstack/query-devtools@npm:5.12.1"
checksum: 1956ef3edb9f54bae2c80a0a6ffbdcfe9167078f187d05db42a507675e6099857f41f1a5523eeed27dd3e1d2f878c6cf14c5912313823ed49532e210eaf3492a
languageName: node
linkType: hard
"@tanstack/react-query-devtools@npm:^5.12.2":
version: 5.12.2
resolution: "@tanstack/react-query-devtools@npm:5.12.2"
dependencies:
"@tanstack/query-devtools": 5.12.1
peerDependencies:
"@tanstack/react-query": ^5.12.2
react: ^18.0.0
checksum: b08093902d3ae000d4a9d90d249dc9bad9be56d1a84dc0c1ae2784a054c61582a66a8b26db2cb15cd2c160950027ffea253113869ac2fb74f7c82619960d6bdb
languageName: node
linkType: hard
"@tanstack/react-query@npm:^5.12.1": "@tanstack/react-query@npm:^5.12.1":
version: 5.12.1 version: 5.12.1
resolution: "@tanstack/react-query@npm:5.12.1" resolution: "@tanstack/react-query@npm:5.12.1"
@ -15153,6 +15172,7 @@ __metadata:
"@radix-ui/react-dropdown-menu": ^2.0.6 "@radix-ui/react-dropdown-menu": ^2.0.6
"@svgr/webpack": ^8.1.0 "@svgr/webpack": ^8.1.0
"@tanstack/react-query": ^5.12.1 "@tanstack/react-query": ^5.12.1
"@tanstack/react-query-devtools": ^5.12.2
"@types/node": 20.10.1 "@types/node": 20.10.1
"@types/react": 18.2.39 "@types/react": 18.2.39
"@types/react-dom": 18.2.17 "@types/react-dom": 18.2.17