From e2414f94f34e3931c96bb6bdb8aa67723d04f207 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Wed, 6 Dec 2023 15:11:50 +0100 Subject: [PATCH] Add movie watch percent progress bar --- .../Repositories/WatchStatusRepository.cs | 1 + front/packages/primitives/src/image/index.tsx | 4 ++- front/packages/ui/src/browse/grid.tsx | 32 +++++++++++++++++++ front/packages/ui/src/browse/index.tsx | 3 ++ front/packages/ui/src/details/episode.tsx | 22 ++----------- front/packages/ui/src/home/news.tsx | 3 ++ front/packages/ui/src/home/watchlist.tsx | 3 ++ 7 files changed, 47 insertions(+), 21 deletions(-) diff --git a/back/src/Kyoo.Core/Controllers/Repositories/WatchStatusRepository.cs b/back/src/Kyoo.Core/Controllers/Repositories/WatchStatusRepository.cs index d4559cf5..b5e89be3 100644 --- a/back/src/Kyoo.Core/Controllers/Repositories/WatchStatusRepository.cs +++ b/back/src/Kyoo.Core/Controllers/Repositories/WatchStatusRepository.cs @@ -233,6 +233,7 @@ public class WatchStatusRepository : IWatchStatusRepository MovieId = movieId, Status = status, WatchedTime = watchedTime, + WatchedPercent = percent, AddedDate = DateTime.UtcNow, PlayedDate = status == WatchStatus.Completed ? DateTime.UtcNow : null, }; diff --git a/front/packages/primitives/src/image/index.tsx b/front/packages/primitives/src/image/index.tsx index 6fe56f97..8ae5f182 100644 --- a/front/packages/primitives/src/image/index.tsx +++ b/front/packages/primitives/src/image/index.tsx @@ -64,6 +64,7 @@ export const ImageBackground = ({ imageStyle, forcedLoading, hideLoad = true, + contrast = "dark", layout, ...asProps }: { @@ -73,12 +74,13 @@ export const ImageBackground = ({ containerStyle?: YoshikiEnhanced; imageStyle?: YoshikiEnhanced; hideLoad?: boolean; + contrast?: "light" | "dark" | "user"; layout?: ImageLayout; } & AsProps & Props) => { const Container = as ?? View; return ( - + {({ css, theme }) => ( { + const { css } = useYoshiki("episodebox"); + + return ( + <> + theme.user.overlay0, + width: percent(100), + height: ts(0.5), + position: "absolute", + bottom: 0, + })} + /> + theme.user.accent, + width: percent(watchPercent), + height: ts(0.5), + position: "absolute", + bottom: 0, + })} + /> + + ); +}; + export const ItemGrid = ({ href, name, + type, subtitle, poster, isLoading, watchStatus, + watchPercent, unseenEpisodesCount, ...props }: WithLoading<{ @@ -80,6 +109,8 @@ export const ItemGrid = ({ subtitle?: string; poster?: KyooImage | null; watchStatus: WatchStatusV | null; + watchPercent: number | null; + type: "movie" | "show" | "collection"; unseenEpisodesCount: number | null; }> & Stylable<"text">) => { @@ -122,6 +153,7 @@ export const ItemGrid = ({ {...(css("poster") as { style: ImageStyle })} > + {type === "movie" && watchPercent && } {isLoading || ( diff --git a/front/packages/ui/src/browse/index.tsx b/front/packages/ui/src/browse/index.tsx index 78cc2a63..a98534d8 100644 --- a/front/packages/ui/src/browse/index.tsx +++ b/front/packages/ui/src/browse/index.tsx @@ -51,6 +51,9 @@ export const itemMap = ( poster: item.poster, thumbnail: item.thumbnail, watchStatus: item.kind !== ItemKind.Collection ? item.watchStatus?.status ?? null : null, + type: item.kind.toLowerCase() as any, + watchPercent: + item.kind !== ItemKind.Collection ? item.watchStatus?.watchedPercent ?? null : null, unseenEpisodesCount: item.kind === ItemKind.Show ? item.watchStatus?.unseenEpisodesCount ?? item.episodesCount! diff --git a/front/packages/ui/src/details/episode.tsx b/front/packages/ui/src/details/episode.tsx index 82927f62..fa4f93d6 100644 --- a/front/packages/ui/src/details/episode.tsx +++ b/front/packages/ui/src/details/episode.tsx @@ -34,6 +34,7 @@ import { ImageStyle, View } from "react-native"; import { Layout, WithLoading } from "../fetch"; import { percent, rem, Stylable, Theme, useYoshiki } from "yoshiki/native"; import { KyooImage, WatchStatusV } from "@kyoo/models"; +import { ItemProgress } from "../browse/grid"; export const episodeDisplayNumber = ( episode: { @@ -112,26 +113,7 @@ export const EpisodeBox = ({ {...(css("poster") as any)} > {(watchedPercent || watchedStatus === WatchStatusV.Completed) && ( - <> - theme.overlay0, - width: percent(100), - height: ts(0.5), - position: "absolute", - bottom: 0, - })} - /> - theme.accent, - width: percent(watchedPercent ?? 100), - height: ts(0.5), - position: "absolute", - bottom: 0, - })} - /> - + )} diff --git a/front/packages/ui/src/home/news.tsx b/front/packages/ui/src/home/news.tsx index 47e5d30d..d77cb897 100644 --- a/front/packages/ui/src/home/news.tsx +++ b/front/packages/ui/src/home/news.tsx @@ -49,6 +49,9 @@ export const NewsList = () => { name={x.name!} subtitle={!x.isLoading ? getDisplayDate(x) : undefined} poster={x.poster} + watchStatus={x.watchStatus?.status || null} + watchPercent={x.watchStatus?.watchedPercent || null} + type={"movie"} /> ) : ( { name={x.name!} subtitle={!x.isLoading ? getDisplayDate(x) : undefined} poster={x.poster} + watchStatus={x.watchStatus?.status || null} + watchPercent={x.watchStatus?.watchedPercent || null} + type={x.kind === WatchlistKind.Movie ? "movie" : "show"} /> ); }}