Skip to content

Commit

Permalink
feat: search keywords and companies
Browse files Browse the repository at this point in the history
  • Loading branch information
frank-mendez committed Aug 6, 2024
1 parent 42bb55a commit 9937a34
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 3 deletions.
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"prettier": "^3.3.3",
"query-string": "^9.1.0",
"react": "^18.3.1",
"react-country-flag": "^3.1.0",
"react-dom": "^18.3.1",
"react-router-dom": "^6.25.1"
},
Expand Down
8 changes: 7 additions & 1 deletion src/pages/home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useNavigate, useSearchParams } from "react-router-dom";

const Home = () => {
const navigate = useNavigate();
const [search, setSearch] = useSearchParams();
const [trendingTab, setTrendingTab] = useState<TrendingTabEnum>(
TrendingTabEnum.TODAY,
);
Expand All @@ -28,7 +29,11 @@ const Home = () => {
navigate(`/search?${search.toString()}`);
};

const [search, setSearch] = useSearchParams();
const handleKeyDown = (e: React.KeyboardEvent) => {
if (e.key === "Enter") {
handleSearch();
}
};

return (
<AppLayout>
Expand All @@ -43,6 +48,7 @@ const Home = () => {
placeholder="Search for a movie, tv show, person"
value={search.get("query") || ""}
onChange={(e) => setSearch({ query: e.target.value })}
onKeyDown={handleKeyDown}
/>
<button className="btn" onClick={handleSearch}>
Search
Expand Down
19 changes: 19 additions & 0 deletions src/pages/search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { SearchTabTypes } from "../../types";
import SearchTab from "./SearchTab.tsx";
import SearchMovieResult from "./SearchMovieResult.tsx";
import SearchPeopleResult from "./SearchPeopleResult.tsx";
import SearchKeywordResult from "./SearchKeywordResult.tsx";
import SearchCompanyResult from "./SearchCompanyResult.tsx";

const Search = () => {
const [search, setSearch] = useSearchParams();
Expand Down Expand Up @@ -45,6 +47,7 @@ const Search = () => {
const currentPage = parseInt(search.get("page") || "1") - 1;

const handleTabChange = (value: SearchTabEnums) => {
setSearch({ page: "1", query: search.get("query") || "" });
setCurrentSearchTab(value);
};

Expand Down Expand Up @@ -155,6 +158,22 @@ const Search = () => {
handlePageChange={handlePageChange}
/>
)}
{currentSearchTab === SearchTabEnums.KEYWORDS && (
<SearchKeywordResult
loading={keywordPending}
data={keywordData}
handlePageChange={handlePageChange}
currentPage={currentPage}
/>
)}
{currentSearchTab === SearchTabEnums.COMPANIES && (
<SearchCompanyResult
loading={companyPending}
data={companyData}
currentPage={currentPage}
handlePageChange={handlePageChange}
/>
)}
</div>
</div>
</AppLayout>
Expand Down
43 changes: 42 additions & 1 deletion src/pages/search/SearchCompanyResult.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,44 @@
const SearchCompanyResult = () => {};
import { SearchMovieResultProps } from "../../types";
import SearchPagination from "./SearchPagination.tsx";
import ReactCountryFlag from "react-country-flag";

const SearchCompanyResult = ({
loading,
data,
currentPage,
handlePageChange,
}: SearchMovieResultProps) => {
return (
<div className={`${loading ? "skeleton w-52 h-12" : ""}`}>
<div className="grid grid-cols-4 gap-4 mb-10">
{data &&
data.results.map((result) => (
<div
key={result.id}
className="rounded-btn bg-base-200 p-4 cursor-pointer"
>
{result.logo_path && (
<img
src={`https://image.tmdb.org/t/p/w500${result.logo_path}`}
alt={result.name}
className="w-auto h-auto"
/>
)}
<p> Name: {result.name}</p>
<p> Origin Country: {result.origin_country ?? "N/A"}</p>{" "}
{result.origin_country && (
<ReactCountryFlag countryCode={result.origin_country} />
)}
</div>
))}
</div>
<SearchPagination
currentPage={currentPage}
data={data}
handlePageChange={handlePageChange}
/>
</div>
);
};

export default SearchCompanyResult;
29 changes: 28 additions & 1 deletion src/pages/search/SearchKeywordResult.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
const SearchKeywordResult = () => {};
import { Link } from "react-router-dom";
import { SearchMovieResultProps } from "../../types";
import SearchPagination from "./SearchPagination.tsx";

const SearchKeywordResult = ({
loading,
data,
currentPage,
handlePageChange,
}: SearchMovieResultProps) => {
return (
<div className={`${loading ? "skeleton w-52 h-12" : ""}`}>
<ul>
{data &&
data.results.map((result) => (
<li key={result.id}>
<Link to="/">{result.name}</Link>
</li>
))}
</ul>
<SearchPagination
currentPage={currentPage}
data={data}
handlePageChange={handlePageChange}
/>
</div>
);
};

export default SearchKeywordResult;

0 comments on commit 9937a34

Please sign in to comment.