Skip to content

Commit

Permalink
Merge pull request #149 from simonv3/nowplaying-on-home
Browse files Browse the repository at this point in the history
feat: now playing on the homepage
  • Loading branch information
simonv3 authored Jun 7, 2022
2 parents 4e4dab4 + 94b84b7 commit e55f0e7
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/components/Explore/NowPlaying.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { css } from "@emotion/css";
import React from "react";
import { fetchLatestTracks } from "../../services/Api";
import usePagination from "../../utils/usePagination";
import { CenteredSpinner } from "../common/Spinner";
import TrackList from "../common/TrackList";

export const NowPlaying: React.FC = () => {
const [tracks, setTracks] = React.useState<Track[]>([]);

const { results, isLoading } = usePagination<Track>({
apiCall: React.useCallback(fetchLatestTracks, []),
options: React.useMemo(() => ({ limit: 2, order: "plays" }), []),
});

React.useEffect(() => {
setTracks(
results.map((r) => ({
...r,
images: {
...r.images,
small: {
// FIXME: There's a bug with the API's `images` being returned
// from fetchTracks. The URLs seem to not point to any existing files.
url: r.cover,
width: 120,
height: 120,
},
},
}))
);
}, [results]);

return (
<>
<h3>Now Playing</h3>
<p
className={css`
margin-bottom: 1rem;
`}
>
What's currently playing in the Resonate ecosystem?
</p>
{isLoading && <CenteredSpinner />}
<TrackList tracks={tracks} />
</>
);
};

export default NowPlaying;
2 changes: 2 additions & 0 deletions src/components/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { tags } from "../constants";
import Tags from "./common/Tags";
import NewReleases from "./NewReleases";
import StaffPicks from "./StaffPicks";
import NowPlaying from "./Explore/NowPlaying";

export const Home: React.FC = () => {
return (
Expand All @@ -20,6 +21,7 @@ export const Home: React.FC = () => {
>
<Tags tags={tags} />
</ul>
<NowPlaying />
<NewReleases />
<StaffPicks />
</div>
Expand Down

0 comments on commit e55f0e7

Please sign in to comment.