Skip to content
Snippets Groups Projects
Commit 7b9cd4fd authored by mrsyaban's avatar mrsyaban
Browse files

last

parent 54f89680
Branches
Tags
No related merge requests found
...@@ -4,7 +4,6 @@ import PodcastCard, { cardProps } from "../../components/PodcastCard"; ...@@ -4,7 +4,6 @@ import PodcastCard, { cardProps } from "../../components/PodcastCard";
import EpisodeCard, { cardEpsProps } from "../../components/EpisodeCard"; import EpisodeCard, { cardEpsProps } from "../../components/EpisodeCard";
import { useEffect, useState, ChangeEvent } from "react"; import { useEffect, useState, ChangeEvent } from "react";
import axios from "axios"; import axios from "axios";
import Select, {ActionMeta} from 'react-select';
// const ChevronIcon = ({isDown} : {isDown : boolean}) => { // const ChevronIcon = ({isDown} : {isDown : boolean}) => {
// return ( // return (
...@@ -18,20 +17,14 @@ const SearchPage = () => { ...@@ -18,20 +17,14 @@ const SearchPage = () => {
const [podcasts, setPodcasts] = useState<cardProps[]>([]); const [podcasts, setPodcasts] = useState<cardProps[]>([]);
const [episodes, setEpisodes] = useState<cardEpsProps[]>([]); const [episodes, setEpisodes] = useState<cardEpsProps[]>([]);
const [keyword, setKeyword] = useState<string>(""); const [keyword, setKeyword] = useState<string>("");
const [selectedGenre, setSelectedGenre] = useState<string | null>("");
const [isShowPodcast, setIsShowPodcast] = useState<boolean>(true); const [isShowPodcast, setIsShowPodcast] = useState<boolean>(true);
const [isShowEps, setIsShowEps] = useState<boolean>(true); const [isShowEps, setIsShowEps] = useState<boolean>(true);
const genres: string[] = [
'comedy',
'technology',
'horror',
];
useEffect(() => { useEffect(() => {
(async () => { (async () => {
const res = await axios.get( const res = await axios.get(
`http://localhost:3000/search/podcast?keyword=${keyword}&genre=${selectedGenre}`, `http://localhost:3000/search/podcast?keyword=${keyword}`,
{ {
headers: { headers: {
Authorization: `Bearer ${localStorage.getItem("token")}`, Authorization: `Bearer ${localStorage.getItem("token")}`,
...@@ -43,12 +36,12 @@ const SearchPage = () => { ...@@ -43,12 +36,12 @@ const SearchPage = () => {
res.data.regularPodcasts, res.data.regularPodcasts,
]); ]);
})() })()
}, [keyword, selectedGenre]) }, [keyword])
useEffect(() => { useEffect(() => {
(async () => { (async () => {
const res = await axios.get( const res = await axios.get(
`http://localhost:3000/search/episode?keyword=${keyword}&genre=${selectedGenre}`, `http://localhost:3000/search/episode?keyword=${keyword}`,
{ {
headers: { headers: {
Authorization: `Bearer ${localStorage.getItem("token")}`, Authorization: `Bearer ${localStorage.getItem("token")}`,
...@@ -60,17 +53,11 @@ const SearchPage = () => { ...@@ -60,17 +53,11 @@ const SearchPage = () => {
res.data.regularEpisodes, res.data.regularEpisodes,
]); ]);
})() })()
}, [keyword, selectedGenre]) }, [keyword])
const handleSearch = (e:ChangeEvent<HTMLInputElement>) => { const handleSearch = (e:ChangeEvent<HTMLInputElement>) => {
setKeyword(e.target.value); setKeyword(e.target.value);
} }
const onHandleGenre = (option: string | null, actionMeta: ActionMeta<string>) => {
setSelectedGenre(option);
actionMeta.action === "clear" && setSelectedGenre(null);
}
return ( return (
...@@ -92,11 +79,6 @@ const SearchPage = () => { ...@@ -92,11 +79,6 @@ const SearchPage = () => {
{/* filter */} {/* filter */}
<div className="flex"> <div className="flex">
<Select
options={genres}
placeholder="Genre"
onChange={onHandleGenre}
/>
</div> </div>
</div> </div>
<div className="flex flex-row gap-2 ml-8 mt-2"> <div className="flex flex-row gap-2 ml-8 mt-2">
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment