Skip to content

Commit

Permalink
Merge pull request #33 from unboxed/architecture-cleanup
Browse files Browse the repository at this point in the history
Move searchArea to separate file and fix button acting strange
  • Loading branch information
HonTastic2 authored Jul 31, 2024
2 parents 7a78b02 + 7f9b2b4 commit 631cb58
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 41 deletions.
43 changes: 2 additions & 41 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import './App.css';
import './govuk-styles.scss';
import axios from 'axios';
import LocationMarker from './components/LocationMarker';
import SearchArea from './components/SearchArea';
import { populateTable, filterTable, sortTable, resetTable} from './components/Table';
// import data from './london-spots.json';
let pageSize = 50;
Expand Down Expand Up @@ -219,46 +220,6 @@ function App () {
}
};

const searchMapArea = async() => {
if (!map) { return; }
var toDisplay = [];

map.eachLayer(function (layer) {
if (layer._latlng === undefined) { return; }

if (map.getBounds().contains(layer._latlng)) {
if (layer.feature) {
toDisplay.push(layer.feature.properties.reference);
}
}

var tr = document.getElementById("applicationTable").getElementsByTagName("tr");

for (let i = 0; i < tr.length; i++) {
var td = tr[i].getElementsByTagName("td")[1];
var tdStat = tr[i].getElementsByTagName("td")[4];
if (td) {
if (document.getElementById("filterSelect").value === "None") {
if (toDisplay.includes(td.innerText)) {
tr[i].style.display = "";
}
else {
tr[i].style.display = "none";
}
}
else {
if (toDisplay.includes(td.innerText) && document.getElementById("filterSelect").value === tdStat.innerText) {
tr[i].style.display = "";
}
else {
tr[i].style.display = "none";
}
}
}
}
});
}

const bindSearchToEnter = () => {
var input = document.getElementById("searchInput");
if (input === null) { return }
Expand Down Expand Up @@ -296,7 +257,7 @@ function App () {
<GeoJSON data={geojson} onEachFeature={onEachFeature} />
<div>
<LocationMarker />
<button className="govuk-button govuk-button--secondary" onClick={searchMapArea} style={{position:"absolute", zIndex:4000, bottom:"-4%", marginLeft:"11em"}}>Search this area</button>
<SearchArea />
</div>
</MapContainer>
</div>
Expand Down
4 changes: 4 additions & 0 deletions src/App.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ jest.mock('./components/LocationMarker', () => {
return jest.fn(() => <div>Mocked LocationMarker</div>);
});

jest.mock('./components/SearchArea', () => {
return jest.fn(() => <div>Mocked SearchArea</div>);
});

test('Loading... is shown on site', () => {
render(<App />);
const loadingElement = screen.getByText(/Loading.../);
Expand Down
58 changes: 58 additions & 0 deletions src/components/SearchArea.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { useMap } from 'react-leaflet';
import { Button } from 'govuk-react';

function SearchArea() {
const map = useMap();

const searchMapArea = async () => {

if (!map) { return; }
var toDisplay = [];

map.eachLayer(function (layer) {
if (layer._latlng === undefined) { return; }

if (map.getBounds().contains(layer._latlng)) {
if (layer.feature) {
toDisplay.push(layer.feature.properties.reference);
}
}

var tr = document.getElementById("applicationTable").getElementsByTagName("tr");

for (let i = 0; i < tr.length; i++) {
var td = tr[i].getElementsByTagName("td")[1];
var tdStat = tr[i].getElementsByTagName("td")[4];
if (td) {
if (document.getElementById("filterSelect").value === "None") {
if (toDisplay.includes(td.innerText)) {
tr[i].style.display = "";
}
else {
tr[i].style.display = "none";
}
}
else {
if (toDisplay.includes(td.innerText) && document.getElementById("filterSelect").value === tdStat.innerText) {
tr[i].style.display = "";
}
else {
tr[i].style.display = "none";
}
}
}
}
});

}
return (
<>
<Button onClick={searchMapArea} buttonColour="#f3f2f1" buttonHoverColour="#ffdd00" buttonShadowColour="#929191" buttonTextColour="#0b0c0c"
style={{ position: 'absolute', bottom: '-4%', left: "21%", zIndex: 4000, width: '170px' }}>
Search this area
</Button>
</>
);
}

export default SearchArea;

0 comments on commit 631cb58

Please sign in to comment.