Add basics episodes more menu

This commit is contained in:
Zoe Roux 2023-12-13 23:07:15 +01:00
parent 8640fefc8b
commit 0f7a8bd4f3
6 changed files with 84 additions and 13 deletions

View File

@ -49,15 +49,21 @@ const Menu = <AsProps,>({
onMenuOpen, onMenuOpen,
onMenuClose, onMenuClose,
children, children,
isOpen: outerOpen,
setOpen: outerSetOpen,
...props ...props
}: { }: {
Trigger: ComponentType<AsProps>; Trigger: ComponentType<AsProps>;
children?: ReactNode | ReactNode[] | null; children?: ReactNode | ReactNode[] | null;
onMenuOpen?: () => void; onMenuOpen?: () => void;
onMenuClose?: () => void; onMenuClose?: () => void;
isOpen?: boolean;
setOpen?: (v: boolean) => void;
} & Omit<AsProps, "onPress">) => { } & Omit<AsProps, "onPress">) => {
const insets = useSafeAreaInsets(); const insets = useSafeAreaInsets();
const [isOpen, setOpen] = useState(false); const [isOpen, setOpen] =
// eslint-disable-next-line react-hooks/rules-of-hooks
outerOpen !== undefined && outerSetOpen ? [outerOpen, outerSetOpen] : useState(false);
useEffect(() => { useEffect(() => {
if (isOpen) onMenuOpen?.call(null); if (isOpen) onMenuOpen?.call(null);

View File

@ -50,18 +50,24 @@ const Menu = <AsProps extends { onPress: PressableProps["onPress"] }>({
onMenuOpen, onMenuOpen,
onMenuClose, onMenuClose,
children, children,
isOpen,
setOpen,
...props ...props
}: { }: {
Trigger: ComponentType<AsProps>; Trigger: ComponentType<AsProps>;
children: ReactNode | ReactNode[] | null; children: ReactNode | ReactNode[] | null;
onMenuOpen?: () => void; onMenuOpen?: () => void;
onMenuClose?: () => void; onMenuClose?: () => void;
isOpen?: boolean;
setOpen?: (v: boolean) => void;
} & Omit<AsProps, "onPress">) => { } & Omit<AsProps, "onPress">) => {
return ( return (
<DropdownMenu.Root <DropdownMenu.Root
modal modal
onOpenChange={(isOpen) => { open={isOpen}
if (isOpen) onMenuOpen?.call(null); onOpenChange={(newOpen) => {
if (setOpen) setOpen(newOpen)
if (newOpen) onMenuOpen?.call(null);
else onMenuClose?.call(null); else onMenuClose?.call(null);
}} }}
> >

View File

@ -1,9 +1,38 @@
import { Menu } from "@kyoo/primitives"; /*
* Kyoo - A portable and vast media library solution.
* Copyright (c) Kyoo.
*
* See AUTHORS.md and LICENSE file in the project root for full license information.
*
* Kyoo is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* Kyoo is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
*/
import { IconButton, Menu, tooltip } from "@kyoo/primitives";
import { ComponentProps } from "react";
import { useTranslation } from "react-i18next";
import MoreVert from "@material-symbols/svg-400/rounded/more_vert.svg";
import Info from "@material-symbols/svg-400/rounded/info.svg";
export const EpisodesContext = ({
showSlug,
...props
}: { showSlug: string } & Partial<ComponentProps<typeof Menu<typeof IconButton>>>) => {
const { t } = useTranslation();
export const EpisodesContext = () => {
return ( return (
<Menu> <Menu Trigger={IconButton} icon={MoreVert} {...tooltip(t("misc.more"))} {...(props as any)}>
<Menu.Item /> <Menu.Item label={t("home.episodeMore.goToShow")} icon={Info} href={`/show/${showSlug}`} />
</Menu> </Menu>
); );
}; };

View File

@ -30,11 +30,13 @@ import {
ts, ts,
} from "@kyoo/primitives"; } from "@kyoo/primitives";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { ImageStyle, PressableProps, View } from "react-native"; import { ImageStyle, Platform, PressableProps, View } from "react-native";
import { Layout, WithLoading } from "../fetch"; import { Layout, WithLoading } from "../fetch";
import { percent, rem, Stylable, Theme, useYoshiki } from "yoshiki/native"; import { percent, rem, Stylable, Theme, useYoshiki } from "yoshiki/native";
import { KyooImage, WatchStatusV } from "@kyoo/models"; import { KyooImage, WatchStatusV } from "@kyoo/models";
import { ItemProgress } from "../browse/grid"; import { ItemProgress } from "../browse/grid";
import { EpisodesContext } from "../components/context-menus";
import { useRef, useState } from "react";
export const episodeDisplayNumber = ( export const episodeDisplayNumber = (
episode: { episode: {
@ -172,21 +174,31 @@ export const EpisodeLine = ({
watchedStatus: WatchStatusV | null; watchedStatus: WatchStatusV | null;
}> & }> &
Partial<PressableProps>) => { Partial<PressableProps>) => {
const [moreOpened, setMoreOpened] = useState(false);
const { css } = useYoshiki("episode-line"); const { css } = useYoshiki("episode-line");
const { t } = useTranslation(); const { t } = useTranslation();
return ( return (
<Link <Link
href={slug ? `/watch/${slug}` : ""} href={slug ? `/watch/${slug}` : ""}
onLongPress={() => setMoreOpened(true)}
{...css( {...css(
{ {
alignItems: "center", alignItems: "center",
flexDirection: "row", flexDirection: "row",
child: {
more: {
display: "none",
},
},
fover: { fover: {
self: focusReset, self: focusReset,
title: { title: {
textDecorationLine: "underline", textDecorationLine: "underline",
}, },
more: {
display: "flex",
},
}, },
}, },
props as any, props as any,
@ -249,7 +261,17 @@ export const EpisodeLine = ({
{isLoading || {isLoading ||
(runtime && <Skeleton>{isLoading || <SubP>{displayRuntime(runtime)}</SubP>}</Skeleton>)} (runtime && <Skeleton>{isLoading || <SubP>{displayRuntime(runtime)}</SubP>}</Skeleton>)}
</View> </View>
<View {...css({ flexDirection: "row" })}>
<Skeleton>{isLoading || <P numberOfLines={3}>{overview}</P>}</Skeleton> <Skeleton>{isLoading || <P numberOfLines={3}>{overview}</P>}</Skeleton>
<EpisodesContext
isOpen={moreOpened}
setOpen={setMoreOpened}
{...css([
"more",
Platform.OS === "web" && moreOpened && { display: "flex !important" as any },
])}
/>
</View>
</View> </View>
</Link> </Link>
); );

View File

@ -5,7 +5,10 @@
"watchlist": "Continue watching", "watchlist": "Continue watching",
"info": "See more", "info": "See more",
"none": "No episodes", "none": "No episodes",
"watchlistLogin": "To keep track of what you watched or plan to watch, you need to login." "watchlistLogin": "To keep track of what you watched or plan to watch, you need to login.",
"episodeMore": {
"goToShow": "Go to show"
}
}, },
"show": { "show": {
"play": "Play", "play": "Play",
@ -58,7 +61,8 @@
"prev-page": "Previous page", "prev-page": "Previous page",
"next-page": "Next page", "next-page": "Next page",
"delete": "Delete", "delete": "Delete",
"cancel": "Cancel" "cancel": "Cancel",
"more": "More"
}, },
"navbar": { "navbar": {
"home": "Home", "home": "Home",

View File

@ -5,7 +5,10 @@
"watchlist": "Continuer de regarder", "watchlist": "Continuer de regarder",
"info": "Voir plus", "info": "Voir plus",
"none": "Aucun episode", "none": "Aucun episode",
"watchlistLogin": "Pour suivre ce que vous avez regardé ou prévoyez de regarder, vous devez vous connecter." "watchlistLogin": "Pour suivre ce que vous avez regardé ou prévoyez de regarder, vous devez vous connecter.",
"episodeMore": {
"goToShow": "Aller a la serie"
}
}, },
"show": { "show": {
"play": "Lecture", "play": "Lecture",
@ -58,7 +61,8 @@
"prev-page": "Page précédente", "prev-page": "Page précédente",
"next-page": "Page suivante", "next-page": "Page suivante",
"delete": "Supprimer", "delete": "Supprimer",
"cancel": "Annuler" "cancel": "Annuler",
"more": "Plus"
}, },
"navbar": { "navbar": {
"home": "Accueil", "home": "Accueil",