Skip to content

Commit

Permalink
Customise Layout, Show Features, Add Play/Pause Debounce, Redesign Al…
Browse files Browse the repository at this point in the history
…bum Card (#140)
  • Loading branch information
WillKirkmanM authored Sep 27, 2024
2 parents ae41c53 + 82cbc45 commit df232f3
Show file tree
Hide file tree
Showing 29 changed files with 1,070 additions and 159 deletions.
1 change: 1 addition & 0 deletions apps/web/app/(app)/artist/ArtistComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export default function ArtistComponent() {
album_id={album.id}
album_name={album.name}
album_cover={album.cover_url}
album_songs_count={album.songs.length}
first_release_date={album.first_release_date}
/>
</div>
Expand Down
1 change: 1 addition & 0 deletions apps/web/app/(app)/explore/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export default function ExplorePage() {
album_id={albumDetails[album.id]?.id ?? ""}
album_name={albumDetails[album.id]?.name ?? ""}
album_cover={albumDetails[album.id]?.cover_url ?? ""}
album_songs_count={Number(albumDetails[album.id]?.songs.length) ?? ""}
first_release_date={albumDetails[album.id]?.first_release_date ?? ""}
/>
) : null}
Expand Down
165 changes: 103 additions & 62 deletions apps/web/app/(app)/home/page.tsx
Original file line number Diff line number Diff line change
@@ -1,63 +1,104 @@
"use client";

import FromYourLibrary from "@/components/Home/FromYourLibrary";
import LandingCarousel from "@/components/Home/LandingCarousel";
import ListenAgain from "@/components/Home/ListenAgain";
import MusicVideos from "@/components/Home/MusicVideos";
import RandomSongs from "@/components/Home/RandomSongs";
import RecommendedAlbums from "@/components/Home/RecommendedAlbums";
import SimilarTo from "@/components/Home/SimilarTo";
import GenreButtons from "@/components/Layout/GenreButtons";
import { useGradientHover } from "@/components/Providers/GradientHoverProvider";
import { getConfig, hasConfig } from "@music/sdk";
import { Button } from "@music/ui/components/button";
import Link from "next/link";
import { useEffect, useState } from "react";

export default function Home() {
let [configExists, setConfigExists] = useState(true);

const { setGradient } = useGradientHover()

useEffect(() => {
async function checkConfig() {
const config = await hasConfig();
if (config) {
setConfigExists(true);
} else {
setConfigExists(false);
setGradient("#FFFFFF")
}
}

checkConfig();
}, [setGradient]);

return configExists ? (
<div className="min-h-screen pt-14 pb-20">
<GenreButtons>
<div className="pb-5">
<LandingCarousel />
"use client";

import FromYourLibrary from "@/components/Home/FromYourLibrary";
import LandingCarousel from "@/components/Home/LandingCarousel";
import ListenAgain from "@/components/Home/ListenAgain";
import MusicVideos from "@/components/Home/MusicVideos";
import RandomSongs from "@/components/Home/RandomSongs";
import RecommendedAlbums from "@/components/Home/RecommendedAlbums";
import SimilarTo from "@/components/Home/SimilarTo";
import CustomiseFeed from "@/components/Layout/CustomiseFeed";
import GenreButtons from "@/components/Layout/GenreButtons";
import { useGradientHover } from "@/components/Providers/GradientHoverProvider";
import { hasConfig } from "@music/sdk";
import { Button } from "@music/ui/components/button";
import Link from "next/link";
import { useEffect, useState } from "react";
import { useLayoutConfig } from "@/components/Providers/LayoutConfigContext";

export default function Home() {
const [configExists, setConfigExists] = useState(true);
const { components, setComponents } = useLayoutConfig();

const { setGradient } = useGradientHover();

useEffect(() => {
async function checkConfig() {
const config = await hasConfig();
if (config) {
setConfigExists(true);
} else {
setConfigExists(false);
setGradient("#FFFFFF");
}
}

checkConfig();
}, [setGradient]);

useEffect(() => {
const savedConfig = localStorage.getItem("layoutConfig");
if (savedConfig) {
setComponents(JSON.parse(savedConfig));
}
}, [setComponents]);

type ComponentConfig = {
id: string;
name: string;
visible: boolean;
pinned: boolean;
};

const renderComponent = (component: ComponentConfig): JSX.Element | null => {
if (!component.visible) return null;
switch (component.id) {
case "LandingCarousel":
return <LandingCarousel key={component.id} />;
case "ListenAgain":
return <ListenAgain key={component.id} />;
case "SimilarTo":
return <SimilarTo key={component.id} />;
case "RecommendedAlbums":
return <RecommendedAlbums key={component.id} />;
case "RandomSongs":
return <RandomSongs key={component.id} />;
case "FromYourLibrary":
return <FromYourLibrary key={component.id} />;
case "MusicVideos":
return <MusicVideos key={component.id} />;
default:
return null;
}
};

return configExists ? (
<div className="min-h-screen pt-4 pb-20">
<div className="relative pr-32 pt-8 z-10 top top-14 flex flex-col items-end">
<CustomiseFeed />
</div>
<GenreButtons>
{components
.filter((component) => component.pinned)
.map(renderComponent)}
{components
.filter((component) => !component.pinned)
.map(renderComponent)}
</GenreButtons>
</div>
<ListenAgain />
<SimilarTo />
<RecommendedAlbums />
<RandomSongs />
<FromYourLibrary />
<MusicVideos />
</GenreButtons>
</div>
) : (
<>
<div className="min-h-screen flex flex-col justify-center items-center space-y-4">
<p className="text-5xl">No Config Found!</p>
<p className="font-semibold">
<Link href="/setup/library" className="underline">Head to the setup page to index your library</Link>
</p>
<Link href="/setup/library">
<Button className="bg-white text-black hover:bg-gray-500">Head to Setup Page</Button>
</Link>
</div>
</>
);
}
) : (
<div className="min-h-screen flex flex-col justify-center items-center space-y-4">
<p className="text-5xl">No Config Found!</p>
<p className="font-semibold">
<Link href="/setup/library" className="underline">
Head to the setup page to index your library
</Link>
</p>
<Link href="/setup/library">
<Button className="bg-white text-black hover:bg-gray-500">
Head to Setup Page
</Button>
</Link>
</div>
);
}
2 changes: 1 addition & 1 deletion apps/web/app/(app)/main-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default function MainLayout({ children }: any) {
<Sidebar
sidebarContent={
<>
<Separator className="bg-gray-800" />
{/* <Separator className="bg-gray-800" /> */}
<Suspense>
<FriendActivity />
</Suspense>
Expand Down
1 change: 1 addition & 0 deletions apps/web/app/(app)/profile/UsernameComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export default function UsernameComponent() {
album_id={album.id}
album_name={album.name}
album_cover={album.cover_url}
album_songs_count={album.songs.length}
first_release_date={album.first_release_date}
key={album.id}
/>
Expand Down
2 changes: 1 addition & 1 deletion apps/web/components/Artist/SongsInLibrary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default function FromYourLibrary() {
}, [id]);

return librarySongs.length > 0 && (
<ScrollButtons heading="In your Library">
<ScrollButtons heading="In your Library" id="InYourLibrary">
<div className="flex flex-row justify-start items-start pb-20">
{librarySongs.map((song, index) => (
<div key={index} className="w-full sm:w-1/2 md:w-1/3 lg:w-1/4 p-8">
Expand Down
2 changes: 1 addition & 1 deletion apps/web/components/Home/FromYourLibrary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default function FromYourLibrary({ genre }: FromYourLibraryProps) {
if (!librarySongs || librarySongs.length === 0) return null;

return (
<ScrollButtons heading="From Your Library">
<ScrollButtons heading="From Your Library" id="FromYourLibrary">
<div className="flex flex-row pb-28">
{librarySongs.map((song, index) => (
<div className="mr-20" key={index}>
Expand Down
3 changes: 2 additions & 1 deletion apps/web/components/Home/ListenAgain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function ListenAgain({ genre }: ListenAgainProps) {
return listenHistorySongs && (
<>
<PageGradient imageSrc={albumCoverSrc} />
<ScrollButtons heading="Listen Again" showUser>
<ScrollButtons heading="Listen Again" showUser id="ListenAgain">
<div className="flex flex-row pb-28">
{listenHistorySongs.map((item, index) => {
if (item.item_type === "album") {
Expand All @@ -48,6 +48,7 @@ export default function ListenAgain({ genre }: ListenAgainProps) {
album_id={item.album_id}
album_name={item.album_name}
album_cover={item.album_cover ?? ""}
album_songs_count={item.album_songs_count}
first_release_date={item.release_date}
/>
</div>
Expand Down
2 changes: 1 addition & 1 deletion apps/web/components/Home/MusicVideos.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default function MusicVideos() {
if (loading) return null;

return songs && (
<ScrollButtons heading="Music Videos">
<ScrollButtons heading="Music Videos" id="MusicVideos">
<div className="flex flex-row">
{songs.map((song) => (
<MusicVideoCard key={song.id} song={song} />
Expand Down
2 changes: 1 addition & 1 deletion apps/web/components/Home/RandomSongs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default function RandomSongs({ genre }: RandomSongsProps) {
if (!randomSongs || randomSongs.length === 0) return null;

return (
<ScrollButtons heading="Random Selection">
<ScrollButtons heading="Random Selection" id="RandomSongs">
<div className="flex flex-row pb-28">
{randomSongs.map((song, index) => (
<div className="mr-20" key={index}>
Expand Down
3 changes: 2 additions & 1 deletion apps/web/components/Home/RecommendedAlbums.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,15 @@ export default function RecommendedAlbums({ genre }: RecommendedAlbumsProps) {
if (!librarySongs || librarySongs.length === 0) return null;

return (
<ScrollButtons heading="Recommended Albums">
<ScrollButtons heading="Recommended Albums" id="RecommendedAlbums">
<div className="flex flex-row pb-28">
{librarySongs.map((song, index) => (
<div className="mr-20" key={index}>
<AlbumCard
album_cover={song.album_object.cover_url}
album_id={song.album_object.id}
album_name={song.album_object.name}
album_songs_count={song.album_object.songs.length}
artist_id={song.artist_object.id}
artist_name={song.artist}
first_release_date={song.album_object.first_release_date}
Expand Down
Loading

0 comments on commit df232f3

Please sign in to comment.