Skip to content

Commit 90a4171

Browse files
committed
fix (#5)
1 parent d17b158 commit 90a4171

File tree

3 files changed

+39
-14
lines changed

3 files changed

+39
-14
lines changed

src/App.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,13 @@ background: rgb(186 22 163) !important;
4343
transform: rotate(360deg);
4444
}
4545
}
46+
/* Default state for search input */
47+
.input-group .form-control {
48+
width: 150px;
49+
transition: width 0.3s ease-in-out;
50+
}
51+
52+
/* Expanded state when the input is focused */
53+
.search-expanded .form-control {
54+
width: 300px; /* You can adjust this width */
55+
}

src/components/Navbar.jsx

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function Navbar({ loggedin }) {
1717
if (searchTerm) {
1818
// Redirect to the search results page with the search term
1919
navigate(`/search?query=${encodeURIComponent(searchTerm)}`);
20-
setSearchTerm(''); // Clear the input after submission
20+
// setSearchTerm(''); // Clear the input after submission
2121
}
2222
};
2323

@@ -55,13 +55,23 @@ function Navbar({ loggedin }) {
5555
</ul>
5656
<div className="d-flex align-items-center flex-column flex-lg-row">
5757
<form className="me-2 mb-2 mb-lg-0" onSubmit={handleSearchSubmit}>
58-
<input
59-
type="text"
60-
className="form-control form-control-sm"
61-
placeholder="Search"
62-
value={searchTerm}
63-
onChange={handleSearchChange}
64-
/>
58+
<div class="input-group">
59+
<span class="input-group-text" id="basic-addon1">
60+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-search" viewBox="0 0 16 16">
61+
<path d="M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001q.044.06.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1 1 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0"></path>
62+
</svg>
63+
</span>
64+
{/* <input type="text" class="form-control" placeholder="Input group example" /> */}
65+
66+
<input
67+
type="text"
68+
className="form-control"
69+
// aria-label="Input group example"
70+
// aria-describedby="basic-addon1"
71+
placeholder="Search"
72+
value={searchTerm}
73+
onChange={handleSearchChange}
74+
/> </div>
6575
</form>
6676
{loggedin === 'true' ? (
6777
<Link className="btn btn-primary clk" to="/profile">Profile </Link>

src/components/search.jsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@ import React from 'react';
22
import { useLocation } from 'react-router-dom';
33
import courses from './courseData'; // Ensure the path is correct
44
import { Link } from 'react-router-dom';
5+
56
const useQuery = () => {
67
return new URLSearchParams(useLocation().search);
78
};
89

910
function SearchResults() {
1011
const query = useQuery();
1112
const searchTerm = query.get('query')?.toLowerCase() || '';
12-
13+
1314
// Filter courses based on the search term
14-
const filteredCourses = Object.values(courses).filter(course =>
15+
const filteredCourses = Object.entries(courses).filter(([key, course]) =>
1516
course.title.toLowerCase().includes(searchTerm) ||
1617
course.description.toLowerCase().includes(searchTerm)
1718
);
@@ -20,10 +21,11 @@ function SearchResults() {
2021
<div className="container mt-5">
2122
<h2>Search Results for "{searchTerm}"</h2>
2223
<div className="row row-cols-1 row-cols-md-3 g-3">
23-
{Object.entries(courses).map(([key, course], index) => (
24+
{filteredCourses.length > 0 ? (
25+
filteredCourses.map(([key, course], index) => (
2426
<div className="col" key={index}>
2527
<div className="card h-100">
26-
<Link to={`/courses/${key}`} className='lnk'>
28+
<Link to={`/courses/${key}`} className="lnk">
2729
<img src={course.image} className="card-img-top" alt={course.title} />
2830
<div className="card-body">
2931
<h5 className="card-title">{course.title}</h5>
@@ -32,9 +34,12 @@ function SearchResults() {
3234
</Link>
3335
</div>
3436
</div>
35-
))}
36-
</div>
37+
))
38+
) : (
39+
<p>No courses match your search term.</p>
40+
)}
3741
</div>
42+
</div>
3843
);
3944
}
4045

0 commit comments

Comments
 (0)