Generalize welcome message

This will be helpful in preparation for the next step: Timeout on idle.
This commit is contained in:
Chandler Swift 2026-02-12 08:40:03 -06:00
parent 538f7dc5a7
commit ceebc2edb4
Signed by: chandlerswift
GPG key ID: A851D929D52FB93F

View file

@ -56,7 +56,7 @@ function App() {
const [album, setAlbum] = useState<AlbumType | null>(null); const [album, setAlbum] = useState<AlbumType | null>(null);
const [buffer, setBuffer] = useState<string[]>([]); const [buffer, setBuffer] = useState<string[]>([]);
const [nowPlaying, play] = useState<number>(0); const [nowPlaying, play] = useState<number>(0);
const [searching, setSearching] = useState(false); const [displayText, setDisplayText] = useState("Scan an album to begin.");
const [paused, setPaused] = useState(true); const [paused, setPaused] = useState(true);
const [currentTime, setCurrentTime] = useState(0); const [currentTime, setCurrentTime] = useState(0);
const [duration, setDuration] = useState(0); const [duration, setDuration] = useState(0);
@ -129,7 +129,7 @@ function App() {
console.log("empty barcode; ignoring"); console.log("empty barcode; ignoring");
return; return;
} }
setSearching(true); setDisplayText("Searching…");
console.log("Scanned barcode:", barcode); console.log("Scanned barcode:", barcode);
var mbRelease: IRelease | IReleaseMatch; var mbRelease: IRelease | IReleaseMatch;
if (barcode.startsWith("mbid:")) { if (barcode.startsWith("mbid:")) {
@ -145,8 +145,8 @@ function App() {
inc: ['artist-credits', 'release-groups', 'genres'], // TODO inc: ['artist-credits', 'release-groups', 'genres'], // TODO
}); });
if (searchResponse.count === 0) { if (searchResponse.count === 0) {
console.log("No album found for barcode:", barcode); // TODO: some kind of toast? setDisplayText("No album found for barcode: " + barcode);
setSearching(false); setTimeout(() => setDisplayText("Scan an album to begin."), 3000);
return; return;
} }
mbRelease = searchResponse.releases[0]; mbRelease = searchResponse.releases[0];
@ -179,7 +179,6 @@ function App() {
// # …and play! // # …and play!
play(0); play(0);
setPaused(false); setPaused(false);
setSearching(false);
} else { // Not found in Navidrome; populate with MusicBrainz data instead } else { // Not found in Navidrome; populate with MusicBrainz data instead
const fullMbRelease = await mbApi.lookup('release', mbRelease.id, ['recordings', 'artist-credits', 'release-groups']); const fullMbRelease = await mbApi.lookup('release', mbRelease.id, ['recordings', 'artist-credits', 'release-groups']);
const tracks: Track[] = fullMbRelease.media[0].tracks.map((t: ITrack) => ({ // TODO: handle multi-disc albums const tracks: Track[] = fullMbRelease.media[0].tracks.map((t: ITrack) => ({ // TODO: handle multi-disc albums
@ -196,7 +195,6 @@ function App() {
coverArtLink: await getCoverArtSrcURL(fullMbRelease.id, fullMbRelease['release-group']?.id || '') || '', coverArtLink: await getCoverArtSrcURL(fullMbRelease.id, fullMbRelease['release-group']?.id || '') || '',
}) })
console.log(album); console.log(album);
setSearching(false);
} }
} }
@ -231,10 +229,8 @@ function App() {
{player} {player}
</div> </div>
) )
} else if (searching) {
return (<div className="welcome">Searching</div>);
} else { } else {
return (<div className="welcome">Scan an album to begin.</div>); return (<div className="welcome">{displayText}</div>);
} }
} }