From feb8d995349a7784464a5a15e31a8afa319a62a9 Mon Sep 17 00:00:00 2001 From: leon-morival Date: Thu, 23 Oct 2025 16:29:01 +0200 Subject: [PATCH] better music selection --- src/screens/Studio/SongReady.js | 219 +++++++++++++++++++------------- 1 file changed, 129 insertions(+), 90 deletions(-) diff --git a/src/screens/Studio/SongReady.js b/src/screens/Studio/SongReady.js index fdba00f..7602c0e 100644 --- a/src/screens/Studio/SongReady.js +++ b/src/screens/Studio/SongReady.js @@ -16,7 +16,7 @@ import Page from "../../layouts/Page"; import { Routes } from "../../navigation"; import { navigate } from "../../navigation/NavigationService"; import { useUser } from "../../providers/UserDataProvider"; -import { Style } from "../../styles"; +import { Palette, Style } from "../../styles"; import { gutters, size } from "../../styles/Style"; import { isWeb } from "../../hooks/useLayoutType"; import CreateLyricsHeader from "../Writing/components/CreateLyricsHeader"; @@ -97,6 +97,7 @@ const SongReady = () => { }, [player0, player1]); const togglePlay = async (idx) => { + setSelectedIndex(idx); const url = musicUrls[idx]; if (!url) return; try { @@ -245,106 +246,144 @@ const SongReady = () => { }} /> - {[0, 1].map((idx) => ( - - { + const isSelected = selectedIndex === idx; + return ( + setSelectedIndex(idx)} + style={({ pressed }) => [ + { + borderRadius: 20, + borderWidth: isSelected ? 2 : 1, + borderColor: isSelected + ? Palette.primary + : Palette.ultraLightWhite, + overflow: "hidden", + }, + pressed && { opacity: 0.96 }, + ]} > - togglePlay(idx)} - style={{ ...Style.containerCenter, ...size({ size: 48 }) }} - > - - - - {`Morceau ${idx + 1}`} - { - try { - const player = idx === 0 ? player0 : player1; - wasPlayingBeforeSeek.current[idx] = !!player?.playing; - if (player?.playing) { - await player.pause?.(); - setIsPlaying((p) => ({ ...p, [idx]: false })); - } - } catch (e) { - console.log( - "SongReady pause on seek start", - e?.message - ); - } - }} - onSeek={(ratio) => onSeek(idx, ratio)} - onSeekEnd={async () => { - try { - const player = idx === 0 ? player0 : player1; - if (player && wasPlayingBeforeSeek.current[idx]) { - await player.play?.(); - setIsPlaying((p) => ({ ...p, [idx]: true })); - } - wasPlayingBeforeSeek.current[idx] = false; - } catch (e) { - console.log("SongReady resume after seek", e?.message); - } - }} - /> - - setSelectedIndex(idx)} - style={{ ...Style.containerCenter, ...size({ size: 24 }) }} + - {selectedIndex === idx && ( - togglePlay(idx)} + style={{ + ...Style.containerCenter, + ...size({ size: 48 }), + }} + > + + + + {`Morceau ${idx + 1}`} + { + setSelectedIndex(idx); + try { + const player = idx === 0 ? player0 : player1; + wasPlayingBeforeSeek.current[idx] = + !!player?.playing; + if (player?.playing) { + await player.pause?.(); + setIsPlaying((p) => ({ ...p, [idx]: false })); + } + } catch (e) { + console.log( + "SongReady pause on seek start", + e?.message + ); + } + }} + onSeek={(ratio) => onSeek(idx, ratio)} + onSeekEnd={async () => { + try { + const player = idx === 0 ? player0 : player1; + if (player && wasPlayingBeforeSeek.current[idx]) { + await player.play?.(); + setIsPlaying((p) => ({ ...p, [idx]: true })); + } + wasPlayingBeforeSeek.current[idx] = false; + } catch (e) { + console.log( + "SongReady resume after seek", + e?.message + ); + } }} /> - )} + + setSelectedIndex(idx)} + style={{ + ...Style.containerCenter, + ...size({ size: 24 }), + }} + > + + {isSelected && ( + + )} + + - - - - ))} + + + ); + })}