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

Commit 34d5c18

Browse files
author
Lian Nivin
authored
Merge pull request #25 from codeableorg/feature-clubs-by-location
Feature clubs by location
2 parents 5e3c10e + 3e6b365 commit 34d5c18

14 files changed

Lines changed: 232 additions & 22 deletions

File tree

api/app/controllers/clubs_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def set_club
2828
end
2929

3030
def club_params
31-
params.permit(:name, :address, :schedule, :image)
31+
params.permit(:name, :address, :schedule, :image, :district, :latitude, :longitude)
3232
end
3333

3434
end

api/app/serializers/club_serializer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class ClubSerializer < ActiveModel::Serializer
22
include Rails.application.routes.url_helpers
33

4-
attributes :id, :name, :address, :image, :schedule, :favorited, :favorited_count
4+
attributes :id, :name, :address, :image, :schedule, :favorited, :favorited_count, :district, :latitude, :longitude
55

66
def image
77
# rails_blob_path(object.image, only_path: true) if object.image.attached?
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class AddDistrictToClubs < ActiveRecord::Migration[5.2]
2+
def change
3+
add_column :clubs, :district, :string
4+
add_column :clubs, :latitude, :string
5+
add_column :clubs, :longitude, :string
6+
end
7+
end

api/db/schema.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema.define(version: 2019_07_15_153026) do
13+
ActiveRecord::Schema.define(version: 2019_07_15_215722) do
1414

1515
# These are extensions that must be enabled in order to support this database
1616
enable_extension "plpgsql"
@@ -42,6 +42,9 @@
4242
t.json "schedule"
4343
t.datetime "created_at", null: false
4444
t.datetime "updated_at", null: false
45+
t.string "district"
46+
t.string "latitude"
47+
t.string "longitude"
4548
end
4649

4750
create_table "favorites", force: :cascade do |t|

api/db/seeds.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
regular_user = User.create(name: 'Lian Nivin', email: 'liam@kampu.pe', role: "regular", password: '123456')
44
owner_user = User.create(name: 'Cristian Berly', email: 'berli@kampu.pe', role: "owner", password: '123456')
55

6-
Club.create([{name: "Club #1", address: 'Jr cayumba 440',
6+
clubs = Club.create([{name: "Club #1", address: 'Jr cayumba 440', district: "Lince", latitude: -12.1199378, longitude: -77.0373161,
77
schedule: {
88
'monday-friday': {
99
start: '8',
@@ -17,7 +17,7 @@
1717
start: '8',
1818
end: '22'
1919
},
20-
}}, {name: "Club #2", address: 'Jr cayumba 440',
20+
}}, {name: "Club #2", address: 'Av. Jorge Chavez 184', district: "Miraflores", latitude: -13.1199378, longitude: -77.0353161,
2121
schedule: {
2222
'monday-friday': {
2323
start: '8',
@@ -31,7 +31,7 @@
3131
start: '8',
3232
end: '22'
3333
},
34-
}}, {name: "Club #3", address: 'Jr cayumba 440',
34+
}}, {name: "Club #3", address: 'Jr General Artigas 440', district: "Pueblo Libre", latitude: -14.1199378, longitude: -77.0373261,
3535
schedule: {
3636
'monday-friday': {
3737
start: '8',
@@ -53,7 +53,7 @@
5353

5454
Club.create(
5555
name: 'Club golden',
56-
address: 'Jr cayumba 440',
56+
address: 'Jr Something 123', district: "Cercado de Lima", latitude: -12.0641388, longitude: -77.0358862,
5757
schedule: {
5858
'monday-friday': {
5959
start: '8',

client/.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
REACT_APP_VERSION=$npm_package_version
22
REACT_APP_API_URL=http://localhost:4000/api
33
REACT_APP_API_URL_PRODUCTION=
4+
REACT_APP_OPEN_CAGE_DATA_KEY=

client/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"@emotion/core": "^10.0.10",
77
"@reach/router": "^1.2.1",
88
"@testing-library/react": "^8.0.1",
9+
"geolib": "^3.0.4",
910
"jest-emotion": "^10.0.11",
1011
"jest-fetch-mock": "^2.1.2",
1112
"leaflet": "^1.5.1",

client/src/components/club-card.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/** @jsx jsx */
2+
import React from "react";
3+
import { jsx } from "@emotion/core";
4+
import { Card, Title } from "../components/ui";
5+
6+
function ClubCard({ club }) {
7+
const styleCard = {
8+
maxWidth: "100%",
9+
marginBottom: "1.5em"
10+
};
11+
12+
return (
13+
<Card css={styleCard}>
14+
<Title>{club.name}</Title>
15+
<p>{JSON.stringify(club)}</p>
16+
<p>{club.position}</p>
17+
<p>{club.distance !== 0 ? `${club.distance / 1000.0}km` : null}</p>
18+
</Card>
19+
);
20+
}
21+
22+
export default ClubCard;

client/src/components/club.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import React from "react";
33
import { jsx } from "@emotion/core";
44
import { Card } from "./ui";
5-
import { Heart } from "./icons";
5+
import { Heart, MapPin } from "./icons";
66
import { favorite, unfavorite } from "../services/club";
77
import { useSetFavorite, useSetUnfavorite } from "../actions/action-hooks";
88

@@ -16,6 +16,12 @@ function Club({ club }) {
1616
color: "tomato"
1717
};
1818

19+
const styleMapPin = {
20+
cursor: "pointer",
21+
color: "#414141",
22+
marginLeft: "auto"
23+
};
24+
1925
async function handleClick() {
2026
if (club.favorited) {
2127
setFavorite(await unfavorite(club.id));
@@ -69,6 +75,10 @@ function Club({ club }) {
6975
>
7076
{club.favorited_count > 0 && club.favorited_count}
7177
</span>
78+
<MapPin width="18px" height="18px" css={styleMapPin} />
79+
<span>
80+
{club.distance !== 0 ? `${club.distance / 1000.0}km` : null}
81+
</span>
7282
</div>
7383
</div>
7484
</Card>

client/src/components/icons.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,24 @@ function Heart(props) {
1919
);
2020
}
2121

22-
export { Heart };
22+
function MapPin(props) {
23+
return (
24+
<svg
25+
xmlns="http://www.w3.org/2000/svg"
26+
width="24"
27+
height="24"
28+
viewBox="0 0 24 24"
29+
fill="none"
30+
stroke="currentColor"
31+
strokeWidth="2"
32+
strokeLinecap="round"
33+
strokeLinejoin="round"
34+
{...props}
35+
>
36+
<path d="M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0 1 18 0z" />
37+
<circle cx="12" cy="10" r="3" />
38+
</svg>
39+
);
40+
}
41+
42+
export { Heart, MapPin };

0 commit comments

Comments
 (0)