Skip to content

Commit

Permalink
Search: UI search page, handle search results with keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
an678-mhg committed Aug 24, 2022
1 parent 6c57229 commit 821d733
Show file tree
Hide file tree
Showing 18 changed files with 339 additions and 88 deletions.
6 changes: 4 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import VideoDetails from "./pages/Detail/VideoDetails";
import useStore from "./zustand/menu";
import ArtistDetails from "./pages/Detail/ArtistDetails";
import Error from "./components/Error";
import Search from "./pages/Search";
import Search from "./pages/Search/Search";
import Topics from "./pages/ListenToday/Topics";
import TopicDetails from "./pages/Detail/TopicDetails";
import Results from "./pages/Search/Results";

function App() {
const { player, close } = useStore();
Expand Down Expand Up @@ -42,6 +43,7 @@ function App() {
<Routes>
<Route path="/" element={<Home />} />
<Route path="/search" element={<Search />} />
<Route path="/results" element={<Results />} />
<Route path="/PLAYLIST/:key" element={<PlaylistsDetails />} />
<Route path="/VIDEO/:key" element={<VideoDetails />} />
<Route path="/TOPIC/:key" element={<TopicDetails />} />
Expand All @@ -59,7 +61,7 @@ function App() {
right: isPC ? "0px" : player ? "0" : "-100%",
transition: "all linear 0.3s",
}}
className={`scroll-none overflow-y-scroll md:w-[300px] w-full max-w-full border-l border-r [rgba(28,30,32,0.05)] px-4 h-screen pt-6 fixed top-0 bottom-0 z-[9999] bg-white`}
className={`scroll-none overflow-y-scroll md:w-[300px] w-full max-w-full border-l border-r [rgba(28,30,32,0.05)] px-4 h-screen pt-4 fixed top-0 bottom-0 z-[9999] bg-white`}
>
<Player />
</div>
Expand Down
5 changes: 5 additions & 0 deletions src/apis/artist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ export const getArtistDetails = async (key: string) => {

return data.data;
};

export const getTrendingArtists = async () => {
const data = await client.get("/trendingArtists");
return data.data;
};
2 changes: 1 addition & 1 deletion src/apis/client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axios from "axios";

export default axios.create({
baseURL: "https://proxy-nct.vercel.app",
baseURL: "http://localhost:3001",
});
16 changes: 16 additions & 0 deletions src/apis/search.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import client from "./client";

export const getTopKeyword = async () => {
const res = await client.get("top-keyword");
return res.data;
};

export const searchKeyword = async (keyword: string) => {
const res = await client.get("search", {
params: {
keyword,
},
});

return res.data;
};
27 changes: 15 additions & 12 deletions src/components/Error.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
import { Link } from "react-router-dom";
import MainLayout from "../layout/MainLayout";
import { img404 } from "../utils/contants";

const Error = () => {
return (
<div className="h-screen flex items-center justify-center">
<div>
<MainLayout>
<div className="flex items-center justify-center">
<div>
<img src={img404} alt="not-found" />
</div>
<div className="w-full flex justify-center">
<Link
className="bg-gray-400 px-4 py-2 text-white rounded-md font-semibold block"
to="/"
>
Trở lại trang chủ
</Link>
<div>
<img src={img404} alt="not-found" />
</div>
<div className="w-full flex justify-center">
<Link
className="bg-gray-400 px-4 py-2 text-white rounded-md font-semibold block"
to="/"
>
Trở lại trang chủ
</Link>
</div>
</div>
</div>
</div>
</MainLayout>
);
};

Expand Down
12 changes: 0 additions & 12 deletions src/components/Loading.tsx

This file was deleted.

8 changes: 4 additions & 4 deletions src/components/Player/PlayerThumnail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ const PlayerThumnail: FC<PlayerThumnailProps> = ({
}) => {
return (
<div
className={`bg-[rgba(28,30,32,0.02)] rounded-md mb-10 relative ${
className={`bg-[rgba(28,30,32,0.02)] rounded-md mb-5 relative ${
showListSong && "h-full"
}`}
>
<div className="w-full flex justify-center pt-5 py-2 md:hidden">
<div className="w-full flex justify-center p-4 md:hidden">
<GrClose onClick={() => setPlayer()} className="w-5 h-5" />
</div>
{showListSong ? (
<ListSong setCurrentIndex={setCurrentIndexMemo} songIds={songMemo} />
) : (
<div>
<div className="p-4">
<div className="w-full aspect-auto">
<div className="pr-4 pl-4 pb-4">
<div className="w-full aspect-[1/1]">
<LazyLoadImage
className="rounded-md border"
src={thumbnail || imgNotFound}
Expand Down
54 changes: 27 additions & 27 deletions src/components/Player/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { getSong } from "../../apis/song";
import Controler from "./Controler";
import PlayReview from "../Song/PlayReview";
import { toast } from "react-hot-toast";
import Loading from "../Loading";

const Player = () => {
const { songIds, currentIndex, setCurrentIndex } = useContext(PlayerContext);
Expand Down Expand Up @@ -76,14 +75,21 @@ const Player = () => {
audioRef.current.play();
}, [songIds, data, songKey]);

// useEffect(() => {
// if (data?.song?.streamUrls?.length === 0) {
// toast.error("Không tìm thấy bài hát!");
// if (currentIndex <= songIds.length - 1) {
// handleNextSong();
// }
// }
// }, [data?.song?.streamUrls]);
useEffect(() => {
if (data?.song?.streamUrls?.length === 0) {
toast.error("Không tìm thấy bài hát!");
if (currentIndex === songIds.length) {
return;
}

return handleNextSong();
}
}, [data?.song?.streamUrls]);

useEffect(() => {
audioRef?.current?.pause();
setCurrentTime(0);
}, [currentIndex]);

useEffect(() => {
if (!audioRef.current) return;
Expand Down Expand Up @@ -161,7 +167,7 @@ const Player = () => {
() =>
setCurrentIndex((prev: number) => {
if (prev >= songIds.length - 1) {
return 0;
return prev;
}

return prev + 1;
Expand All @@ -173,7 +179,7 @@ const Player = () => {
() =>
setCurrentIndex((prev: number) => {
if (prev <= 0) {
return songIds.length - 1;
return prev;
}

return prev - 1;
Expand Down Expand Up @@ -201,22 +207,16 @@ const Player = () => {
setShowConTrolVolume(false);
}}
>
{!data ? (
<Loading />
) : (
<PlayerThumnail
thumbnail={data?.song?.thumbnail}
title={data?.song?.title}
artists={data?.song?.artists
?.map((item: any) => item.name)
.join(", ")}
setCurrentIndexMemo={setCurrentIndexMemo}
setPlayer={setPlayerMemo}
showListSong={showListSong}
songMemo={songMemo}
key={"player"}
/>
)}
<PlayerThumnail
thumbnail={data?.song?.thumbnail}
title={data?.song?.title}
artists={data?.song?.artists?.map((item: any) => item.name).join(", ")}
setCurrentIndexMemo={setCurrentIndexMemo}
setPlayer={setPlayerMemo}
showListSong={showListSong}
songMemo={songMemo}
key={"player"}
/>

<Controler
audioRef={audioRef}
Expand Down
22 changes: 22 additions & 0 deletions src/components/Search/TrendingItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React, { FC } from "react";
import { Link } from "react-router-dom";

interface TrendingItemProps {
position: string;
name: string;
}

const TrendingItem: FC<TrendingItemProps> = ({ position, name }) => {
return (
<Link
to={`/results?q=${name}`}
className="bg-gray-200 py-1 px-2 flex items-center rounded-sm cursor-pointer"
>
<span className="text-blue-500 font-semibold">#{position}</span>

<p className="text-gray-400 text-sm font-normal ml-1">{name}</p>
</Link>
);
};

export default TrendingItem;
4 changes: 2 additions & 2 deletions src/components/Skeleton/ListSongSkeleton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import SongItemSkeleton from "./SongItemSkeleton";

const ListSongSkeleton = () => {
return (
<>
<div className="my-5">
<div>
<h1 className="w-[200px] h-6 mt-4 skeleton"></h1>
</div>
Expand All @@ -20,7 +20,7 @@ const ListSongSkeleton = () => {
<SongItemSkeleton />
<SongItemSkeleton />
</div>
</>
</div>
);
};

Expand Down
17 changes: 17 additions & 0 deletions src/components/Skeleton/ResultsSkeleton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from "react";
import ListSongSkeleton from "./ListSongSkeleton";
import SliderSkeleton from "./SliderSkeleton";

const ResultsSkeleton = () => {
return (
<div>
<h1 className="mb-5 font-semibold text-2xl h-8 skeleton"></h1>

<ListSongSkeleton />
<SliderSkeleton />
<SliderSkeleton />
</div>
);
};

export default ResultsSkeleton;
37 changes: 37 additions & 0 deletions src/components/Skeleton/SearchSkeleton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React from "react";

const SearchSkeleton = () => {
return (
<>
<div className="mt-5">
<h1 className="mb-5 font-semibold text-xl skeleton h-6"></h1>
<div className="flex items-center flex-wrap gap-2">
<div className="w-[100px] py-4 skeleton"></div>
<div className="w-[100px] py-4 skeleton"></div>
<div className="w-[100px] py-4 skeleton"></div>
<div className="w-[100px] py-4 skeleton"></div>
<div className="w-[100px] py-4 skeleton"></div>
<div className="w-[100px] py-4 skeleton"></div>
<div className="w-[100px] py-4 skeleton"></div>
<div className="w-[100px] py-4 skeleton"></div>
</div>
</div>

<div className="mt-5">
<h1 className="mb-5 font-semibold text-xl skeleton h-6"></h1>
<div className="flex items-center flex-wrap gap-2">
<div className="w-[100px] py-4 skeleton"></div>
<div className="w-[100px] py-4 skeleton"></div>
<div className="w-[100px] py-4 skeleton"></div>
<div className="w-[100px] py-4 skeleton"></div>
<div className="w-[100px] py-4 skeleton"></div>
<div className="w-[100px] py-4 skeleton"></div>
<div className="w-[100px] py-4 skeleton"></div>
<div className="w-[100px] py-4 skeleton"></div>
</div>
</div>
</>
);
};

export default SearchSkeleton;
4 changes: 2 additions & 2 deletions src/components/Skeleton/SliderSkeleton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import GridLayout from "../../layout/GridLayout";

const SliderSkeleton = () => {
return (
<>
<div className="my-5">
<div>
<h1 className="mb-5 skeleton h-6 w-[150px]"></h1>
</div>
Expand All @@ -13,7 +13,7 @@ const SliderSkeleton = () => {
<div className="skeleton aspect-[1/1] rounded-md"></div>
<div className="skeleton aspect-[1/1] rounded-md"></div>
</GridLayout>
</>
</div>
);
};

Expand Down
4 changes: 2 additions & 2 deletions src/pages/Detail/ArtistDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ const ArtistDetails = () => {

{data?.playlist?.playlist && (
<div>
<h1 className="mb-5 font-semibold text-xl">Playlist</h1>
<h1 className="my-5 font-semibold text-xl">Playlist</h1>
<Slider banners={data?.playlist?.playlist} />
</div>
)}

{data?.video?.video && (
<div>
<h1 className="mb-5 font-semibold text-xl">Video</h1>
<h1 className="my-5 font-semibold text-xl">Video</h1>
<Slider radio="16/9" banners={data?.video?.video} />
</div>
)}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Detail/VideoDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const VideoDetails = () => {
<p className="mt-5 flex items-center">
{data?.video?.artists?.map((item: any) => (
<Link
to={item.artistId ? `/ARTIST/${item.artistId}` : "#"}
to={item.shortLink ? `/ARTIST/${item.shortLink}` : "#"}
key={item.artistId}
>
<div className="rounded-full w-10 h-10 overflow-hidden border">
Expand Down
23 changes: 0 additions & 23 deletions src/pages/Search.tsx

This file was deleted.

Loading

1 comment on commit 821d733

@vercel
Copy link

@vercel vercel bot commented on 821d733 Aug 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nct-clone – ./

nct-clone-git-master-an678-mhg.vercel.app
nct-clone-an678-mhg.vercel.app
nct-clone.vercel.app

Please sign in to comment.