mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
wip
This commit is contained in:
parent
3a9cb262f8
commit
43cf343841
@ -26,25 +26,6 @@ import type { Movie, Show } from "./resources";
|
|||||||
|
|
||||||
export const zdate = z.coerce.date;
|
export const zdate = z.coerce.date;
|
||||||
|
|
||||||
export const getDisplayDate = (data: Show | Movie) => {
|
|
||||||
const {
|
|
||||||
startAir,
|
|
||||||
endAir,
|
|
||||||
airDate,
|
|
||||||
}: { startAir?: Date | null; endAir?: Date | null; airDate?: Date | null } = data;
|
|
||||||
|
|
||||||
if (startAir) {
|
|
||||||
if (!endAir || startAir.getFullYear() === endAir.getFullYear()) {
|
|
||||||
return startAir.getFullYear().toString();
|
|
||||||
}
|
|
||||||
return startAir.getFullYear() + (endAir ? ` - ${endAir.getFullYear()}` : "");
|
|
||||||
}
|
|
||||||
if (airDate) {
|
|
||||||
return airDate.getFullYear().toString();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const useLocalSetting = (setting: string, def: string) => {
|
export const useLocalSetting = (setting: string, def: string) => {
|
||||||
if (Platform.OS === "web" && typeof window === "undefined") return [def, null!] as const;
|
if (Platform.OS === "web" && typeof window === "undefined") return [def, null!] as const;
|
||||||
// eslint-disable-next-line react-hooks/rules-of-hooks
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||||
|
@ -1,163 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 { WatchStatusV, queryFn, useAccount } from "@kyoo/models";
|
|
||||||
import { HR, IconButton, Menu, tooltip, usePopup } from "@kyoo/primitives";
|
|
||||||
import Refresh from "@material-symbols/svg-400/rounded/autorenew.svg";
|
|
||||||
import Download from "@material-symbols/svg-400/rounded/download.svg";
|
|
||||||
import Info from "@material-symbols/svg-400/rounded/info.svg";
|
|
||||||
import MoreVert from "@material-symbols/svg-400/rounded/more_vert.svg";
|
|
||||||
import MovieInfo from "@material-symbols/svg-400/rounded/movie_info.svg";
|
|
||||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
||||||
import type { ComponentProps } from "react";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import { Platform } from "react-native";
|
|
||||||
import { useYoshiki } from "yoshiki/native";
|
|
||||||
import { useDownloader } from "../downloads";
|
|
||||||
import { MediaInfoPopup } from "./media-info";
|
|
||||||
import { watchListIcon } from "./watchlist-info";
|
|
||||||
|
|
||||||
export const EpisodesContext = ({
|
|
||||||
type = "episode",
|
|
||||||
slug,
|
|
||||||
showSlug,
|
|
||||||
status,
|
|
||||||
force,
|
|
||||||
...props
|
|
||||||
}: {
|
|
||||||
type?: "show" | "movie" | "episode";
|
|
||||||
showSlug?: string | null;
|
|
||||||
slug: string;
|
|
||||||
status: WatchStatusV | null;
|
|
||||||
force?: boolean;
|
|
||||||
} & Partial<ComponentProps<typeof Menu<typeof IconButton>>>) => {
|
|
||||||
const account = useAccount();
|
|
||||||
const downloader = useDownloader();
|
|
||||||
const { css } = useYoshiki();
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const [setPopup, close] = usePopup();
|
|
||||||
|
|
||||||
const queryClient = useQueryClient();
|
|
||||||
const mutation = useMutation({
|
|
||||||
mutationFn: (newStatus: WatchStatusV | null) =>
|
|
||||||
queryFn({
|
|
||||||
path: [type, slug, "watchStatus", newStatus && `?status=${newStatus}`],
|
|
||||||
method: newStatus ? "POST" : "DELETE",
|
|
||||||
}),
|
|
||||||
onSettled: async () => await queryClient.invalidateQueries({ queryKey: [type, slug] }),
|
|
||||||
});
|
|
||||||
|
|
||||||
const metadataRefreshMutation = useMutation({
|
|
||||||
mutationFn: () =>
|
|
||||||
queryFn({
|
|
||||||
path: [type, slug, "refresh"],
|
|
||||||
method: "POST",
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Menu
|
|
||||||
Trigger={IconButton}
|
|
||||||
icon={MoreVert}
|
|
||||||
{...tooltip(t("misc.more"))}
|
|
||||||
{...(css([Platform.OS !== "web" && !force && { display: "none" }], props) as any)}
|
|
||||||
>
|
|
||||||
{showSlug && (
|
|
||||||
<Menu.Item
|
|
||||||
label={t("home.episodeMore.goToShow")}
|
|
||||||
icon={Info}
|
|
||||||
href={`/show/${showSlug}`}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<Menu.Sub
|
|
||||||
label={account ? t("show.watchlistEdit") : t("show.watchlistLogin")}
|
|
||||||
disabled={!account}
|
|
||||||
icon={watchListIcon(status)}
|
|
||||||
>
|
|
||||||
{Object.values(WatchStatusV).map((x) => (
|
|
||||||
<Menu.Item
|
|
||||||
key={x}
|
|
||||||
label={t(`show.watchlistMark.${x.toLowerCase() as Lowercase<WatchStatusV>}`)}
|
|
||||||
onSelect={() => mutation.mutate(x)}
|
|
||||||
selected={x === status}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
{status !== null && (
|
|
||||||
<Menu.Item
|
|
||||||
label={t("show.watchlistMark.null")}
|
|
||||||
onSelect={() => mutation.mutate(null)}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</Menu.Sub>
|
|
||||||
{type !== "show" && (
|
|
||||||
<>
|
|
||||||
<Menu.Item
|
|
||||||
label={t("home.episodeMore.download")}
|
|
||||||
icon={Download}
|
|
||||||
onSelect={() => downloader(type, slug)}
|
|
||||||
/>
|
|
||||||
<Menu.Item
|
|
||||||
label={t("home.episodeMore.mediainfo")}
|
|
||||||
icon={MovieInfo}
|
|
||||||
onSelect={() =>
|
|
||||||
setPopup(<MediaInfoPopup mediaType={type} mediaSlug={slug} close={close} />)
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
{account?.isAdmin === true && (
|
|
||||||
<>
|
|
||||||
<HR />
|
|
||||||
<Menu.Item
|
|
||||||
label={t("home.refreshMetadata")}
|
|
||||||
icon={Refresh}
|
|
||||||
onSelect={() => metadataRefreshMutation.mutate()}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</Menu>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const ItemContext = ({
|
|
||||||
type,
|
|
||||||
slug,
|
|
||||||
status,
|
|
||||||
force,
|
|
||||||
...props
|
|
||||||
}: {
|
|
||||||
type: "movie" | "show";
|
|
||||||
slug: string;
|
|
||||||
status: WatchStatusV | null;
|
|
||||||
force?: boolean;
|
|
||||||
} & Partial<ComponentProps<typeof Menu<typeof IconButton>>>) => {
|
|
||||||
return (
|
|
||||||
<EpisodesContext
|
|
||||||
type={type}
|
|
||||||
slug={slug}
|
|
||||||
status={status}
|
|
||||||
showSlug={null}
|
|
||||||
force={force}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
|
@ -1,32 +1,13 @@
|
|||||||
/*
|
|
||||||
* 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 { WatchStatusV, queryFn, useAccount } from "@kyoo/models";
|
|
||||||
import { IconButton, Menu, tooltip } from "@kyoo/primitives";
|
|
||||||
import Bookmark from "@material-symbols/svg-400/rounded/bookmark-fill.svg";
|
import Bookmark from "@material-symbols/svg-400/rounded/bookmark-fill.svg";
|
||||||
import BookmarkAdd from "@material-symbols/svg-400/rounded/bookmark_add.svg";
|
import BookmarkAdd from "@material-symbols/svg-400/rounded/bookmark_add.svg";
|
||||||
import BookmarkAdded from "@material-symbols/svg-400/rounded/bookmark_added-fill.svg";
|
import BookmarkAdded from "@material-symbols/svg-400/rounded/bookmark_added-fill.svg";
|
||||||
import BookmarkRemove from "@material-symbols/svg-400/rounded/bookmark_remove.svg";
|
import BookmarkRemove from "@material-symbols/svg-400/rounded/bookmark_remove.svg";
|
||||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
||||||
import type { ComponentProps } from "react";
|
import type { ComponentProps } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { WatchStatusV } from "~/models";
|
||||||
|
import { IconButton, Menu, tooltip } from "~/primitives";
|
||||||
|
import { useAccount } from "~/providers/account-context";
|
||||||
|
import { useMutation } from "~/query";
|
||||||
|
|
||||||
export const watchListIcon = (status: WatchStatusV | null) => {
|
export const watchListIcon = (status: WatchStatusV | null) => {
|
||||||
switch (status) {
|
switch (status) {
|
||||||
@ -55,14 +36,13 @@ export const WatchListInfo = ({
|
|||||||
const account = useAccount();
|
const account = useAccount();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const queryClient = useQueryClient();
|
|
||||||
const mutation = useMutation({
|
const mutation = useMutation({
|
||||||
mutationFn: (newStatus: WatchStatusV | null) =>
|
path: [type, slug, "watchStatus"],
|
||||||
queryFn({
|
compute: (newStatus: WatchStatusV | null) => ({
|
||||||
path: [type, slug, "watchStatus", newStatus && `?status=${newStatus}`],
|
method: newStatus ? "POST" : "DELETE",
|
||||||
method: newStatus ? "POST" : "DELETE",
|
params: newStatus ? { status: newStatus } : undefined,
|
||||||
}),
|
}),
|
||||||
onSettled: async () => await queryClient.invalidateQueries({ queryKey: [type, slug] }),
|
invalidate: [type, slug],
|
||||||
});
|
});
|
||||||
if (mutation.isPending) status = mutation.variables;
|
if (mutation.isPending) status = mutation.variables;
|
||||||
|
|
||||||
@ -112,5 +92,11 @@ export const WatchListInfo = ({
|
|||||||
<Menu.Item label={t("show.watchlistMark.null")} onSelect={() => mutation.mutate(null)} />
|
<Menu.Item label={t("show.watchlistMark.null")} onSelect={() => mutation.mutate(null)} />
|
||||||
</Menu>
|
</Menu>
|
||||||
);
|
);
|
||||||
|
default:
|
||||||
|
return exhaustiveCheck(status);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function exhaustiveCheck(v: never): never {
|
||||||
|
return v;
|
||||||
|
}
|
@ -1,17 +1,11 @@
|
|||||||
import { type ComponentProps, useState } from "react";
|
import { type ComponentProps, useState } from "react";
|
||||||
import {
|
import { ItemGrid } from "~/components";
|
||||||
type LibraryItem,
|
import { type LibraryItem, LibraryItemP, getDisplayDate } from "~/models";
|
||||||
LibraryItemP,
|
import { InfiniteFetch, type QueryIdentifier, type QueryPage } from "~/query";
|
||||||
type QueryIdentifier,
|
|
||||||
type QueryPage,
|
|
||||||
getDisplayDate,
|
|
||||||
} from "~/models";
|
|
||||||
import { useQueryState } from "~/utils";
|
import { useQueryState } from "~/utils";
|
||||||
import { DefaultLayout } from "../../../packages/ui/src/layout";
|
import { DefaultLayout } from "../../../packages/ui/src/layout";
|
||||||
import { InfiniteFetch } from "../../query/fetch-infinite";
|
|
||||||
import { ItemGrid } from "~/components";
|
|
||||||
import { BrowseSettings } from "./header";
|
|
||||||
import { ItemList } from "../../components/item-list";
|
import { ItemList } from "../../components/item-list";
|
||||||
|
import { BrowseSettings } from "./header";
|
||||||
import {
|
import {
|
||||||
Layout,
|
Layout,
|
||||||
type MediaType,
|
type MediaType,
|
||||||
|
@ -16,3 +16,23 @@ export const useQueryState = <S>(key: string, initial: S) => {
|
|||||||
};
|
};
|
||||||
return [state, update] as const;
|
return [state, update] as const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getDisplayDate = (data: Show | Movie) => {
|
||||||
|
const {
|
||||||
|
startAir,
|
||||||
|
endAir,
|
||||||
|
airDate,
|
||||||
|
}: { startAir?: Date | null; endAir?: Date | null; airDate?: Date | null } = data;
|
||||||
|
|
||||||
|
if (startAir) {
|
||||||
|
if (!endAir || startAir.getFullYear() === endAir.getFullYear()) {
|
||||||
|
return startAir.getFullYear().toString();
|
||||||
|
}
|
||||||
|
return startAir.getFullYear() + (endAir ? ` - ${endAir.getFullYear()}` : "");
|
||||||
|
}
|
||||||
|
if (airDate) {
|
||||||
|
return airDate.getFullYear().toString();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
"types": [
|
"types": [
|
||||||
"node",
|
"node",
|
||||||
"react",
|
"react",
|
||||||
"vite/client"
|
|
||||||
],
|
],
|
||||||
"lib": [
|
"lib": [
|
||||||
"dom",
|
"dom",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user