Fix hydratation error

This commit is contained in:
Zoe Roux 2023-07-18 11:27:25 +09:00
parent 4c84f857e7
commit 4fde5fb65f
3 changed files with 9 additions and 37 deletions

View File

@ -158,9 +158,11 @@ export type QueryPage<Props = {}> = ComponentType<Props> & {
}; };
const toQueryKey = <Data,>(query: QueryIdentifier<Data>) => { const toQueryKey = <Data,>(query: QueryIdentifier<Data>) => {
const prefix = Platform.OS !== "web" ? [kyooApiUrl] : [""];
if (query.params) { if (query.params) {
return [ return [
kyooApiUrl, ...prefix,
...query.path, ...query.path,
"?" + "?" +
Object.entries(query.params) Object.entries(query.params)
@ -169,7 +171,7 @@ const toQueryKey = <Data,>(query: QueryIdentifier<Data>) => {
.join("&"), .join("&"),
]; ];
} else { } else {
return [kyooApiUrl, ...query.path]; return [...prefix, ...query.path];
} }
}; };

View File

@ -58,4 +58,4 @@ export const DefaultLayout = ({
</> </>
); );
}; };
DefaultLayout.getFetchUrls = () => [Navbar.query(), MeQuery]; DefaultLayout.getFetchUrls = () => [MeQuery];

View File

@ -21,11 +21,7 @@
import { import {
AccountContext, AccountContext,
deleteAccount, deleteAccount,
Library,
LibraryP,
logout, logout,
Page,
Paged,
QueryIdentifier, QueryIdentifier,
User, User,
UserP, UserP,
@ -37,7 +33,6 @@ import {
Header, Header,
Avatar, Avatar,
A, A,
Skeleton,
tooltip, tooltip,
ts, ts,
Menu, Menu,
@ -48,14 +43,14 @@ import { Platform, TextInput, View, ViewProps } from "react-native";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { createParam } from "solito"; import { createParam } from "solito";
import { useRouter } from "solito/router"; import { useRouter } from "solito/router";
import { rem, Stylable, useYoshiki } from "yoshiki/native"; import { Stylable, useYoshiki } from "yoshiki/native";
import MenuIcon from "@material-symbols/svg-400/rounded/menu-fill.svg"; import MenuIcon from "@material-symbols/svg-400/rounded/menu-fill.svg";
import Search from "@material-symbols/svg-400/rounded/search-fill.svg"; import Search from "@material-symbols/svg-400/rounded/search-fill.svg";
import Login from "@material-symbols/svg-400/rounded/login.svg"; import Login from "@material-symbols/svg-400/rounded/login.svg";
import Register from "@material-symbols/svg-400/rounded/app_registration.svg"; import Register from "@material-symbols/svg-400/rounded/app_registration.svg";
import Logout from "@material-symbols/svg-400/rounded/logout.svg"; import Logout from "@material-symbols/svg-400/rounded/logout.svg";
import Delete from "@material-symbols/svg-400/rounded/delete.svg"; import Delete from "@material-symbols/svg-400/rounded/delete.svg";
import { Fetch, FetchNE } from "../fetch"; import { FetchNE } from "../fetch";
import { KyooLongLogo } from "./icon"; import { KyooLongLogo } from "./icon";
import { forwardRef, useContext, useRef, useState } from "react"; import { forwardRef, useContext, useRef, useState } from "react";
import { useQueryClient } from "@tanstack/react-query"; import { useQueryClient } from "@tanstack/react-query";
@ -116,7 +111,7 @@ export const NavbarProfile = () => {
const { css, theme } = useYoshiki(); const { css, theme } = useYoshiki();
const { t } = useTranslation(); const { t } = useTranslation();
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const { type, accounts, selected, setSelected } = useContext(AccountContext); const { accounts, selected, setSelected } = useContext(AccountContext);
return ( return (
<FetchNE query={MeQuery}> <FetchNE query={MeQuery}>
@ -276,33 +271,8 @@ export const Navbar = (props: Stylable) => {
display: { xs: "none", sm: "flex" }, display: { xs: "none", sm: "flex" },
marginX: ts(2), marginX: ts(2),
})} })}
> />
<Fetch query={Navbar.query()} placeholderCount={4}>
{(library, i) =>
!library.isLoading ? (
<A
href={`/browse/${library.slug}`}
key={library.slug}
{...css({
marginX: ts(1),
textTransform: "uppercase",
color: "white",
})}
>
{library.name}
</A>
) : (
<Skeleton key={i} {...css({ width: rem(5), marginX: ts(1) })} />
)
}
</Fetch>
</View>
<NavbarRight /> <NavbarRight />
</Header> </Header>
); );
}; };
Navbar.query = (): QueryIdentifier<Page<Library>> => ({
parser: Paged(LibraryP),
path: ["libraries"],
});