Format code

This commit is contained in:
Zoe Roux 2022-09-28 13:15:56 +09:00
parent ca41ddb271
commit 03b05dfc87
14 changed files with 105 additions and 56 deletions

View File

@ -42,7 +42,7 @@ export const EpisodeBox = ({ episode, sx }: { episode?: Episode; sx: SxProps })
};
export const EpisodeLine = ({ episode, sx }: { episode?: Episode; sx?: SxProps }) => {
const { t } = useTranslation("browse");
const { t } = useTranslation("browse");
return (
<>
@ -61,7 +61,13 @@ export const EpisodeLine = ({ episode, sx }: { episode?: Episode; sx?: SxProps }
<Typography variant="overline" align="center" sx={{ width: "4rem", flexShrink: 0 }}>
{episode ? displayNumber(episode) : <Skeleton />}
</Typography>
<Image img={episode?.thumbnail} alt="" width="18%" aspectRatio="16/9" sx={{ flexShrink: 0 }} />
<Image
img={episode?.thumbnail}
alt=""
width="18%"
aspectRatio="16/9"
sx={{ flexShrink: 0 }}
/>
{episode ? (
<Box sx={{ flexGrow: 1 }}>
<Typography variant="h6">{episode.name ?? t("show.episodeNoMetadata")}</Typography>

View File

@ -22,7 +22,7 @@ import { Alert, Box, Snackbar, SnackbarCloseReason, Typography, SxProps } from "
import { SyntheticEvent, useState } from "react";
import { KyooErrors } from "~/models";
export const ErrorComponent = ({ errors, sx }: { errors: string[], sx?: SxProps }) => {
export const ErrorComponent = ({ errors, sx }: { errors: string[]; sx?: SxProps }) => {
return (
<Box
sx={{
@ -32,10 +32,12 @@ export const ErrorComponent = ({ errors, sx }: { errors: string[], sx?: SxProps
justifyContent: "center",
height: "100%",
backgroundColor: "error.light",
...sx
...sx,
}}
>
<Typography variant="h1" component="h1" sx={{ fontWeight: 500 }}>Error</Typography>
<Typography variant="h1" component="h1" sx={{ fontWeight: 500 }}>
Error
</Typography>
{errors.map((x, i) => (
<Typography variant="h2" component="h2" key={i}>
{x}

View File

@ -24,7 +24,15 @@ import { ReactNode, useRef } from "react";
import { Container } from "./container";
import useTranslation from "next-translate/useTranslation";
export const HorizontalList = ({ title, noContent, children }: { title: string, noContent: string, children: ReactNode[] }) => {
export const HorizontalList = ({
title,
noContent,
children,
}: {
title: string;
noContent: string;
children: ReactNode[];
}) => {
const { t } = useTranslation("browse");
const ref = useRef<HTMLDivElement>(null);
const getScrollSize = () => {
@ -41,18 +49,24 @@ export const HorizontalList = ({ title, noContent, children }: { title: string,
<>
<Container
sx={{ display: "flex", flexDirection: "row", justifyContent: "space-between", py: 3 }}
>
>
<Typography variant="h4" component="h2">
{title}
</Typography>
<Box>
<Tooltip title={t("misc.prev-page")}>
<IconButton aria-label={t("misc.prev-page")} onClick={() => ref.current?.scrollBy({ left: -getScrollSize(), behavior: "smooth" })}>
<IconButton
aria-label={t("misc.prev-page")}
onClick={() => ref.current?.scrollBy({ left: -getScrollSize(), behavior: "smooth" })}
>
<ArrowLeft />
</IconButton>
</Tooltip>
<Tooltip title={t("misc.next-page")}>
<IconButton aria-label={t("misc.next-page")} onClick={() => ref.current?.scrollBy({ left: getScrollSize(), behavior: "smooth" })}>
<IconButton
aria-label={t("misc.next-page")}
onClick={() => ref.current?.scrollBy({ left: getScrollSize(), behavior: "smooth" })}
>
<ArrowRight />
</IconButton>
</Tooltip>
@ -62,22 +76,22 @@ export const HorizontalList = ({ title, noContent, children }: { title: string,
<Box sx={{ display: "flex", justifyContent: "center" }}>
<Typography sx={{ py: 3 }}>{noContent}</Typography>
</Box>
) : (
<Container
sx={{
display: "flex",
flexDirection: "row",
maxWidth: "100%",
overflowY: "auto",
pt: 1,
pb: 2,
overflowX: "visible",
}}
ref={ref}
>
{children}
</Container>
) : (
<Container
sx={{
display: "flex",
flexDirection: "row",
maxWidth: "100%",
overflowY: "auto",
pt: 1,
pb: 2,
overflowX: "visible",
}}
ref={ref}
>
{children}
</Container>
)}
</>
);
}
};

View File

@ -63,7 +63,7 @@ const KyooTitle = (props: { sx: SxProps<Theme> }) => {
mr: 2,
fontFamily: "monospace",
fontWeight: 700,
color: "white"
color: "white",
}}
>
Kyoo
@ -112,7 +112,7 @@ export const Navbar = (barProps: AppBarProps) => {
</Box>
<Tooltip title={t("navbar.login")}>
<IconButton sx={{ p: 0 }} href="/auth/login">
<Avatar alt={t("navbar.login")}/>
<Avatar alt={t("navbar.login")} />
</IconButton>
</Tooltip>
</Toolbar>
@ -125,4 +125,3 @@ Navbar.query = (): QueryIdentifier<Page<Library>> => ({
parser: Paged(LibraryP),
path: ["libraries"],
});

View File

@ -26,11 +26,15 @@ export const PersonAvatar = ({ person, sx }: { person?: Person; sx?: SxProps })
if (!person) {
return (
<Box sx={sx}>
<Skeleton variant="circular" sx={{ width: "100%", aspectRatio: "1/1", height: "unset" }}/>
<Typography align="center"><Skeleton/></Typography>
<Typography variant="body2" align="center"><Skeleton/></Typography>
<Skeleton variant="circular" sx={{ width: "100%", aspectRatio: "1/1", height: "unset" }} />
<Typography align="center">
<Skeleton />
</Typography>
<Typography variant="body2" align="center">
<Skeleton />
</Typography>
</Box>
)
);
}
return (
<Link href={`/person/${person.slug}`} color="inherit" sx={sx}>

View File

@ -21,7 +21,6 @@
import { z } from "zod";
import { ImagesP, ResourceP } from "../traits";
export const CollectionP = ResourceP.merge(ImagesP).extend({
/**
* The title of this collection.

View File

@ -38,8 +38,17 @@ export const LibraryItemP = z.preprocess(
return x;
},
z.union([
/*
* Either a Show
*/
ShowP.and(z.object({ type: z.literal(ItemType.Show) })),
/*
* Or a Movie
*/
MovieP.and(z.object({ type: z.literal(ItemType.Movie) })),
/*
* Or a Collection
*/
CollectionP.and(z.object({ type: z.literal(ItemType.Collection) })),
]),
);

View File

@ -32,8 +32,7 @@ export const getDisplayDate = (data: Show | Movie) => {
return startAir.getFullYear().toString();
}
return startAir.getFullYear() + (endAir ? ` - ${endAir.getFullYear()}` : "");
}
else if (airDate) {
} else if (airDate) {
return airDate.getFullYear().toString();
}
};

View File

@ -67,9 +67,7 @@ const App = ({ Component, pageProps }: AppProps) => {
</Head>
<QueryClientProvider client={queryClient}>
<Hydrate state={queryState}>
<ThemeProvider theme={defaultTheme}>
{getLayout(<Component {...props} />)}
</ThemeProvider>
<ThemeProvider theme={defaultTheme}>{getLayout(<Component {...props} />)}</ThemeProvider>
</Hydrate>
</QueryClientProvider>
</>

View File

@ -247,7 +247,9 @@ const BrowseSettings = ({
const router = useRouter();
const { t } = useTranslation("browse");
const switchViewTitle = layout === Layout.Grid ? t("browse.switchToList") : t("browse.switchToGrid");
const switchViewTitle = layout === Layout.Grid
? t("browse.switchToList")
: t("browse.switchToGrid");
return (
<>

View File

@ -18,6 +18,6 @@
* along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
*/
import BrowsePage from "./browse"
import BrowsePage from "./browse";
export default BrowsePage;

View File

@ -135,7 +135,11 @@ export const ShowHeader = ({ data }: { data?: Show | Movie }) => {
{data?.name ?? <Skeleton width="15rem" />}
</Typography>
{(!data || getDisplayDate(data)) && (
<Typography component="p" variant="h5" sx={{ color: { md: "white" }, fontWeight: 300, mb: ".5rem" }}>
<Typography
component="p"
variant="h5"
sx={{ color: { md: "white" }, fontWeight: 300, mb: ".5rem" }}
>
{data != undefined ? (
getDisplayDate(data)
) : (
@ -247,7 +251,6 @@ export const ShowHeader = ({ data }: { data?: Show | Movie }) => {
);
};
export const ShowStaff = ({ slug }: { slug: string }) => {
const { items, isError, error } = useInfiniteFetch(ShowStaff.query(slug));
const { t } = useTranslation("browse");
@ -300,11 +303,6 @@ const MovieDetails: QueryPage<{ slug: string }> = ({ slug }) => {
);
};
MovieDetails.getFetchUrls = ({ slug }) => [
query(slug),
ShowStaff.query(slug),
Navbar.query(),
];
MovieDetails.getFetchUrls = ({ slug }) => [query(slug), ShowStaff.query(slug), Navbar.query()];
export default withRoute(MovieDetails);

View File

@ -19,14 +19,22 @@
*/
import { forwardRef, Ref } from "react";
import NLink, { LinkProps as NLinkProps} from "next/link";
import { Button as MButton, ButtonProps, Link as MLink, LinkProps as MLinkProps} from "@mui/material";
import NLink, { LinkProps as NLinkProps } from "next/link";
import {
Button as MButton,
ButtonProps,
Link as MLink,
LinkProps as MLinkProps,
} from "@mui/material";
type ButtonRef = HTMLButtonElement;
type ButtonLinkProps = Omit<ButtonProps, "href"> &
Pick<NLinkProps, "href" | "as" | "prefetch" | "locale">;
const NextButton = ({ href, as, prefetch, locale, ...props }: ButtonLinkProps, ref: Ref<ButtonRef>) => (
const NextButton = (
{ href, as, prefetch, locale, ...props }: ButtonLinkProps,
ref: Ref<ButtonRef>,
) => (
<NLink href={href} as={as} prefetch={prefetch} locale={locale} passHref>
<MButton ref={ref} {...props} />
</NLink>
@ -37,10 +45,21 @@ export const ButtonLink = forwardRef<ButtonRef, ButtonLinkProps>(NextButton);
type LinkRef = HTMLAnchorElement;
type LinkProps = Omit<MLinkProps, "href"> &
Pick<NLinkProps, "as" | "prefetch" | "locale" | "shallow" | "replace"> &
({ to: NLinkProps["href"], href?: undefined } | { href: NLinkProps["href"], to?: undefined });
({ to: NLinkProps["href"]; href?: undefined } | { href: NLinkProps["href"]; to?: undefined });
const NextLink = ({ href, to, as, prefetch, locale, shallow, replace, ...props }: LinkProps, ref: Ref<LinkRef>) => (
<NLink href={href ?? to} as={as} prefetch={prefetch} locale={locale} shallow={shallow} replace={replace} passHref>
const NextLink = (
{ href, to, as, prefetch, locale, shallow, replace, ...props }: LinkProps,
ref: Ref<LinkRef>,
) => (
<NLink
href={href ?? to}
as={as}
prefetch={prefetch}
locale={locale}
shallow={shallow}
replace={replace}
passHref
>
<MLink ref={ref} {...props} />
</NLink>
);

View File

@ -61,7 +61,7 @@ const queryFn = async <Data>(
} catch (e) {
data = { errors: [error] } as KyooErrors;
}
console.log("Invalid response:", data)
console.log("Invalid response:", data);
throw data as KyooErrors;
}
@ -132,7 +132,7 @@ export const useInfiniteFetch = <Data>(query: QueryIdentifier<Data>) => {
queryFn: (ctx) => queryFn(Paged(query.parser), ctx),
getNextPageParam: (page: Page<Data>) => page?.next || undefined,
});
return {...ret, items: ret.data?.pages.flatMap((x) => x.items)}
return { ...ret, items: ret.data?.pages.flatMap((x) => x.items) };
};
export const fetchQuery = async (queries: QueryIdentifier[]) => {