Skip to content
This repository was archived by the owner on Aug 8, 2019. It is now read-only.

Commit d758d6b

Browse files
authored
Merge pull request #30 from codeableorg/feature-filter-by-district
Add filters by district
2 parents cdef835 + 89f1999 commit d758d6b

3 files changed

Lines changed: 10 additions & 30 deletions

File tree

client/src/components/club-card.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

client/src/index.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,8 @@ function App() {
5050
<OwnerHome path="/owner" />
5151
<CreateClub path="/create-club" />
5252
<CreateSportField path="/create-sport-field" />
53-
<<<<<<< HEAD
5453
<OwnerSportField path="/owner-sport-field/:id" />
55-
=======
5654
<Favorites path="/favorites" />
57-
>>>>>>> Get favorite clubs
5855
</Router>
5956
</main>
6057
</>

client/src/views/home.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { jsx } from "@emotion/core";
44
import { useSetClubs } from "../actions/action-hooks";
55
import { useClubs } from "../selectors/selectors";
66
import { getClubs } from "../services/club";
7-
import ClubCard from "../components/club-card";
87
import Club from "../components/club";
98
import { getDistance } from "geolib";
109
import { Select } from "../components/ui";
@@ -13,7 +12,7 @@ function Home() {
1312
const clubs = useClubs();
1413
const setClubs = useSetClubs();
1514
const [position, setPosition] = React.useState([0, 0]);
16-
const [selectedLocation, setSelectedLocation] = React.useState();
15+
const [selectedLocation, setSelectedLocation] = React.useState("");
1716
const [sortType, setSortType] = React.useState("location");
1817

1918
React.useEffect(() => {
@@ -42,12 +41,10 @@ function Home() {
4241
}, [setPosition]);
4342

4443
function handleChangeLocation(e) {
45-
console.log(e.target.value);
4644
setSelectedLocation(e.target.value);
4745
}
4846

4947
function handleChangeSortType(e) {
50-
console.log(e.target.value);
5148
setSortType(e.target.value);
5249
}
5350

@@ -67,6 +64,14 @@ function Home() {
6764
}
6865
}
6966

67+
function filterBy(club) {
68+
if (selectedLocation !== "") {
69+
return selectedLocation === club.district;
70+
} else {
71+
return true;
72+
}
73+
}
74+
7075
const styleSelectsContainer = {
7176
display: "flex",
7277
justifyContent: "space-between",
@@ -115,9 +120,9 @@ function Home() {
115120
distance = setDistance(club, position);
116121
}
117122
club.distance = distance;
118-
console.log(club);
119123
return club;
120124
})
125+
.filter(filterBy)
121126
.sort(sortBy)
122127
.map(club => {
123128
return <Club key={club.id} club={club} />;

0 commit comments

Comments
 (0)