Skip to content

Commit

Permalink
Related Posts showing on search
Browse files Browse the repository at this point in the history
  • Loading branch information
karatashsyn committed May 17, 2024
1 parent 54858d6 commit a72ba37
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
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
3 changes: 2 additions & 1 deletion src/web/animal-trove/src/services/api.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import axios from "axios";

const api = axios.create({
baseURL: "http://165.22.95.135:8080/api",
// baseURL: "http://165.22.95.135:8080/api",
baseURL: "http://localhost:8080/api",
});

export default api;

0 comments on commit a72ba37

Please sign in to comment.