From 53f042a453f7cdd8a2dc19903c5f8c793c05eb4e Mon Sep 17 00:00:00 2001 From: prayag17 Date: Mon, 24 Apr 2023 14:49:05 +0530 Subject: [PATCH] Display songs in libView and update titlePage #9 #26 --- src/App.jsx | 11 -- src/components/card/card.jsx | 16 +- src/components/card/episodeCard.jsx | 15 +- src/components/menu/sidemenu.jsx | 1 - src/routes/home/index.jsx | 5 +- src/routes/item/index.jsx | 234 ++++++++++++++++++++----- src/routes/item/item.module.scss | 7 +- src/routes/library/index.jsx | 155 +++++++++++++--- src/routes/library/library.module.scss | 36 ++++ src/utils/date/time.js | 14 +- 10 files changed, 391 insertions(+), 103 deletions(-) create mode 100644 src/routes/library/library.module.scss diff --git a/src/App.jsx b/src/App.jsx index f8ff92a..6903f9a 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -137,13 +137,8 @@ function App() { const server = await getServer(); if (server == null) { - console.log("server not found"); return false; } else { - // if (!window.api) { - // console.log("Creating Jf api (without accessToken)"); - // event.emit("create-jellyfin-api", server.Ip); - // } return true; } }; @@ -159,7 +154,6 @@ function App() { const userSaved = async () => { const user = await getUser(); - console.log("User store => ", user); if (user == null) { return false; } else { @@ -189,7 +183,6 @@ function App() { }) .catch((error) => { setServerReachable(false); - console.error(error); setChecking(false); }); }; @@ -253,22 +246,18 @@ function App() { const handleRelaunch = async () => { let result = await relaunch(); - console.log(result); }; const handleRemoveServer = async () => { await delServer(); await delUser(); let result = await relaunch(); - console.log(result); }; const location = useLocation(); if (!window.api) { - console.log("WindowAPi not present"); serverAvailable().then((available) => { if (available) { - console.log(available); createApi().then( userSaved().then((userSavedBool) => { if (userSavedBool) { diff --git a/src/components/card/card.jsx b/src/components/card/card.jsx index ca54159..2741f35 100644 --- a/src/components/card/card.jsx +++ b/src/components/card/card.jsx @@ -51,7 +51,7 @@ export const Card = ({ const navigate = useNavigate(); const [imgLoading, setImgLoading] = useState(true); const [isWatched, setIsWatched] = useState(watchedStatus); - const [isFavourite, setIsFavourite] = useState(favourite); + const [isFavorite, setisFavorite] = useState(favourite); const [watchedCountState, setWatchedCountState] = useState(watchedCount); const handleMarkAsPlayOrUnMarkAsPlay = async () => { let result; @@ -71,18 +71,18 @@ export const Card = ({ }; const handleLiking = async () => { let result; - if (isFavourite) { + if (isFavorite) { result = await getUserLibraryApi(window.api).unmarkFavoriteItem({ userId: currentUser.Id, itemId: itemId, }); - } else if (!isFavourite) { + } else if (!isFavorite) { result = await getUserLibraryApi(window.api).markFavoriteItem({ userId: currentUser.Id, itemId: itemId, }); } - setIsFavourite(result.data.IsFavorite); + setisFavorite(result.data.IsFavorite); }; const availableMarkButtonTypes = [ @@ -214,7 +214,7 @@ export const Card = ({ window.api.basePath + "/Items/" + itemId + - "/Images/Primary" + "/Images/Primary?fillHeight=532&fillWidth=300&quality=96" } alt={itemName} sx={{ @@ -240,8 +240,8 @@ export const Card = ({ hash={blurhash} width="100%" height="100%" - resolutionX={64} - resolutionY={64} + resolutionX={24} + resolutionY={24} style={{ aspectRatio: cardOrientation == "landscape" @@ -311,7 +311,7 @@ export const Card = ({ handleLiking(); }} > - {isFavourite ? ( + {isFavorite ? ( diff --git a/src/components/card/episodeCard.jsx b/src/components/card/episodeCard.jsx index 986cd59..b757c06 100644 --- a/src/components/card/episodeCard.jsx +++ b/src/components/card/episodeCard.jsx @@ -56,7 +56,6 @@ export const EpisodeCard = ({ parentId, }) => { const navigate = useNavigate(); - const [imgLoading, setImgLoading] = useState(true); const [isWatched, setIsWatched] = useState(watchedStatus); const [isFavourite, setIsFavourite] = useState(favourite); const handleMarkAsPlayOrUnMarkAsPlay = async () => { @@ -72,7 +71,6 @@ export const EpisodeCard = ({ itemId: itemId, }); } - console.log(result.data); setIsWatched(result.data.Played); }; const handleLiking = async () => { @@ -88,7 +86,6 @@ export const EpisodeCard = ({ itemId: itemId, }); } - console.log(result.data.IsFavorite); setIsFavourite(result.data.IsFavorite); }; @@ -132,13 +129,10 @@ export const EpisodeCard = ({ opacity: isWatched ? 1 : 0, }} /> - + {imageTags && ( setImgLoading(false)} className="card-image" > )} @@ -163,8 +156,8 @@ export const EpisodeCard = ({ hash={blurhash} width="100%" height="100%" - resolutionX={512} - resolutionY={910} + resolutionX={12} + resolutionY={18} style={{ aspectRatio: "1.777", }} diff --git a/src/components/menu/sidemenu.jsx b/src/components/menu/sidemenu.jsx index d0de1dc..686e9d0 100644 --- a/src/components/menu/sidemenu.jsx +++ b/src/components/menu/sidemenu.jsx @@ -101,7 +101,6 @@ export const SideMenu = ({}) => { }; useEffect(() => { - console.log(location.pathname.includes("login")); if ( location.pathname.includes("login") || location.pathname.includes("setup") diff --git a/src/routes/home/index.jsx b/src/routes/home/index.jsx index d6fc634..e09cb59 100644 --- a/src/routes/home/index.jsx +++ b/src/routes/home/index.jsx @@ -253,7 +253,6 @@ const Home = () => { // <> latestMedia.data != null && latestMedia.data.map((item, index) => { - // console.log(item); return ( { width="1080" height="720" resolutionX={ - 720 + 64 } resolutionY={ - 1080 + 96 } className="hero-carousel-background-blurhash" /> diff --git a/src/routes/item/index.jsx b/src/routes/item/index.jsx index b929137..1787414 100644 --- a/src/routes/item/index.jsx +++ b/src/routes/item/index.jsx @@ -21,6 +21,8 @@ import TableHead from "@mui/material/TableHead"; import TableRow from "@mui/material/TableRow"; import TableBody from "@mui/material/TableBody"; import TableCell from "@mui/material/TableCell"; +import TextField from "@mui/material/TextField"; +import MenuItem from "@mui/material/MenuItem"; import { green, pink } from "@mui/material/colors"; import { AvatarImage } from "../../components/avatar/avatar"; @@ -37,6 +39,7 @@ import { getLibraryApi } from "@jellyfin/sdk/lib/utils/api/library-api"; import { getTvShowsApi } from "@jellyfin/sdk/lib/utils/api/tv-shows-api"; import { getItemsApi } from "@jellyfin/sdk/lib/utils/api/items-api"; import { getPlaystateApi } from "@jellyfin/sdk/lib/utils/api/playstate-api"; +import { getVideosApi } from "@jellyfin/sdk/lib/utils/api/videos-api"; import { useQuery } from "@tanstack/react-query"; @@ -303,6 +306,18 @@ const ItemDetail = () => { networkMode: "always", }); + // const videoStreams = useQuery({ + // queryKey: ["item", id, "videoTracks"], + // queryFn: async () => { + // const result = await getVideosApi(window.api).getVideoStream({ + // itemId: item.data.Id, + // }); + // return result.data; + // }, + // enabled: item.isSuccess, + // networkMode: "always", + // }); + const handleMarkPlayedOrunPlayed = async () => { let result; if (!item.data.UserData.Played) { @@ -325,7 +340,6 @@ const ItemDetail = () => { userId: user.data.Id, itemId: item.data.Id, }); - console.log(result.statusText); } else if (!item.data.UserData.IsFavorite) { result = await getUserLibraryApi(window.api).markFavoriteItem({ userId: user.data.Id, @@ -341,7 +355,6 @@ const ItemDetail = () => { userId: user.data.Id, itemId: track.Id, }); - console.log(result.statusText); } else if (!track.UserData.IsFavorite) { result = await getUserLibraryApi(window.api).markFavoriteItem({ userId: user.data.Id, @@ -412,8 +425,8 @@ const ItemDetail = () => { } width="100%" height="100%" - resolutionX={64} - resolutionY={96} + resolutionX={14} + resolutionY={22} style={{ aspectRatio: "0.666", }} @@ -436,25 +449,50 @@ const ItemDetail = () => { > - {item.data.BackdropImageTags.length != 0 && ( - - setBackdropImageLoaded(true) - } - /> - )} + {item.data.Type != BaseItemKind.MusicAlbum + ? item.data.BackdropImageTags.length != + 0 && ( + + setBackdropImageLoaded( + true, + ) + } + /> + ) + : !!item.data.ParentBackdropItemId && ( + + setBackdropImageLoaded( + true, + ) + } + /> + )} {item.data.BackdropImageTags.length != 0 && ( { } width="100%" height="100%" - resolutionX={64} - resolutionY={96} + resolutionX={12} + resolutionY={18} style={{ aspectRatio: "0.666", }} @@ -522,7 +560,7 @@ const ItemDetail = () => { window.api.basePath + "/Items/" + item.data.Id + - "/Images/Primary?quality=10" + "/Images/Primary?fillHeight=532&fillWidth=300&quality=96" } style={{ opacity: primageImageLoaded @@ -549,8 +587,8 @@ const ItemDetail = () => { } width="100%" height="100%" - resolutionX={64} - resolutionY={96} + resolutionX={12} + resolutionY={8} style={{ aspectRatio: 0.666, }} @@ -773,7 +811,7 @@ const ItemDetail = () => { {item.data.Genres != 0 && ( - + { > Artists - {item.data.Artists.map((mitem, mindex) => { - return ( - - {mitem} + + , - ); - })} + } + > + {item.data.Artists.map( + (mitem, mindex) => { + return ( + + {mitem} + + ); + }, + )} + )} + {!!item.data.MediaStreams && + item.data.MediaStreams.length != 0 && ( + <> + + + + Video + + + {item.data.MediaStreams.map( + ( + stream, + sindex, + ) => { + if ( + stream.Type == + BaseItemKind.Video + ) + return ( + + { + stream.DisplayTitle + } + + ); + }, + )} + + + + + + + Audio + + + {item.data.MediaStreams.map( + ( + stream, + sindex, + ) => { + if ( + stream.Type == + BaseItemKind.Audio + ) + return ( + + { + stream.DisplayTitle + } + + ); + }, + )} + + + + + )} + {!!item.data.Overview && ( @@ -1558,11 +1711,6 @@ const ItemDetail = () => { .UserData .Played } - watchedCount={ - mitem - .UserData - .PlayCount - } blurhash={ mitem.ImageBlurHashes == {} diff --git a/src/routes/item/item.module.scss b/src/routes/item/item.module.scss index e5005bc..270d8e2 100644 --- a/src/routes/item/item.module.scss +++ b/src/routes/item/item.module.scss @@ -39,10 +39,11 @@ } } &-image { + position: absolute; width: 100%; height: 100%; object-fit: cover; - position: absolute; + object-position: top; transition: opacity $transition-time-default; &-blurhash { z-index: -1; @@ -71,8 +72,8 @@ } &-title-logo { filter: drop-shadow(0 0 10px rgb(0 0 0 /0.2)); - max-width: 75%; - height: 2em; + height: 100%; + width: 45%; object-fit: contain; object-position: bottom; } diff --git a/src/routes/library/index.jsx b/src/routes/library/index.jsx index 54270b6..11bfdb6 100644 --- a/src/routes/library/index.jsx +++ b/src/routes/library/index.jsx @@ -24,10 +24,17 @@ import Accordion from "@mui/material/Accordion"; import AccordionSummary from "@mui/material/AccordionSummary"; import AccordionDetails from "@mui/material/AccordionDetails"; import Button from "@mui/material/Button"; +import Paper from "@mui/material/Paper"; +import Table from "@mui/material/Table"; +import TableContainer from "@mui/material/TableContainer"; +import TableRow from "@mui/material/TableRow"; +import TableCell from "@mui/material/TableCell"; +import IconButton from "@mui/material/IconButton"; import { theme } from "../../theme"; import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api"; +import { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api/user-library-api"; import { getItemsApi } from "@jellyfin/sdk/lib/utils/api/items-api"; import { getArtistsApi } from "@jellyfin/sdk/lib/utils/api/artists-api"; import { getGenresApi } from "@jellyfin/sdk/lib/utils/api/genres-api"; @@ -45,6 +52,16 @@ import { MdiFilterOutline } from "../../components/icons/mdiFilterOutline"; import { clrBackgroundDarkOpacity0_8 } from "../../palette.module.scss"; import { ErrorNotice } from "../../components/notices/errorNotice/errorNotice"; +import { + BaseItemKind, + CollectionTypeOptions, +} from "@jellyfin/sdk/lib/generated-client"; +import { getRuntimeMusic } from "../../utils/date/time"; + +import "./library.module.scss"; +import { MdiMusic } from "../../components/icons/mdiMusic"; +import { MdiHeart } from "../../components/icons/mdiHeart"; +import { MdiHeartOutline } from "../../components/icons/mdiHeartOutline"; const LibraryView = () => { const navigate = useNavigate(); @@ -64,12 +81,17 @@ const LibraryView = () => { }, }); - const [sortAscending, setSortAscending] = useState(false); + const [sortAscending, setSortAscending] = useState(true); const [sortBy, setSortBy] = useState("SortName"); const [sortByData, setSortByData] = useState([ { title: "Name", value: "SortName" }, + { title: "Critic Rating", value: "CriticRating" }, { title: "Rating", value: "CommunityRating" }, { title: "Release Date", value: "PremiereDate" }, + { title: "Date Added", value: "DateCreated" }, + { title: "Play Count", value: "PlayCount" }, + { title: "Runtime", value: "Runtime" }, + { title: "Random", value: "Random" }, ]); const handleSortChange = (e) => { setSortAscending(e.target.checked); @@ -98,7 +120,7 @@ const LibraryView = () => { const [isPlayed, setIsPlayed] = useState(false); const [isUnPlayed, setIsUnPlayed] = useState(false); const [isResumable, setIsResumable] = useState(false); - const [isFavourite, setIsFavourite] = useState(false); + const [isFavorite, setisFavorite] = useState(false); const [isLiked, setIsLiked] = useState(false); const [isUnliked, setIsUnliked] = useState(false); const availableWatchStatus = [ @@ -120,7 +142,7 @@ const LibraryView = () => { { title: "Favourite", value: false, - state: (val) => setIsFavourite(val), + state: (val) => setisFavorite(val), }, { title: "Liked", @@ -186,26 +208,27 @@ const LibraryView = () => { if (currentLib.isSuccess) { if (currentLib.data.Items[0].CollectionType == "movies") { setViewType([ - { title: "Movies", value: "Movie" }, - { title: "Collections", value: "BoxSet" }, - { title: "Actors", value: "Person" }, - { title: "Genres", value: "Genre" }, - { title: "Studios", value: "Studio" }, + { title: "Movies", value: BaseItemKind.Movie }, + { title: "Collections", value: BaseItemKind.BoxSet }, + { title: "Actors", value: BaseItemKind.Person }, + { title: "Genres", value: BaseItemKind.Genre }, + { title: "Studios", value: BaseItemKind.Studio }, ]); } else if (currentLib.data.Items[0].CollectionType == "music") { setViewType([ - { title: "Albums", value: "MusicAlbum" }, - { title: "Artists", value: "MusicArtist" }, - { title: "Genres", value: "MusicGenre" }, + { title: "Songs", value: BaseItemKind.Audio }, + { title: "Albums", value: BaseItemKind.MusicAlbum }, + { title: "Artists", value: BaseItemKind.MusicArtist }, + { title: "Genres", value: BaseItemKind.MusicGenre }, ]); } else if ( currentLib.data.Items[0].CollectionType == "tvshows" ) { setViewType([ - { title: "Series", value: "Series" }, - { title: "Actors", value: "Person" }, - { title: "Genres", value: "Genre" }, - { title: "Networks", value: "Studio" }, + { title: "Series", value: BaseItemKind.Series }, + { title: "Actors", value: BaseItemKind.Person }, + { title: "Genres", value: BaseItemKind.Genre }, + { title: "Networks", value: BaseItemKind.Studio }, ]); } else { setViewType([]); @@ -260,7 +283,7 @@ const LibraryView = () => { isPlayed && "IsPlayed", isUnPlayed && "IsUnplayed", isResumable && "IsResumable", - isFavourite && "IsFavorite", + isFavorite && "IsFavorite", isLiked && "IsFavoriteOrLikes", isUnliked && "Dislikes", ], @@ -291,7 +314,7 @@ const LibraryView = () => { isPlayed, isUnPlayed, isResumable, - isFavourite, + isFavorite, isLiked, isUnliked, ], @@ -343,6 +366,22 @@ const LibraryView = () => { threshold: 1, }); + const handleLiking = async (item) => { + let result; + if (item.UserData.isFavorite) { + result = await getUserLibraryApi(window.api).unmarkFavoriteItem({ + userId: user.data.Id, + itemId: item.Id, + }); + } else if (!item.UserData.isFavorite) { + result = await getUserLibraryApi(window.api).markFavoriteItem({ + userId: user.data.Id, + itemId: item.Id, + }); + } + items.refetch(); + }; + return ( { checkedIcon={ } - color="white" - onChange={handleSortChange} - defaultValue={sortAscending} sx={{ color: "white !important", }} + color="white" + onChange={handleSortChange} + defaultValue={sortAscending} /> { {items.isSuccess && (items.data.TotalRecordCount == 0 ? ( - ) : ( + ) : currentViewType != BaseItemKind.Audio ? ( { ); })} + ) : ( + + + {items.data.Items.map((item, index) => { + return ( + + + + {!!item + .ImageTags + .Primary && ( + + )} + + + + + + + + {item.Name} + + + {item.Album} + + + + + {getRuntimeMusic( + item.RunTimeTicks, + )} + + + + { + handleLiking( + item, + ); + }} + > + {item.UserData + .IsFavorite ? ( + + ) : ( + + )} + + + + ); + })} +
+
))} {items.isError && }
diff --git a/src/routes/library/library.module.scss b/src/routes/library/library.module.scss new file mode 100644 index 0000000..6b026e3 --- /dev/null +++ b/src/routes/library/library.module.scss @@ -0,0 +1,36 @@ +/** @format */ +.library-list { + &-image { + position: relative; + width: 100%; + height: 100%; + z-index: 1; + object-fit: cover; + &-container { + position: relative; + width: 4.5em; + height: 4.5em; + aspect-ratio: 1; + border-radius: $border-radius-intensity-1; + overflow: hidden; + box-shadow: 0 2px 7px rgb(0 0 0 / 0.2); + } + } + &-icon { + font-size: 3em; + fill: url(#clr-gradient-default) !important; + + &-container { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + display: flex; + justify-content: center; + align-items: center; + z-index: 0; + background: $clr-gradient-dark; + } + } +} diff --git a/src/utils/date/time.js b/src/utils/date/time.js index 25faac2..1160ca6 100644 --- a/src/utils/date/time.js +++ b/src/utils/date/time.js @@ -40,12 +40,22 @@ export const getRuntimeMusic = (ticks) => { let timeSec = Math.floor(time / 1000); let timeMin = Math.floor(timeSec / 60); timeSec -= timeMin * 60; + timeSec = timeSec == 0 ? 0o0 : timeSec; if (timeMin > 60) { let timeHr = Math.floor(timeMin / 60); timeMin -= timeHr * 60; - formatedTime = `${timeHr}:${timeMin}`; + formatedTime = `${timeHr}:${timeMin.toLocaleString([], { + minimumIntegerDigits: 2, + useGrouping: false, + })}:${timeSec.toLocaleString([], { + minimumIntegerDigits: 2, + useGrouping: false, + })}`; } else { - formatedTime = `${timeMin}:${timeSec}`; + formatedTime = `${timeMin}:${timeSec.toLocaleString([], { + minimumIntegerDigits: 2, + useGrouping: false, + })}`; } return formatedTime; };