From 29ae54fe03498e2712d2ccf1905c0c233aa4416b Mon Sep 17 00:00:00 2001 From: SrGooglo Date: Thu, 24 Apr 2025 06:04:18 +0000 Subject: [PATCH] Split player actions --- .../{ExtraActions => Actions}/index.jsx | 32 +- .../src/components/Player/Actions/index.less | 19 + .../src/components/Player/Controls/index.jsx | 17 +- .../components/Player/ToolBarPlayer/index.jsx | 9 +- .../Player/ToolBarPlayer/index.less | 380 ++++++++---------- 5 files changed, 231 insertions(+), 226 deletions(-) rename packages/app/src/components/Player/{ExtraActions => Actions}/index.jsx (51%) create mode 100644 packages/app/src/components/Player/Actions/index.less diff --git a/packages/app/src/components/Player/ExtraActions/index.jsx b/packages/app/src/components/Player/Actions/index.jsx similarity index 51% rename from packages/app/src/components/Player/ExtraActions/index.jsx rename to packages/app/src/components/Player/Actions/index.jsx index b3be128b..9b873395 100755 --- a/packages/app/src/components/Player/ExtraActions/index.jsx +++ b/packages/app/src/components/Player/Actions/index.jsx @@ -6,41 +6,51 @@ import LikeButton from "@components/LikeButton" import { usePlayerStateContext } from "@contexts/WithPlayerContext" +import "./index.less" + const ExtraActions = (props) => { - const [playerState] = usePlayerStateContext() + const [trackInstance, setTrackInstance] = React.useState({}) + + const onPlayerStateChange = React.useCallback((state) => { + const instance = app.cores.player.track() + + if (instance) { + setTrackInstance(instance) + } + }, []) + + const [playerState] = usePlayerStateContext(onPlayerStateChange) const handleClickLike = async () => { - if (!playerState.track_manifest) { + if (!trackInstance) { console.error("Cannot like a track if nothing is playing") return false } - const track = app.cores.player.track() - - await track.manifest.serviceOperations.toggleItemFavourite( + await trackInstance.manifest.serviceOperations.toggleItemFavourite( "track", - playerState.track_manifest._id, + trackInstance.manifest._id, ) } return ( -
+
{app.isMobile && (
diff --git a/packages/app/src/components/Player/ToolBarPlayer/index.jsx b/packages/app/src/components/Player/ToolBarPlayer/index.jsx index fac61db7..14f671ac 100755 --- a/packages/app/src/components/Player/ToolBarPlayer/index.jsx +++ b/packages/app/src/components/Player/ToolBarPlayer/index.jsx @@ -8,11 +8,10 @@ import { usePlayerStateContext } from "@contexts/WithPlayerContext" import LiveInfo from "@components/Player/LiveInfo" import SeekBar from "@components/Player/SeekBar" import Controls from "@components/Player/Controls" +import Actions from "@components/Player/Actions" import RGBStringToValues from "@utils/rgbToValues" -import ExtraActions from "../ExtraActions" - import "./index.less" function isOverflown(parent, element) { @@ -93,7 +92,7 @@ const Player = (props) => { } } - const { title, artistStr, service, cover_analysis, cover } = + const { title, artist, service, cover_analysis, cover } = playerState.track_manifest ?? {} const playing = playerState.playback_status === "playing" @@ -201,7 +200,7 @@ const Player = (props) => { )}

- {artistStr ?? ""} + {artist ?? ""}

@@ -218,7 +217,7 @@ const Player = (props) => { streamMode={playerState.live} /> - +