0xVantrex / 0xVantrex/DevHub-JS

Build Search & Filter System (js/search.js)

Đang mở Phù hợp với người mới
#4 0 bình luận 0 reaction 1 người được giao Được @mololukiprotich nhận Xem trên GitHub
Ngôn ngữ chính
HTML
Star
0
Fork
0
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

Goal

Allow users to search profiles by name or skill in real-time as they type — no reloads.
Your job is to make the search input actually filter what’s displayed.

File Ownership

You fully own:
/js/search.js

You’re responsible for:

Writing the filtering logic

Listening to search input changes

Updating visible profiles on screen

Learning Concepts

input event listeners

filter() and includes() methods

DOM updates (hide/show elements)

Working with modules

Functional Requirements
1. Search Input Setup

In the HTML (already or soon to be added), there’s a search box like:

You’ll attach your logic to that.

2. Create Main Function

Create a function named:

function setupSearch(profilesArray) { ... }

Inside this function:

Grab the input element

const searchInput = document.getElementById("searchInput");

Add an event listener

searchInput.addEventListener("input", () => {
const searchTerm = searchInput.value.toLowerCase();
const filteredProfiles = profilesArray.filter(profile => {
return (
profile.name.toLowerCase().includes(searchTerm) ||
profile.skills.toLowerCase().includes(searchTerm)
);
});
displayFilteredProfiles(filteredProfiles);
});

Create Helper Function

function displayFilteredProfiles(filtered) {
const container = document.getElementById("profilesContainer");
container.innerHTML = "";
filtered.forEach(profile => {
const div = document.createElement("div");
div.classList.add("profile-card");
div.innerHTML = `

${profile.name}


${profile.skills}


`;
container.appendChild(div);
});
}

3. Export the Function
export { setupSearch };

4. Integration Example

Your teammate from profiles.js or app.js will use:

import { setupSearch } from "./search.js";

setupSearch(profiles);

That’s it — your search will kick in whenever the user types.

Definition of Done

Typing filters profiles instantly (by name or skill)

Case-insensitive search

No console errors

DOM updates happen cleanly

All code inside js/search.js

Optional

Highlight the matching text inside results

Add a “No results found” message when the array is empty

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Hướng nghiên cứu

The work is in js/search.js. Start by examining the existing HTML for the search input with id 'searchInput' and the profiles container with id 'profilesContainer'. Implement the setupSearch function as described, using event listeners and filter logic. Test by typing in the search box and verifying profiles are filtered. Done when typing filters profiles instantly, case-insensitively, with no console errors.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
javascript
Lĩnh vực
frontend
Loại issue
Tính năng
Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
90/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.