From 7a2e4ae5952bf78f7fac284fab642b6600353a11 Mon Sep 17 00:00:00 2001 From: Prayag Prajapati Date: Wed, 31 Jul 2024 11:41:44 +0530 Subject: [PATCH] feat: add new audioPlayer route and allow reordering queue --- .babelrc | 1 + biome.json | 3 + package.json | 3 + pnpm-lock.yaml | 147 +++++++- src-tauri/tauri.conf.json | 19 +- src/components/appBar/appBar.tsx | 3 - src/components/buttons/queueButton.tsx | 2 +- src/components/playback/audioPlayer/index.tsx | 4 +- src/components/queueTrack/index.tsx | 114 ++++++ src/eventEmitter.js | 3 - src/routes/__root.tsx | 334 +++++++++--------- src/routes/_api/album/$id.tsx | 8 +- src/routes/_api/album/album.scss | 3 - src/routes/_api/player/audio.scss | 69 +++- src/routes/_api/player/audio.tsx | 122 ++++++- src/styles/variables.scss | 1 + vite.config.js | 12 +- 17 files changed, 629 insertions(+), 219 deletions(-) create mode 100644 .babelrc create mode 100644 src/components/queueTrack/index.tsx delete mode 100644 src/eventEmitter.js diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/.babelrc @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/biome.json b/biome.json index 0c15368..6daca8a 100644 --- a/biome.json +++ b/biome.json @@ -34,5 +34,8 @@ "*.scss" ], "ignoreUnknown": true + }, + "formatter": { + "formatWithErrors": true } } diff --git a/package.json b/package.json index d0c80e9..effdef3 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,8 @@ "notistack": "^3.0.1", "react": "18.3.1", "react-blurhash": "^0.3.0", + "react-dnd": "^16.0.1", + "react-dnd-html5-backend": "^16.0.1", "react-dom": "18.3.1", "react-error-boundary": "^4.0.13", "react-markdown": "^9.0.1", @@ -59,6 +61,7 @@ "zustand": "^4.5.4" }, "devDependencies": { + "@babel/plugin-proposal-optional-chaining-assign": "^7.24.7", "@biomejs/biome": "^1.8.3", "@tanstack/router-cli": "^1.45.8", "@tanstack/router-devtools": "^1.45.11", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d6e7fd2..7e0b4db 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -107,6 +107,12 @@ importers: react-blurhash: specifier: ^0.3.0 version: 0.3.0(blurhash@2.0.5)(react@18.3.1) + react-dnd: + specifier: ^16.0.1 + version: 16.0.1(@types/node@22.0.0)(@types/react@18.3.3)(react@18.3.1) + react-dnd-html5-backend: + specifier: ^16.0.1 + version: 16.0.1 react-dom: specifier: 18.3.1 version: 18.3.1(react@18.3.1) @@ -141,6 +147,9 @@ importers: specifier: ^4.5.4 version: 4.5.4(@types/react@18.3.3)(react@18.3.1) devDependencies: + '@babel/plugin-proposal-optional-chaining-assign': + specifier: ^7.24.7 + version: 7.24.7(@babel/core@7.24.9) '@biomejs/biome': specifier: ^1.8.3 version: 1.8.3 @@ -228,6 +237,10 @@ packages: resolution: {integrity: sha512-zBAIvbCMh5Ts+b86r/CjU+4XGYIs+R1j951gxI3KmmxBMhCg4oQMsv6ZXQ64XOm/cvzfU1FmoCyt6+owc5QMYg==} engines: {node: '>=6.9.0'} + '@babel/helper-skip-transparent-expression-wrappers@7.24.7': + resolution: {integrity: sha512-IO+DLT3LQUElMbpzlatRASEyQtfhSE0+m465v++3jyyXeBTBUjtVZg28/gHeV5mrTJqvEKhKroBGAvhW+qPHiQ==} + engines: {node: '>=6.9.0'} + '@babel/helper-string-parser@7.24.8': resolution: {integrity: sha512-pO9KhhRcuUyGnJWwyEgnRJTSIZHiT+vMD0kPeD+so0l7mxkMT19g3pjY9GTnHySck/hDzq+dtW/4VgnMkippsQ==} engines: {node: '>=6.9.0'} @@ -253,18 +266,41 @@ packages: engines: {node: '>=6.0.0'} hasBin: true + '@babel/plugin-proposal-optional-chaining-assign@7.24.7': + resolution: {integrity: sha512-a7+U9LJ06lqftkbRQB8P0tTIADoQhzZMl3owT/Rly7JZjcpDX/VNauogJmuK5VIBJN91jQMUd8EGPTpNehvvFQ==} + engines: {node: '>=6.9.0'} + peerDependencies: + '@babel/core': ^7.22.5 + '@babel/plugin-syntax-jsx@7.24.7': resolution: {integrity: sha512-6ddciUPe/mpMnOKv/U+RSd2vvVy+Yw/JfBB0ZHYjEZt9NLHmCUylNYlsbqCCS1Bffjlb0fCwC9Vqz+sBz6PsiQ==} engines: {node: '>=6.9.0'} peerDependencies: '@babel/core': ^7.0.0-0 + '@babel/plugin-syntax-optional-chaining-assign@7.24.7': + resolution: {integrity: sha512-syk5SNtBRAMFM32edresIIKDfJh4KHdJU8Cc5WLhUx2iRVovERCfiBaxJaZ5M1p4fxnVznc7ioSe21qPMCSwhw==} + engines: {node: '>=6.9.0'} + peerDependencies: + '@babel/core': ^7.0.0-0 + + '@babel/plugin-syntax-optional-chaining@7.8.3': + resolution: {integrity: sha512-KoK9ErH1MBlCPxV0VANkXW2/dw4vlbGDrFgz8bmUsBGYkFRcbRwMh6cIJubdPrkxRwuGdtCk0v/wPTKbQgBjkg==} + peerDependencies: + '@babel/core': ^7.0.0-0 + '@babel/plugin-syntax-typescript@7.24.7': resolution: {integrity: sha512-c/+fVeJBB0FeKsFvwytYiUD+LBvhHjGSI0g446PRGdSVGZLRNArBUno2PETbAly3tpiNAQR5XaZ+JslxkotsbA==} engines: {node: '>=6.9.0'} peerDependencies: '@babel/core': ^7.0.0-0 + '@babel/plugin-transform-optional-chaining@7.24.8': + resolution: {integrity: sha512-5cTOLSMs9eypEy8JUVvIKOu6NgvbJMnpG62VpIHrTmROdQ+L5mDAaI40g25k5vXti55JWNX5jCkq3HZxXBQANw==} + engines: {node: '>=6.9.0'} + peerDependencies: + '@babel/core': ^7.0.0-0 + '@babel/plugin-transform-react-jsx-self@7.24.7': resolution: {integrity: sha512-fOPQYbGSgH0HUp4UJO4sMBFjY6DuWq+2i8rixyUMb3CdGixs/gccURvYOAhajBdKDoGajFr3mUq5rH3phtkGzw==} engines: {node: '>=6.9.0'} @@ -931,6 +967,15 @@ packages: '@popperjs/core@2.11.8': resolution: {integrity: sha512-P1st0aksCrn9sGZhp8GMYwBnQsbvAWsZAX44oXNNvLHGqAOcoVxmjZiohstwQ7SqKnbR47akdNi+uleWD8+g6A==} + '@react-dnd/asap@5.0.2': + resolution: {integrity: sha512-WLyfoHvxhs0V9U+GTsGilGgf2QsPl6ZZ44fnv0/b8T3nQyvzxidxsg/ZltbWssbsRDlYW8UKSQMTGotuTotZ6A==} + + '@react-dnd/invariant@4.0.2': + resolution: {integrity: sha512-xKCTqAK/FFauOM9Ta2pswIyT3D8AQlfrYdOi/toTPEhqCuAs1v5tcJ3Y08Izh1cJ5Jchwy9SeAXmMg6zrKs2iw==} + + '@react-dnd/shallowequal@4.0.2': + resolution: {integrity: sha512-/RVXdLvJxLg4QKvMoM5WlwNR9ViO9z8B/qPcc+C0Sa/teJY7QG7kJ441DwzOjMYEY7GmU4dj5EcGHIkKZiQZCA==} + '@react-spring/animated@9.7.4': resolution: {integrity: sha512-7As+8Pty2QlemJ9O5ecsuPKjmO0NKvmVkRR1n6mEotFgWar8FKuQt2xgxz3RTgxcccghpx1YdS1FCdElQNexmQ==} peerDependencies: @@ -1606,6 +1651,9 @@ packages: resolution: {integrity: sha512-uIFDxqpRZGZ6ThOk84hEfqWoHx2devRFvpTZcTHur85vImfaxUbTW9Ryh4CpCuDnToOP1CEtXKIgytHBPVff5A==} engines: {node: '>=0.3.1'} + dnd-core@16.0.1: + resolution: {integrity: sha512-HK294sl7tbw6F6IeuK16YSBUoorvHpY8RHO+9yFfaJyCDVb6n7PRcezrOEOa2SBCqiYpemh5Jx20ZcjKdFAVng==} + dom-helpers@5.2.1: resolution: {integrity: sha512-nRCa7CK3VTrM2NmGkIy4cbK7IZlgBE/PYMn55rrXefr5xXDP0LdtfPnblFDoVdcAfslJ7or6iqAUnx0CCGIWQA==} @@ -1675,6 +1723,9 @@ packages: extend@3.0.2: resolution: {integrity: sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==} + fast-deep-equal@3.1.3: + resolution: {integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==} + fetch-retry@6.0.0: resolution: {integrity: sha512-BUFj1aMubgib37I3v4q78fYo63Po7t4HUPTpQ6/QE6yK6cIQrP+W43FYToeTEyg5m2Y7eFUtijUuAv/PDlWuag==} @@ -2235,6 +2286,24 @@ packages: blurhash: ^2.0.3 react: '>=15' + react-dnd-html5-backend@16.0.1: + resolution: {integrity: sha512-Wu3dw5aDJmOGw8WjH1I1/yTH+vlXEL4vmjk5p+MHxP8HuHJS1lAGeIdG/hze1AvNeXWo/JgULV87LyQOr+r5jw==} + + react-dnd@16.0.1: + resolution: {integrity: sha512-QeoM/i73HHu2XF9aKksIUuamHPDvRglEwdHL4jsp784BgUuWcg6mzfxT0QDdQz8Wj0qyRKx2eMg8iZtWvU4E2Q==} + peerDependencies: + '@types/hoist-non-react-statics': '>= 3.3.1' + '@types/node': '>= 12' + '@types/react': '>= 16' + react: '>= 16.14' + peerDependenciesMeta: + '@types/hoist-non-react-statics': + optional: true + '@types/node': + optional: true + '@types/react': + optional: true + react-dom@18.3.1: resolution: {integrity: sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==} peerDependencies: @@ -2293,6 +2362,9 @@ packages: resolution: {integrity: sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==} engines: {node: '>=8.10.0'} + redux@4.2.1: + resolution: {integrity: sha512-LAUYz4lc+Do8/g7aeRa8JkyDErK6ekstQaqWQrNRW//MY1TvCEpMtpTWvlQ+FPbWCx+Xixu/6SHt5N0HR+SB4w==} + regenerator-runtime@0.14.1: resolution: {integrity: sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==} @@ -2803,6 +2875,13 @@ snapshots: transitivePeerDependencies: - supports-color + '@babel/helper-skip-transparent-expression-wrappers@7.24.7': + dependencies: + '@babel/traverse': 7.25.1 + '@babel/types': 7.25.0 + transitivePeerDependencies: + - supports-color + '@babel/helper-string-parser@7.24.8': {} '@babel/helper-validator-identifier@7.24.7': {} @@ -2825,16 +2904,46 @@ snapshots: dependencies: '@babel/types': 7.25.0 + '@babel/plugin-proposal-optional-chaining-assign@7.24.7(@babel/core@7.24.9)': + dependencies: + '@babel/core': 7.24.9 + '@babel/helper-plugin-utils': 7.24.8 + '@babel/helper-skip-transparent-expression-wrappers': 7.24.7 + '@babel/plugin-syntax-optional-chaining-assign': 7.24.7(@babel/core@7.24.9) + '@babel/plugin-transform-optional-chaining': 7.24.8(@babel/core@7.24.9) + transitivePeerDependencies: + - supports-color + '@babel/plugin-syntax-jsx@7.24.7(@babel/core@7.24.9)': dependencies: '@babel/core': 7.24.9 '@babel/helper-plugin-utils': 7.24.8 + '@babel/plugin-syntax-optional-chaining-assign@7.24.7(@babel/core@7.24.9)': + dependencies: + '@babel/core': 7.24.9 + '@babel/helper-plugin-utils': 7.24.8 + '@babel/helper-validator-option': 7.24.8 + + '@babel/plugin-syntax-optional-chaining@7.8.3(@babel/core@7.24.9)': + dependencies: + '@babel/core': 7.24.9 + '@babel/helper-plugin-utils': 7.24.8 + '@babel/plugin-syntax-typescript@7.24.7(@babel/core@7.24.9)': dependencies: '@babel/core': 7.24.9 '@babel/helper-plugin-utils': 7.24.8 + '@babel/plugin-transform-optional-chaining@7.24.8(@babel/core@7.24.9)': + dependencies: + '@babel/core': 7.24.9 + '@babel/helper-plugin-utils': 7.24.8 + '@babel/helper-skip-transparent-expression-wrappers': 7.24.7 + '@babel/plugin-syntax-optional-chaining': 7.8.3(@babel/core@7.24.9) + transitivePeerDependencies: + - supports-color + '@babel/plugin-transform-react-jsx-self@7.24.7(@babel/core@7.24.9)': dependencies: '@babel/core': 7.24.9 @@ -3200,8 +3309,8 @@ snapshots: dependencies: '@antfu/ni': 0.21.12 '@axiomhq/js': 1.0.0-rc.3 - '@babel/core': 7.24.6 - '@babel/types': 7.24.6 + '@babel/core': 7.24.9 + '@babel/types': 7.25.0 '@clack/prompts': 0.7.0 cli-high: 0.4.2 diff: 5.2.0 @@ -3423,6 +3532,12 @@ snapshots: '@popperjs/core@2.11.8': {} + '@react-dnd/asap@5.0.2': {} + + '@react-dnd/invariant@4.0.2': {} + + '@react-dnd/shallowequal@4.0.2': {} + '@react-spring/animated@9.7.4(react@18.3.1)': dependencies: '@react-spring/shared': 9.7.4(react@18.3.1) @@ -4082,6 +4197,12 @@ snapshots: diff@5.2.0: {} + dnd-core@16.0.1: + dependencies: + '@react-dnd/asap': 5.0.2 + '@react-dnd/invariant': 4.0.2 + redux: 4.2.1 + dom-helpers@5.2.1: dependencies: '@babel/runtime': 7.25.0 @@ -4188,6 +4309,8 @@ snapshots: extend@3.0.2: {} + fast-deep-equal@3.1.3: {} + fetch-retry@6.0.0: {} fflate@0.4.8: {} @@ -4905,6 +5028,22 @@ snapshots: blurhash: 2.0.5 react: 18.3.1 + react-dnd-html5-backend@16.0.1: + dependencies: + dnd-core: 16.0.1 + + react-dnd@16.0.1(@types/node@22.0.0)(@types/react@18.3.3)(react@18.3.1): + dependencies: + '@react-dnd/invariant': 4.0.2 + '@react-dnd/shallowequal': 4.0.2 + dnd-core: 16.0.1 + fast-deep-equal: 3.1.3 + hoist-non-react-statics: 3.3.2 + react: 18.3.1 + optionalDependencies: + '@types/node': 22.0.0 + '@types/react': 18.3.3 + react-dom@18.3.1(react@18.3.1): dependencies: loose-envify: 1.4.0 @@ -4974,6 +5113,10 @@ snapshots: dependencies: picomatch: 2.3.1 + redux@4.2.1: + dependencies: + '@babel/runtime': 7.25.0 + regenerator-runtime@0.14.1: {} registry-auth-token@5.0.2: diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 46bb5a2..1e549e8 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -71,15 +71,16 @@ "app": { "windows": [ { - "fullscreen": false, - "height": 600, - "width": 800, - "resizable": true, - "title": "Blink", - "visible": true, - "center": true, - "label": "main" - } + "fullscreen": false, + "height": 600, + "width": 800, + "resizable": true, + "title": "Blink", + "visible": true, + "center": true, + "label": "main", + "dragDropEnabled": false + } ], "security": { "csp": null diff --git a/src/components/appBar/appBar.tsx b/src/components/appBar/appBar.tsx index 76a7afe..92cada5 100644 --- a/src/components/appBar/appBar.tsx +++ b/src/components/appBar/appBar.tsx @@ -19,8 +19,6 @@ import { useQuery, useQueryClient } from "@tanstack/react-query"; import { delUser } from "@/utils/storage/user"; import "./appBar.scss"; -import { EventEmitter as event } from "@/eventEmitter"; - import { getTypeIcon } from "../utils/iconsCollection"; import { useApiInContext } from "@/utils/store/api"; @@ -121,7 +119,6 @@ export const AppBar = () => { await api.logout(); delUser(); sessionStorage.removeItem("accessToken"); - event.emit("create-jellyfin-api", api.basePath); queryClient.clear(); setAnchorEl(null); navigate({ to: "/login" }); diff --git a/src/components/buttons/queueButton.tsx b/src/components/buttons/queueButton.tsx index 0af0ecc..fd5acf3 100644 --- a/src/components/buttons/queueButton.tsx +++ b/src/components/buttons/queueButton.tsx @@ -86,7 +86,7 @@ const QueueButton = () => { > {item.Type === "Audio" - ? item.IndexNumber ?? 0 + ? index + 1 : item.IndexNumberEnd ? `S${item.ParentIndexNumber}:E${item.IndexNumber} / ${item.IndexNumberEnd}` : `S${item.ParentIndexNumber}:E${item.IndexNumber}`} diff --git a/src/components/playback/audioPlayer/index.tsx b/src/components/playback/audioPlayer/index.tsx index 7e41f1b..9665345 100644 --- a/src/components/playback/audioPlayer/index.tsx +++ b/src/components/playback/audioPlayer/index.tsx @@ -93,7 +93,7 @@ const AudioPlayer = () => { }); setAudioRef(audioRef); } - }, [url, currentTrack]); + }, [url, tracks[currentTrack]?.Id]); const navigate = useNavigate(); @@ -288,6 +288,7 @@ const AudioPlayer = () => { onTimeUpdate={(e) => setProgress(secToTicks(e.currentTarget.currentTime)) } + id="audio-player" />
{controls} @@ -317,7 +318,6 @@ const AudioPlayer = () => { onChange={(e, value) => { setIsScrubbing(true); setSliderProgress(value); - console.log(value); }} onChangeCommitted={(e, value) => { setIsScrubbing(false); diff --git a/src/components/queueTrack/index.tsx b/src/components/queueTrack/index.tsx new file mode 100644 index 0000000..d493bf2 --- /dev/null +++ b/src/components/queueTrack/index.tsx @@ -0,0 +1,114 @@ +import { getRuntimeMusic } from "@/utils/date/time"; +import useQueue, { setQueue } from "@/utils/store/queue"; +import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client"; +import { Typography } from "@mui/material"; +import React from "react"; +import { useCallback, useRef } from "react"; +import { type XYCoord, useDrag, useDrop } from "react-dnd"; +import type { Identifier } from "typescript"; + +type Props = { + track: BaseItemDto; + index: number; +}; +const QueueTrack = (props: Props) => { + const { track, index } = props; + const [queue, currentItemIndex] = useQueue((s) => [ + s.tracks, + s.currentItemIndex, + ]); + const trackRef = useRef(null); + const handleQueueUpdate = useCallback( + (dragIndex: number, dropIndex: number) => { + const prevState = queue; + prevState.splice(dropIndex, 0, prevState.splice(dragIndex, 1)[0]); + setQueue(prevState, dropIndex); + }, + [queue], + ); + + const [{ handlerId }, drop] = useDrop< + { + index: number; + id: string; + type: string; + }, + void, + { handlerId: Identifier | null } + >({ + accept: "Row", + collect(monitor) { + return { + handlerId: monitor.getHandlerId(), + }; + }, + hover(hoverItem, monitor) { + console.log(hoverItem); + if (!trackRef.current) return; + + const dragIndex = hoverItem.index; + const dropIndex = index; + + if (dragIndex === dropIndex) return; + + const hoverBoundingRect = trackRef.current?.getBoundingClientRect(); + const hoverMiddleY = + (hoverBoundingRect.bottom - hoverBoundingRect.top) / 2; + + const clientOffset = monitor.getClientOffset(); + + const hoverClientY = (clientOffset as XYCoord).y - hoverBoundingRect.top; + + if (dragIndex < dropIndex && hoverClientY < hoverMiddleY) { + return; + } + + if (dragIndex > dropIndex && hoverClientY > hoverMiddleY) { + return; + } + + handleQueueUpdate(dragIndex, dropIndex); + hoverItem.index = dropIndex; + }, + }); + + const [{ isDragging }, drag] = useDrag({ + type: "Row", + item: () => { + const id = track.Id; + return { id, index }; + }, + collect: (monitor) => ({ + isDragging: monitor.isDragging(), + }), + }); + + drag(drop(trackRef)); + + return ( +
+ drag_handle +
+ + {track.Name} + + + {track.Artists?.join(", ")} + +
+ + {getRuntimeMusic(track.RunTimeTicks)} + +
+ ); +}; + +export default QueueTrack; \ No newline at end of file diff --git a/src/eventEmitter.js b/src/eventEmitter.js deleted file mode 100644 index e0d7d7b..0000000 --- a/src/eventEmitter.js +++ /dev/null @@ -1,3 +0,0 @@ -import { EventEmitter as eventEmitter } from "events"; - -export const EventEmitter = new eventEmitter(); diff --git a/src/routes/__root.tsx b/src/routes/__root.tsx index d86888a..166d926 100644 --- a/src/routes/__root.tsx +++ b/src/routes/__root.tsx @@ -46,6 +46,8 @@ import "material-symbols/rounded.scss"; import type { Api, Jellyfin } from "@jellyfin/sdk"; import type { UserDto } from "@jellyfin/sdk/lib/generated-client"; import { ReactQueryDevtools } from "@tanstack/react-query-devtools"; +import { DndProvider } from "react-dnd"; +import { HTML5Backend } from "react-dnd-html5-backend"; type ApiContext = { api: Api; @@ -94,175 +96,179 @@ export const Route = createRootRouteWithContext()({ setBackdropLoading(true); }, [backdropId]); return ( - Loading...}> - - - - - - - + + Loading...}> + + + + + + + - {routeIsLoading && ( - + + + )} + + - - - )} - - - {updateInfo !== undefined && ( - <> - - Update Available! - update - } - label={`v${updateInfo.version}`} - color="success" - /> - - - - - {updateInfo.body} - - - - - - - - Update - - - - - - { - setUpdateDialogButton(true); - await updateInfo.downloadAndInstall(); - enqueueSnackbar( - "Update has been installed! You need to relaunch JellyPlayer.", - { - variant: "success", - }, - ); - await relaunch(); + {updateInfo !== undefined && ( + <> + - Update - - - - )} - -
- - setBackdropLoading(false)} - loading="lazy" - /> - -
- - - - - {/* */} -
-
-
+ Update Available! + + update + + } + label={`v${updateInfo.version}`} + color="success" + /> + + + + + {updateInfo.body} + + + + + + + + Update + + + + + + { + setUpdateDialogButton(true); + await updateInfo.downloadAndInstall(); + enqueueSnackbar( + "Update has been installed! You need to relaunch JellyPlayer.", + { + variant: "success", + }, + ); + await relaunch(); + }} + > + Update + + + + )} + +
+ + setBackdropLoading(false)} + loading="lazy" + /> + +
+ + + + + {/* */} +
+
+
+ ); }, }); \ No newline at end of file diff --git a/src/routes/_api/album/$id.tsx b/src/routes/_api/album/$id.tsx index 2fdc936..f256485 100644 --- a/src/routes/_api/album/$id.tsx +++ b/src/routes/_api/album/$id.tsx @@ -250,7 +250,7 @@ function MusicAlbumTitlePage() { Title Duration
- {musicTracks.data?.Items?.map((track) => ( + {musicTracks.data?.Items?.map((track, index) => (
- handlePlayback( - track.IndexNumber, - track, - musicTracks.data.Items, - ) + handlePlayback(index, track, musicTracks.data.Items) } >
diff --git a/src/routes/_api/album/album.scss b/src/routes/_api/album/album.scss index 470cb62..bc31175 100644 --- a/src/routes/_api/album/album.scss +++ b/src/routes/_api/album/album.scss @@ -97,9 +97,6 @@ $border-radius: 20px; flex-direction: column; gap: 0.1em } - &:nth-last-of-type(even):not(.header) { - background: rgb(0 0 0 / 0.2); - } &:hover { background: rgb(255 255 255 / 0.1) !important; .index-container { diff --git a/src/routes/_api/player/audio.scss b/src/routes/_api/player/audio.scss index c09787c..c8ee018 100644 --- a/src/routes/_api/player/audio.scss +++ b/src/routes/_api/player/audio.scss @@ -1,21 +1,60 @@ -.audio-info { - &-container { - display: flex; - gap: 1em; - align-items: center; - justify-content: flex-start; - } - &-image { +.audio { + &-info { width: 100%; - aspect-ratio: 1; - height: 100%; - object-fit: cover; + padding: 4em; + gap: 0.5em; + display: flex; + flex-direction: column; &-container { - width: 25em; + display: flex; + gap: 0em; + align-items: center; + justify-content: flex-start; + } + &-image { + width: 100%; aspect-ratio: 1; - position: relative; - border-radius: $border-radius-default; - overflow: hidden; + height: 100%; + object-fit: cover; + &-container { + width: 25em; + aspect-ratio: 1; + position: relative; + border-radius: $border-radius-default; + overflow: hidden; + } + } + &-controls { + width: 100%; + display: flex; + align-items: center; + justify-content: center; + gap: 1em; + } + } + &-queue{ + display: flex; + flex-direction: column; + width: 100%; + align-items: center; + gap: 1em; + margin-top: 2em; + &-track{ + display: grid; + grid-template-columns: 3em 1fr 6em; + align-items: center; + justify-content: center; + width: 100%; + gap: 1em; + &-info-name{ + transition: $transition-time-fast; + } + &.active{ + .audio-queue-track-info-name{ + color: $clr-accent-light; + font-weight: 500; + } + } } } } \ No newline at end of file diff --git a/src/routes/_api/player/audio.tsx b/src/routes/_api/player/audio.tsx index 7c0a949..bb0fc69 100644 --- a/src/routes/_api/player/audio.tsx +++ b/src/routes/_api/player/audio.tsx @@ -1,25 +1,45 @@ import { useApiInContext } from "@/utils/store/api"; import { useAudioPlayback } from "@/utils/store/audioPlayback"; import useQueue from "@/utils/store/queue"; -import { Typography } from "@mui/material"; +import { Fab, IconButton, Slider, Typography } from "@mui/material"; import { createFileRoute } from "@tanstack/react-router"; -import React from "react"; +import React, { useCallback, useEffect, useRef, useState } from "react"; import "./audio.scss"; +import LikeButton from "@/components/buttons/likeButton"; +import PlayNextButton from "@/components/buttons/playNextButton"; +import PlayPreviousButton from "@/components/buttons/playPreviousButtom"; +import QueueTrack from "@/components/queueTrack"; +import { getRuntimeMusic, secToTicks, ticksToSec } from "@/utils/date/time"; +import { useDrop } from "react-dnd"; +import { Identifier } from "typescript"; export const Route = createFileRoute("/_api/player/audio")({ component: AudioPlayerRoute, }); +const SEEK_AMOUNT = 10; // seconds to skip on fast_rewind or fast_forward button click + function AudioPlayerRoute() { - const item = useAudioPlayback((s) => s.item); const api = useApiInContext((s) => s.api); - const [queue, currentTrack] = useQueue((s) => [ - s.currentItemIndex, - s.currentItemIndex, - ]); + const [queue, currentTrack] = useQueue((s) => [s.tracks, s.currentItemIndex]); + const [item] = useAudioPlayback((s) => [s.item]); + const audioPlayer: HTMLAudioElement | null = + document.querySelector("#audio-player"); + + const [isScrubbing, setIsScrubbing] = useState(false); + const [sliderProgress, setSliderProgress] = useState(0); // this state hold the slider scrubbing value allowing user to scrub track without changing current time + const [progress, setProgress] = useState( + audioPlayer?.currentTime ?? 0, + ); + useEffect(() => { + audioPlayer?.addEventListener("timeupdate", () => { + setProgress(audioPlayer.currentTime); + }); + }, [item?.Id]); + return ( -
+
{item?.ImageTags ? ( @@ -35,7 +55,7 @@ function AudioPlayerRoute() { )}
- + {item?.Name} by {item?.Artists?.join(", ")} + { + setIsScrubbing(true); + setSliderProgress(newVal); + }} + onChangeCommitted={(_, newVal) => { + setIsScrubbing(false); + Array.isArray(newVal) + ? setProgress(ticksToSec(newVal[0])) + : setProgress(ticksToSec(newVal)); + audioPlayer?.currentTime = Array.isArray(newVal) + ? ticksToSec(newVal[0]) + : ticksToSec(newVal); + }} + sx={{ + "& .MuiSlider-thumb": { + width: 14, + height: 14, + transition: "0.1s ease-in-out", + opacity: 0, + "&.Mui-active": { + width: 20, + height: 20, + opacity: 1, + }, + }, + "&:hover .MuiSlider-thumb": { + opacity: 1, + }, + "& .MuiSlider-rail": { + opacity: 0.28, + background: "white", + }, + }} + /> +
+ + { + audioPlayer?.currentTime -= SEEK_AMOUNT; + }} + > + fast_rewind + + + audioPlayer?.paused ? audioPlayer.play() : audioPlayer?.pause() + } + > + + {audioPlayer?.paused ? "play_arrow" : "pause"} + + + { + audioPlayer?.currentTime += SEEK_AMOUNT; + }} + > + fast_forward + + +
+
+
+
+ Queue: +
+ {queue.map((track, index) => ( + + ))}
-
); } \ No newline at end of file diff --git a/src/styles/variables.scss b/src/styles/variables.scss index e555602..936d0a7 100644 --- a/src/styles/variables.scss +++ b/src/styles/variables.scss @@ -1,5 +1,6 @@ $clr-accent-default: hsl(337, 96%, 56%); +$clr-accent-light: hsl(337, 96%, 90%); $clr-accent-dark: hsl(337, 96%, 20%); $clr-secondary-default: hsl(273, 100%, 36%); $clr-secondary-dark: hsl(273, 100%, 12%); diff --git a/vite.config.js b/vite.config.js index c0520b4..f19d9c6 100644 --- a/vite.config.js +++ b/vite.config.js @@ -7,7 +7,17 @@ import path from "path"; // const ReactCompilerConfig = {compilationMode: "annotation"} -const plugins = [react(), svgr(), TanStackRouterVite()]; +const plugins = [react({ + babel: { + babelrc: true, + plugins: [ + ["@babel/plugin-proposal-optional-chaining-assign", + { + version: "2023-07" + }] + ] + } +}), svgr(), TanStackRouterVite()]; export default defineConfig({ plugins: plugins, css: {