Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to add search bar #28

Merged
merged 1 commit into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions js/accident.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ function processCrime(list) {
return newArray;
}

function filterList(list, filterInputValue) {
return list.filter((item) => {
if (!item.street_address) { return; }
const lowerCaseName = item.street_address.toLowerCase();
const lowerCaseQuery = filterInputValue.toLowerCase();
return lowerCaseName.includes(lowerCaseQuery);
});
}

function initMap() {
console.log('initMap');
const map = L.map('map').setView([38.9897, -76.9378], 11);
Expand Down Expand Up @@ -91,11 +100,11 @@ async function mainEvent() {
loadAnimation.classList.add('lds-ellipsis_hidden');

let currentList = [];

form.addEventListener('input', (event) => {
console.log(event.target.value);
console.log('input', event.target.value);
const newFilterList = filterList(currentList, event.target.value);
injectHTML(newFilterList);
markerPlace(newFilterList, pageMap);
injectHTML(newFilterList, pageMap);
});

form.addEventListener('submit', (submitEvent) => {
Expand Down
6 changes: 6 additions & 0 deletions other_pages/accident.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ <h3>Accident Occurrences</h3>
<div class="lds-ellipsis"><div></div><div></div><div></div><div></div></div>
<button type="submit" id="get-resto">Show accidents...</button>
</form>
<form action="/api" class="main_form">
<div>
<label for="resto">Enter Street Name or Address</label>
<input type="text" name="resto" id="resto" />
</div>
</form>
<div class="box" id="crime_list">A list of accidents</div>
</div>
</div>
Expand Down