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

Commit 877339f

Browse files
authored
Merge pull request #38 from codeableorg/feature-club-gallery
Regular user can visualize many pictures from the club
2 parents 6c217a3 + 78f90ae commit 877339f

12 files changed

Lines changed: 109 additions & 11 deletions

File tree

api/app/assets/images/cancha1.jpg

134 KB
Loading

api/app/assets/images/cancha2.jpg

311 KB
Loading

api/app/controllers/clubs_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def set_club
3232
end
3333

3434
def club_params
35-
params.permit(:name, :address, :schedule, :image, :district, :latitude, :longitude)
35+
params.permit(:name, :address, :schedule, :district, :latitude, :longitude, image: [])
3636
end
3737

3838
end

api/app/models/club.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class Club < ApplicationRecord
2-
has_one_attached :image
2+
has_many_attached :image
33
has_many :favorites
44
has_many :sport_fields
55

api/app/serializers/club_serializer.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ class ClubSerializer < ActiveModel::Serializer
55

66
def image
77
# rails_blob_path(object.image, only_path: true) if object.image.attached?
8-
url_for(object.image) if self.object.image.attached?
8+
if self.object.image.attached?
9+
object.image.map do |img|
10+
url_for(img)
11+
end
12+
end
913
end
1014

1115
def favorited

api/db/seeds.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
puts "Init seed"
2+
3+
def get_image(file_name)
4+
{ io: File.open(File.join(Rails.root, "/app/assets/images/#{file_name}")), filename: file_name }
5+
end
6+
27
User.destroy_all
38
regular_user = User.create(name: 'Lian Nivin', email: 'liam@kampu.pe', role: "regular", password: '123456')
49
owner_user = User.create(name: 'Cristian Berly', email: 'berli@kampu.pe', role: "owner", password: '123456')
510

6-
clubs = Club.create([{name: "Club #1", address: 'Jr cayumba 440', district: "Lince", latitude: -12.1199378, longitude: -77.0373161,
11+
clubs = Club.create([{name: "Club #1", image: get_image("cancha1.jpg"), address: 'Jr cayumba 440', district: "Lince", latitude: -12.1199378, longitude: -77.0373161,
712
schedule: {
813
'monday-friday': {
914
start: '8',

client/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"leaflet": "^1.5.1",
1313
"react": "^16.8.6",
1414
"react-dom": "^16.8.6",
15+
"react-image-gallery": "^0.8.18",
1516
"react-leaflet": "^2.4.0",
1617
"react-redux": "^7.1.0",
1718
"react-scripts": "3.0.1",

client/src/components/gallery.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/** @jsx jsx */
2+
import React from "react";
3+
import { jsx } from "@emotion/core";
4+
import "react-image-gallery/styles/css/image-gallery.css";
5+
import ImageGallery from "react-image-gallery";
6+
7+
function Gallery({ club }) {
8+
const [images, setImages] = React.useState([]);
9+
10+
function getImagesReady(originalArray) {
11+
return originalArray.map(element => {
12+
return {
13+
original: element
14+
};
15+
});
16+
}
17+
console.log(club);
18+
19+
React.useEffect(() => {
20+
setImages(getImagesReady(club ? club.image : []));
21+
}, [club]);
22+
23+
return (
24+
<div
25+
css={{
26+
img: {
27+
objectFit: "cover",
28+
maxHeight: "45vw",
29+
"@media screen and (min-width: 530px)": {
30+
height: "300px"
31+
}
32+
}
33+
}}
34+
>
35+
<ImageGallery
36+
items={images}
37+
showBullets={true}
38+
showThumbnails={false}
39+
showFullscreenButton={false}
40+
showPlayButton={false}
41+
/>
42+
</div>
43+
);
44+
}
45+
46+
export default Gallery;

client/src/services/club.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ async function postClub(club) {
1313
console.log(errors);
1414
throw new Error(errors);
1515
}
16-
1716
return response.json();
1817
}
1918

client/src/views/clubs.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import { jsx } from "@emotion/core";
44
import { Title, Text, Card } from "../components/ui";
55
import { clubData } from "../services/club";
66
import SportfieldInfo from "../components/sportfield-info";
7+
import Gallery from "../components/gallery";
78

89
function Clubs({ id }) {
9-
const [club, setClub] = React.useState({ sport_fields: [] });
10+
const [club, setClub] = React.useState({ sport_fields: [], image: [] });
1011

1112
React.useEffect(() => {
1213
clubData(id).then(data => {
@@ -20,6 +21,7 @@ function Clubs({ id }) {
2021

2122
return (
2223
<div>
24+
<Gallery club={club} />
2325
<div
2426
css={{
2527
display: "flex",

0 commit comments

Comments
 (0)