Skip to content

Commit

Permalink
Merge pull request #198 from bounswe/ip-test
Browse files Browse the repository at this point in the history
Ip test
  • Loading branch information
karatashsyn authored May 17, 2024
2 parents 54858d6 + 035ad5c commit 9d49f42
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/web/animal-trove/src/pages/SearchPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,30 @@ import mockData from "../constants/mockData";
import styles from "./SearchPage.module.css";
import AuthenticatedPage from "../components/AuthenticatedPage";
import { search } from "../services/search";
import PostCard2 from "../components/PostCard2";

export default function SearchPage() {
const [searchTerm, setSearchTerm] = useState("");
const [data, setData] = useState(null);
const [loading, setLoading] = useState(false);
const [postsData, setPostsData] = useState([]);
//f for familia, s for species and u for users
const [mode, setMode] = useState("f");

const handleSearch = async (searchKey) => {
try {
setLoading(true);
const response = await search({ searchTerm: mode + "@" + searchKey });

if (mode === "f") {
setData(response.animalInfoSearch);
} else if (mode === "s") {
setData(response.animalInfoSearch);
} else if (mode === "u") {
setData(response.users);
}
if (response.posts) {
setPostsData(response.posts);
}
} catch (error) {
setData([]);
} finally {
Expand Down Expand Up @@ -86,6 +90,13 @@ export default function SearchPage() {
<p>Found {data.length} results</p>
)}
</div>
<div className={styles.resultsContainer}>
{!loading &&
postsData &&
postsData.map((post) => (
<PostCard2 key={post.postID} post={post} />
))}
</div>
<div className={styles.resultsContainer}>
{!loading &&
data &&
Expand Down

0 comments on commit 9d49f42

Please sign in to comment.