{i}
{track.name}
{track.artists.some(a => a.name) && (
by
{track.artists.map((a, i) => (
{a.name}
{i !== track.artists.length - 1 && {", "}}
))}
)}
{track.album.name && (
on
{track.album.name}
)}
);
}
export function Player() {
const track = useStateFromStores(
[SpotifyStore],
() => SpotifyStore.track,
null,
(prev, next) => prev?.id ? (prev.id === next?.id) : prev?.name === next?.name
);
const device = useStateFromStores(
[SpotifyStore],
() => SpotifyStore.device,
null,
(prev, next) => prev?.id === next?.id
);
const isPlaying = useStateFromStores([SpotifyStore], () => SpotifyStore.isPlaying);
const [shouldHide, setShouldHide] = useState(false);
// Hide player after 5 minutes of inactivity
// eslint-disable-next-line consistent-return
React.useEffect(() => {
setShouldHide(false);
if (!isPlaying) {
const timeout = setTimeout(() => setShouldHide(true), 1000 * 60 * 5);
return () => clearTimeout(timeout);
}
}, [isPlaying]);
if (!track || !device?.is_active || shouldHide)
return null;
const exportTrackImageStyle = {
"--vc-spotify-track-image": `url(${track?.album?.image?.url || ""})`,
} as React.CSSProperties;
return (