From f549d6430f15b7dcf2f97cd1593ee3960d829c44 Mon Sep 17 00:00:00 2001 From: Prayag Prajapati Date: Tue, 19 Sep 2023 15:18:39 +0530 Subject: [PATCH] Addd ArtistTitlePage #160 --- package.json | 1 + pnpm-lock.yaml | 23 + src/App.jsx | 9 +- src/components/buttons/playButton.jsx | 17 + .../layouts/artist/albumArtist.scss | 26 +- src/components/layouts/artist/artistAlbum.jsx | 299 ++++++----- .../homeSection/latestMediaSection.jsx | 1 + src/components/layouts/item/hero.jsx | 84 +-- src/components/musicTrack/index.jsx | 124 +++++ .../musicTrack/musicTrack.module.scss | 40 ++ .../audioPlayer/audioPlayer.module.scss | 1 - src/components/playback/audioPlayer/index.jsx | 76 ++- src/components/textLink/index.jsx | 3 +- src/routes/album/index.jsx | 16 +- src/routes/artist/artist.module.scss | 22 + src/routes/artist/index.jsx | 497 ++++++++++++++++++ src/routes/person/index.jsx | 45 +- 17 files changed, 1050 insertions(+), 234 deletions(-) create mode 100644 src/components/musicTrack/index.jsx create mode 100644 src/components/musicTrack/musicTrack.module.scss create mode 100644 src/routes/artist/artist.module.scss diff --git a/package.json b/package.json index 26e2faa..987943c 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "react-player": "^2.12.0", "react-router-dom": "^6.14.0", "react-use-konami": "^1.1.0", + "react-virtualized": "^9.22.5", "tauri-plugin-log-api": "github:tauri-apps/tauri-plugin-log#v1", "tauri-plugin-store-api": "github:tauri-apps/tauri-plugin-store", "uuid": "^9.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7a5954a..bd996c0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -74,6 +74,9 @@ dependencies: react-use-konami: specifier: ^1.1.0 version: 1.1.0(react-dom@18.2.0)(react@18.2.0) + react-virtualized: + specifier: ^9.22.5 + version: 9.22.5(react-dom@18.2.0)(react@18.2.0) tauri-plugin-log-api: specifier: github:tauri-apps/tauri-plugin-log#v1 version: github.com/tauri-apps/tauri-plugin-log/9075595196d5a66f8f3265d2aaf7e2ffeb4cb2ab @@ -1823,6 +1826,10 @@ packages: resolution: {integrity: sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w==} dev: false + /react-lifecycles-compat@3.0.4: + resolution: {integrity: sha512-fBASbA6LnOU9dOU2eW7aQ8xmYBSXUIWr+UmF9b1efZBazGNO+rcXT/icdKnYm2pTwcRylVUYwW7H1PHfLekVzA==} + dev: false + /react-multi-carousel@2.8.4: resolution: {integrity: sha512-7Is5Wr+m2ebkR+oq2Su2tjUdBwpVtB2O6Tjb74KDNfxWe/FrsTQwezTJTk/r9cKCrRp9Li308v822/5bZm7XKg==} engines: {node: '>=8'} @@ -1893,6 +1900,22 @@ packages: react-dom: 18.2.0(react@18.2.0) dev: false + /react-virtualized@9.22.5(react-dom@18.2.0)(react@18.2.0): + resolution: {integrity: sha512-YqQMRzlVANBv1L/7r63OHa2b0ZsAaDp1UhVNEdUaXI8A5u6hTpA5NYtUueLH2rFuY/27mTGIBl7ZhqFKzw18YQ==} + peerDependencies: + react: ^15.3.0 || ^16.0.0-alpha || ^17.0.0 || ^18.0.0 + react-dom: ^15.3.0 || ^16.0.0-alpha || ^17.0.0 || ^18.0.0 + dependencies: + '@babel/runtime': 7.22.15 + clsx: 1.2.1 + dom-helpers: 5.2.1 + loose-envify: 1.4.0 + prop-types: 15.8.1 + react: 18.2.0 + react-dom: 18.2.0(react@18.2.0) + react-lifecycles-compat: 3.0.4 + dev: false + /react@18.2.0: resolution: {integrity: sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==} engines: {node: '>=0.10.0'} diff --git a/src/App.jsx b/src/App.jsx index b029c0e..155ebe9 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -78,6 +78,7 @@ import PersonTitlePage from "./routes/person/index.jsx"; import MusicAlbumTitlePage from "./routes/album/index.jsx"; import AudioPlayer from "./components/playback/audioPlayer/index.jsx"; import { useAudioPlayback } from "./utils/store/audioPlayback.js"; +import ArtistTitlePage from "./routes/artist/index.jsx"; const jellyfin = new Jellyfin({ clientInfo: { @@ -281,7 +282,9 @@ function App() { }); } - const [audioPlayerVisible] = useAudioPlayback((state) => [state.display]); + const [audioPlayerVisible, currentAudioIndex] = useAudioPlayback( + (state) => [state.display, state.currentTrack], + ); const [backdropUrl, backdropId] = useBackdropStore((state) => [ state.backdropUrl, @@ -428,7 +431,7 @@ function App() { - + }> } + element={} /> { const navigate = useNavigate(); const [ @@ -94,6 +95,19 @@ const PlayButton = ({ sortOrder: SortOrder.Ascending, sortBy: "IndexNumber", }); + } else if (itemType == BaseItemKind.MusicArtist) { + result = await getItemsApi(window.api).getItems({ + artistIds: [itemId], + recursive: true, + includeItemTypes: [BaseItemKind.Audio], + userId: userId, + fields: [ + ItemFields.MediaSources, + ItemFields.MediaStreams, + ], + sortOrder: SortOrder.Ascending, + sortBy: ["PremiereDate", "ProductionYear", "SortName"], + }); } else { result = await getItemsApi(window.api).getItems({ ids: [itemId], @@ -109,6 +123,7 @@ const PlayButton = ({ return result.data; }, onSuccess: (item) => { + console.log(item); if (audio) { setAudioTracks(item.Items); setAudioUrl( @@ -156,6 +171,7 @@ const PlayButton = ({ className={className} onClick={handleClick} sx={sx} + size={size} {...buttonProps} > @@ -173,6 +189,7 @@ const PlayButton = ({ position: "relative", overflow: "hidden", }} + size={size} > { const albumTracks = useQuery({ @@ -37,9 +40,12 @@ export const ArtistAlbum = ({ user, album, boxProps }) => { const result = await getItemsApi(window.api).getItems({ userId: user.Id, parentId: album.Id, + sortOrder: SortOrder.Ascending, + sortBy: "IndexNumber", }); return result.data; }, + networkMode: "always", }); @@ -61,22 +67,43 @@ export const ArtistAlbum = ({ user, album, boxProps }) => { const [imgLoaded, setImgLoaded] = useState(false); + const [ + currentTrackItem, + setCurrentAudioTrack, + setAudioUrl, + setAudioDisplay, + setAudioItem, + setAudioTracks, + ] = useAudioPlayback((state) => [ + state.item, + state.setCurrentTrack, + state.setUrl, + state.setDisplay, + state.setItem, + state.setTracks, + ]); + const playTrack = (index) => { + setAudioTracks(albumTracks.data.Items); + setCurrentAudioTrack(index); + setAudioUrl( + `${window.api.basePath}/Audio/${albumTracks.data.Items[index].Id}/universal?deviceId=${window.api.deviceInfo.id}&userId=${user.Id}&api_key=${window.api.accessToken}`, + ); + setAudioItem(albumTracks.data.Items[index]); + setAudioDisplay(true); + }; + return ( - - +
+
{!!album.ImageTags?.Primary && ( - +
{ }} onLoad={() => setImgLoaded(true)} /> - +
- - +
+
)} {album.ProductionYear} { {album.Name} - +
- - - +
- - + # + +
+ { + console.log("Hvnrjn"); + }} + > + Name + + +
+ {albumTracks.data.Items.map((track, index) => { + return ( +
playTrack(index)} > - # - - - - - Name + + {!!track.IndexNumber + ? track.IndexNumber + : "-"} - - - - - - - - - - {albumTracks.isSuccess && - albumTracks.data.Items.map( - (mitem, mindex) => { - return ( - + +
+ + {track.Name} + + {track.AlbumArtist == + "Various Artists" && ( + - - - { - mitem.IndexNumber - } - - - - - handleLikingTrack( - mitem, - ) - } - > - {mitem.UserData - .IsFavorite ? ( - - ) : ( - - )} - - - - - {mitem.Name} - - - - - {getRuntimeMusic( - mitem.RunTimeTicks, - )} - - - - ); - }, - )} - -
-
- + {track.ArtistItems.map( + (artist) => + artist.Name, + ).join(", ")} + + )} +
+ + {getRuntimeMusic( + track.RunTimeTicks, + )} + + + ); + })} + + )} + ); }; diff --git a/src/components/layouts/homeSection/latestMediaSection.jsx b/src/components/layouts/homeSection/latestMediaSection.jsx index 7a7fcf9..ec59ecd 100644 --- a/src/components/layouts/homeSection/latestMediaSection.jsx +++ b/src/components/layouts/homeSection/latestMediaSection.jsx @@ -84,6 +84,7 @@ export const LatestMediaSection = ({ latestMediaLib }) => { ]} userId={user.data.Id} imageBlurhash={ + !!item.ImageBlurHashes?.Primary && item.ImageBlurHashes?.Primary[ Object.keys( item.ImageBlurHashes.Primary, diff --git a/src/components/layouts/item/hero.jsx b/src/components/layouts/item/hero.jsx index 0504b24..97254a7 100644 --- a/src/components/layouts/item/hero.jsx +++ b/src/components/layouts/item/hero.jsx @@ -205,15 +205,19 @@ const Hero = ({ )} {!!albumBy && ( - By {albumBy} - + )} {!disableInfoStrip && ( @@ -550,22 +554,21 @@ const Hero = ({ {writers.map((writer, index) => ( <> - - ,{" "} - + {index != + writers.length - 1 && ( + + ,{" "} + + )} ))} @@ -595,13 +598,17 @@ const Hero = ({ variant={"subtitle1"} location={`/person/${director.Id}`} /> - - ,{" "} - + {index != + directors.length - 1 && ( + + ,{" "} + + )} ))} @@ -623,11 +630,28 @@ const Hero = ({ > Artists - - {artists - .map((artist) => artist.Name) - .join(", ")} - +
+ {artists.map((artist, index) => ( + <> + + {index != + artists.length - 1 && ( + + ,{" "} + + )} + + ))} +
)} {studios.length > 0 && ( diff --git a/src/components/musicTrack/index.jsx b/src/components/musicTrack/index.jsx new file mode 100644 index 0000000..3004728 --- /dev/null +++ b/src/components/musicTrack/index.jsx @@ -0,0 +1,124 @@ +/** @format */ +import Typography from "@mui/material/Typography"; +import "./musicTrack.module.scss"; +import { getRuntimeMusic } from "../../utils/date/time"; +import LikeButton from "../buttons/likeButton"; +import TextLink from "../textLink"; +import PlayButton from "../buttons/playButton"; +import { useAudioPlayback } from "../../utils/store/audioPlayback"; + +/** + * @typedef {Object} Props + * @property {import("@jellyfin/sdk/lib/generated-client/models").BaseItemDto} item + * @property {Array} queryKey + * @property {string} userId + */ + +/** + * @description Music Track element displayed in ArtistTitlePage and Songs library + * @param {Props} + * @returns {React.Component} + */ + +const MusicTrack = ({ item, queryKey, userId }) => { + const [currentTrackItem] = useAudioPlayback((state) => [state.item]); + + return ( +
+
+ (e.target.style.opacity = 1)} + /> +
+ +
+
+
+ + {item.Name} + + +
+ {item.ArtistItems.map((artist, index) => ( + <> + + {index != item.ArtistItems.length - 1 && ( + + ,{" "} + + )} + + ))} +
+ {/* + {item.Name} + */} +
+ + {getRuntimeMusic(item.RunTimeTicks)} + + +
+ ); +}; + +export default MusicTrack; diff --git a/src/components/musicTrack/musicTrack.module.scss b/src/components/musicTrack/musicTrack.module.scss new file mode 100644 index 0000000..74ef59c --- /dev/null +++ b/src/components/musicTrack/musicTrack.module.scss @@ -0,0 +1,40 @@ +/** @format */ + +.music-track { + display: grid; + grid-template-columns: 4.5em 80% 1fr 1fr; + gap: 0.5em; + align-items: center; + justify-items: center; + &-image { + margin: 0.4em; + border-radius: $border-radius-default; + overflow: hidden; + aspect-ratio: 1; + position: relative; + &-overlay { + position: absolute; + top: 0; + left: 0; + backdrop-filter: blur(10px); + width: 100%; + height: 100%; + display: flex; + justify-content: center; + align-items: center; + opacity: 0; + transition: opacity $transition-time-fast; + } + box-shadow: 0 0 10px rgb(0 0 0 / 0.2); + transition: opacity $transition-time-fast; + } + &-info { + justify-self: start; + } + + &:hover { + .music-track-image-overlay { + opacity: 1; + } + } +} diff --git a/src/components/playback/audioPlayer/audioPlayer.module.scss b/src/components/playback/audioPlayer/audioPlayer.module.scss index 922ae2e..f6102c4 100644 --- a/src/components/playback/audioPlayer/audioPlayer.module.scss +++ b/src/components/playback/audioPlayer/audioPlayer.module.scss @@ -3,7 +3,6 @@ .audio-player { position: fixed; bottom: 0; - left: 0; right: 0; background: $clr-background-dark-opacity-0_8; z-index: 10; diff --git a/src/components/playback/audioPlayer/index.jsx b/src/components/playback/audioPlayer/index.jsx index 2256002..949c1be 100644 --- a/src/components/playback/audioPlayer/index.jsx +++ b/src/components/playback/audioPlayer/index.jsx @@ -6,6 +6,7 @@ import { motion } from "framer-motion"; import Fab from "@mui/material/Fab"; import IconButton from "@mui/material/IconButton"; import Typography from "@mui/material/Typography"; +import CircularProgress from "@mui/material/CircularProgress"; import WaveSurfer from "wavesurfer.js"; @@ -21,10 +22,11 @@ import { MdiSkipNext } from "../../icons/mdiSkipNext"; import { MdiSkipPrevious } from "../../icons/mdiSkipPrevious"; import { useQuery } from "@tanstack/react-query"; import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api"; -import { Icon } from "@mui/material"; import { MdiClose } from "../../icons/mdiClose"; import { MdiMusic } from "../../icons/mdiMusic"; +import { theme } from "../../../theme"; + const AudioPlayer = () => { const user = useQuery({ queryKey: ["user"], @@ -37,7 +39,10 @@ const AudioPlayer = () => { const waveSurferRef = useRef(null); const waveSurferContainerRef = useRef(null); - const [playing, setPlaying] = useState(false); + const [playerReady, setPlayerReady] = useState(false); + const [playing, setPlaying] = useState(true); + + const [loading, setLoading] = useState(true); const [showWaveform, setShowWaveform] = useState(false); @@ -73,17 +78,22 @@ const AudioPlayer = () => { if (display) { const waveSurfer = WaveSurfer.create({ container: waveSurferContainerRef.current, - autoplay: true, barHeight: 0.8, dragToSeek: true, height: 35, cursorColor: "#fb2376", progressColor: "#fb2376", + waveColor: "#ffffff2f", normalize: true, }); waveSurfer.load(url); + waveSurfer.on("load", () => { + setLoading(true); + }); waveSurfer.on("ready", () => { waveSurferRef.current = waveSurfer; + waveSurfer.play(); + setLoading(false); }); waveSurfer.on("timeupdate", (e) => { setCurrentTime(e); @@ -114,18 +124,27 @@ const AudioPlayer = () => { setShowWaveform(false); } }); + waveSurfer.on("destroy", () => { + waveSurfer.unAll(); + setLoading(true); + }); return () => { waveSurfer.destroy(); }; } - }, [url]); + }, [url, display, currentTrack]); + + useEffect(() => { + if (playerReady) waveSurferRef.current.play(); + }, [playerReady]); const handlePlayPause = () => { waveSurferRef.current.playPause(); }; const handleNext = () => { + setPlaying(false); setCurrentTrack(currentTrack + 1); setAudioUrl( `${window.api.basePath}/Audio/${ @@ -139,6 +158,7 @@ const AudioPlayer = () => { }; const handlePrevious = () => { + setPlaying(false); setCurrentTrack(currentTrack - 1); setAudioUrl( `${window.api.basePath}/Audio/${ @@ -159,6 +179,14 @@ const AudioPlayer = () => { transform: "translateY(100%)", }} animate={{ transform: "translateY(0)" }} + exit={{ + transform: "translateY(100%)", + }} + style={{ + width: `calc(100vw - ${theme.spacing( + 13, + )} - 10px)`, + }} className="audio-player" > { { }} fontWeight={500} > - {item.IndexNumber}. {item.Name} + {!!item.IndexNumber + ? `${item.IndexNumber}. ${item.Name}` + : item.Name} { > - - {playing ? : } - +
+ + + {playing ? ( + + ) : ( + + )} + +
{ +const TextLink = ({ text, location, variant, otherProps }) => { const navigate = useNavigate(); return ( @@ -13,6 +13,7 @@ const TextLink = ({ text, location, variant }) => { variant={variant} className="link" onClick={() => navigate(location)} + {...otherProps} > {text}
diff --git a/src/routes/album/index.jsx b/src/routes/album/index.jsx index 1f7cbc3..6e28ca4 100644 --- a/src/routes/album/index.jsx +++ b/src/routes/album/index.jsx @@ -122,29 +122,19 @@ const MusicAlbumTitlePage = () => { }); const [ - url, - display, currentTrackItem, - tracks, - currentTrack, setCurrentAudioTrack, setAudioUrl, setAudioDisplay, setAudioItem, setAudioTracks, - resetPlayer, ] = useAudioPlayback((state) => [ - state.url, - state.display, state.item, - state.tracks, - state.currentTrack, state.setCurrentTrack, state.setUrl, state.setDisplay, state.setItem, state.setTracks, - state.reset, ]); const playTrack = (index) => { setAudioTracks(musicTracks.data.Items); @@ -201,7 +191,7 @@ const MusicAlbumTitlePage = () => { userId={user.data.Id} queryKey={["item", id]} artists={item.data.ArtistItems} - albumBy={item.data.AlbumArtist} + albumBy={item.data.AlbumArtists[0]} disableMarkAsPlayedButton audioPlayButton /> @@ -274,7 +264,9 @@ const MusicAlbumTitlePage = () => { "end", }} > - {track.IndexNumber} + {!!track.IndexNumber + ? track.IndexNumber + : "-"}