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

Commit ee4da66

Browse files
committed
Change image to accept multiple images
1 parent 4fce7d6 commit ee4da66

8 files changed

Lines changed: 32 additions & 15 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: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ 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+
p "CRIS", url_for(img)
11+
url_for(img)
12+
end
13+
end
914
end
1015

1116
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/src/components/gallery.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,23 @@ import React from "react";
33
import { jsx } from "@emotion/core";
44
import "react-image-gallery/styles/css/image-gallery.css";
55
import ImageGallery from "react-image-gallery";
6+
import { useClubs } from "../selectors/selectors";
67

7-
function Gallery() {
8-
const images = [
9-
{
10-
original:
11-
"https://pvpanthers.com/common/controls/image_handler.aspx?thumb_id=0&image_path=/images/2017/2/7/Soccer_Field_1.jpeg"
12-
},
13-
{
14-
original:
15-
"https://apelotear.com/media/canchas/8ECE298C-60A2-4E92-8A3A-C4C82EF948AF.jpeg"
16-
}
17-
];
8+
function Gallery({ id }) {
9+
const clubs = useClubs();
10+
const [images, setImages] = React.useState([]);
11+
12+
function getImagesReady(originalArray) {
13+
return originalArray.map(element => {
14+
return {
15+
original: element
16+
};
17+
});
18+
}
19+
20+
React.useEffect(() => {
21+
setImages(getImagesReady(clubs[0].image));
22+
}, []);
1823

1924
return (
2025
<div

client/src/views/create-club.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ function CreateClub() {
3131

3232
function handleChange(e) {
3333
if (e.target.name === "image") {
34+
console.log([...e.target.files]);
3435
setFields({ ...fields, image: e.target.files[0] });
3536
} else {
3637
setFields({ ...fields, [e.target.name]: e.target.value });
@@ -129,6 +130,7 @@ function CreateClub() {
129130
id="image"
130131
name="image"
131132
type="file"
133+
multiple
132134
onChange={handleChange}
133135
/>
134136
</div>

0 commit comments

Comments
 (0)