From 153f634a088c1b218db43f4f72606a9440992f04 Mon Sep 17 00:00:00 2001 From: aarbit Date: Fri, 19 Jul 2024 23:40:35 -0500 Subject: [PATCH] Adds ability to select a specific track within an album, and fixes info view not keeping position between albums. --- src/App.tsx | 7 ++++++- src/components/AlbumInfoDisplay.tsx | 6 ++++-- src/components/AlbumPlayer.tsx | 13 +++++++------ src/components/TrackListing.tsx | 6 ++++-- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index acb0a86..26b1e28 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -12,6 +12,7 @@ function App() { const [albums, setAlbums] = useState(Array) const [selectedAlbum, setSelectedAlbum] = useState("") const [albumInfo, setAlbumInfo] = useState() + const [isShowAlbumInfo, setIsShowAlbumInfo] = useState(false) useEffect(() => { let fetched = fetch(`${hostName}/album`) @@ -41,10 +42,14 @@ function App() { setSelectedAlbum(event.currentTarget.id) } + function handleAlbumInfoAdjust() { + setIsShowAlbumInfo(!isShowAlbumInfo) + } + return (
- {albumInfo ? :
} + {albumInfo ? :
}
) } diff --git a/src/components/AlbumInfoDisplay.tsx b/src/components/AlbumInfoDisplay.tsx index e305e10..d204bd8 100644 --- a/src/components/AlbumInfoDisplay.tsx +++ b/src/components/AlbumInfoDisplay.tsx @@ -1,9 +1,11 @@ import {AlbumInfo} from "../models/AlbumInfo.ts"; import TrackListing from "./TrackListing.tsx"; +import React from "react"; interface AlbumInfoDisplayProps { albumInfo: AlbumInfo, - trackNumber: number + trackNumber: number, + trackClickHandler: (event: React.MouseEvent, trackNumber: number) => void } export default function AlbumInfoDisplay(props: Readonly) { let isVarious = props.albumInfo.albumArtist.startsWith("Various") @@ -11,7 +13,7 @@ export default function AlbumInfoDisplay(props: Readonly) return (
{!isVarious && `${props.albumInfo.albumArtist} - `}{props.albumInfo.albumTitle}
- +
) } \ No newline at end of file diff --git a/src/components/AlbumPlayer.tsx b/src/components/AlbumPlayer.tsx index 70d1dc5..2a84352 100644 --- a/src/components/AlbumPlayer.tsx +++ b/src/components/AlbumPlayer.tsx @@ -1,4 +1,4 @@ -import {useEffect, useState} from "react"; +import React, {useEffect, useState} from "react"; import hostName from "../Config.ts"; import {AlbumInfo} from "../models/AlbumInfo.ts"; import AlbumInfoDisplay from "./AlbumInfoDisplay.tsx"; @@ -9,12 +9,13 @@ import minimize from '/minimize-2.svg' interface AlbumPlayerProps { albumHash: string, albumInfo: AlbumInfo + handleAlbumInfoAdjust: () => void, + isShowAlbumInfo: boolean } export default function AlbumPlayer(props: Readonly) { const [trackNum, setTrackNum] = useState(0) const [isAlbumOver, setIsAlbumOver] = useState(false) - const [isShowAlbumInfo, setIsShowAlbumInfo] = useState(false) let album = props.albumInfo @@ -30,16 +31,16 @@ export default function AlbumPlayer(props: Readonly) { } } - function handleAlbumInfoAdjust() { - setIsShowAlbumInfo(!isShowAlbumInfo) + function handleTrackClick(_: React.MouseEvent, trackNumber: number) { + setTrackNum(trackNumber) } if(props.albumHash && album) { console.log(album) return (
-
{isShowAlbumInfo ? {'minimize : {'show}
-
{isShowAlbumInfo ? : }
+
{props.isShowAlbumInfo ? {'minimize : {'show}
+
{props.isShowAlbumInfo ? : }