@@ -8,10 +8,8 @@ export default {
8
8
return {
9
9
store,
10
10
apartments: [],
11
- perPage: 4 ,
12
- currentPage: 0 ,
13
- hasAnimated: false ,
14
- transition: false
11
+ currentIndex: 0 ,
12
+ itemsPerPage: 4 , // Numero di card visibili per volta
15
13
};
16
14
},
17
15
@@ -21,6 +19,12 @@ export default {
21
19
22
20
mounted () {
23
21
this .getApartments ();
22
+ this .updateItemsPerPage ();
23
+ window .addEventListener (' resize' , this .updateItemsPerPage );
24
+ },
25
+
26
+ beforeDestroy () {
27
+ window .removeEventListener (' resize' , this .updateItemsPerPage );
24
28
},
25
29
26
30
watch: {
@@ -32,94 +36,104 @@ export default {
32
36
methods: {
33
37
getApartments () {
34
38
axios
35
- .get (' http://127.0.0.1:8000/api/apartments' )
39
+ .get (' http://127.0.0.1:8000/api/apartments' )
36
40
.then ((res ) => {
37
41
this .apartments = res .data .data .filter (
38
- apartment => apartment .is_visible && apartment .sponsorships && apartment .sponsorships .length > 0 && ! apartment .sponsorships .some (sponsorship => sponsorship .name === ' No sponsorship' )
42
+ (apartment ) =>
43
+ apartment .is_visible &&
44
+ apartment .sponsorships &&
45
+ apartment .sponsorships .length > 0 &&
46
+ ! apartment .sponsorships .some ((sponsorship ) => sponsorship .name === ' No sponsorship' )
39
47
);
40
48
41
49
this .apartments .sort ((a , b ) => {
42
50
const priority = { Gold: 1 , Silver: 2 , Bronze: 3 };
43
- const aSponsor = a .sponsorships [0 ]? .name || " Bronze" ;
44
- const bSponsor = b .sponsorships [0 ]? .name || " Bronze" ;
51
+ const aSponsor = a .sponsorships [0 ]? .name || ' Bronze' ;
52
+ const bSponsor = b .sponsorships [0 ]? .name || ' Bronze' ;
45
53
return priority[aSponsor] - priority[bSponsor];
46
54
});
47
55
48
56
store .suggestions = this .apartments .map ((apartment ) => apartment .address );
49
-
50
57
})
51
58
.catch ((error ) => console .error (' Errore:' , error));
52
59
},
53
60
54
- NextPage () {
55
- if (this .currentPage < Math .ceil (this .apartments .length / this .perPage ) - 1 ) {
56
- this .currentPage ++ ;
57
- }
58
- this .hasAnimated = true ;
59
- },
61
+ updateItemsPerPage () {
62
+ if (window .innerWidth >= 1024 ) {
63
+ this .itemsPerPage = 4 ;
64
+ } else if (window .innerWidth >= 768 ) {
65
+ this .itemsPerPage = 3 ;
66
+ } else {
67
+ this .itemsPerPage = 1 ;
68
+ }
69
+ },
70
+
71
+ NextCard () {
72
+ if (this .currentIndex < this .apartments .length - this .itemsPerPage ) {
73
+ this .currentIndex = this .currentIndex + this .itemsPerPage ;
74
+ }
75
+ },
60
76
61
- PrevPage () {
62
- if (this .currentPage > 0 ) {
63
- this .currentPage -- ;
77
+ PrevCard () {
78
+ if (this .currentIndex > 0 ) {
79
+ this .currentIndex = this . currentIndex - this . itemsPerPage ;
64
80
}
65
- }
81
+ },
66
82
},
67
83
68
84
computed: {
69
- paginatedApartments () {
70
- const start = this .currentPage * this .perPage ;
71
- const end = start + this .perPage ;
72
- return this .apartments .slice (start, end);
85
+ visibleApartments () {
86
+ return this .apartments .slice (this .currentIndex , this .currentIndex + this .itemsPerPage );
73
87
},
74
88
},
75
89
};
76
90
< / script>
77
91
78
92
< template>
79
- < div class = " max-w-7xl mx-auto h-[432px] relative" >
80
- <!-- Visualizzazione degli appartamenti -->
81
- < transition- group
82
- name= " fade"
83
- tag= " div"
84
- class = " grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-6"
85
- : key= " currentPage"
86
- >
87
- < Card
88
- v- for = " (property, index) in paginatedApartments"
89
- : key= " property.id"
90
- : id= " property.id"
91
- : user_id= " property.user_id"
92
- : title= " property.title"
93
- : rooms= " property.rooms"
94
- : beds= " property.beds"
95
- : bathrooms= " property.bathrooms"
96
- : square_meters= " property.square_meters"
97
- : address= " property.address"
98
- : latitude= " property.latitude"
99
- : longitude= " property.longitude"
100
- : image= " property.cover_image"
101
- : services= " property.services"
102
- : is_visible= " Boolean(property.is_visible)"
103
- class = " transform transition duration-500 ease-in-out hover:scale-105"
104
- / >
105
- < / transition- group>
106
-
107
- <!-- Bottone per la pagina precedente -->
93
+ < div class = " max-w-7xl mx-auto relative px-8 sm:px-6 lg:px-8 lg:scale-75 2xl:scale-90 md:w-full md:scale-75 xl:scale-90" >
94
+ <!-- Bottone per la slide precedente -->
108
95
< button
109
- @click= " PrevPage "
110
- class = " absolute top-1/2 -left-20 transform -translate-y-1/2 w-10 h-10 flex items-center justify-center bg-[#B49578] text-white rounded-full shadow-md hover:bg-[#EDEEF0] hover:text-[#B49578] hover:shadow-lg transition-all hover:-translate-x-1 duration-300 ease-in-out"
96
+ @click= " PrevCard "
97
+ class = " absolute top-1/2 -left-12 transform -translate-y-1/2 w-8 h-8 sm:w- 10 sm: h-10 flex items-center justify-center bg-[#B49578] text-white rounded-full shadow-md hover:bg-[#EDEEF0] hover:text-[#B49578] hover:shadow-lg transition-all hover:-translate-x-1 duration-300 ease-in-out z-10 "
111
98
>
112
- < span class = " text-xl font-bold" >
99
+ < span class = " text-sm sm:text- xl font-bold" >
113
100
< i class = " fa-solid fa-arrow-left" >< / i>
114
101
< / span>
115
102
< / button>
116
103
117
- <!-- Bottone per la pagina successiva -->
104
+ <!-- Visualizzazione degli appartamenti in modalità carosello -->
105
+ < div class = " overflow-visible" >
106
+ < div
107
+ class = " flex gap-6 transition-all ease-in-out duration-500"
108
+ : style= " { transform: `-translateX(${currentIndex * (100 / itemsPerPage)}%)` }"
109
+ >
110
+ < Card
111
+ v- for = " (property, index) in visibleApartments"
112
+ : key= " property.id"
113
+ : id= " property.id"
114
+ : user_id= " property.user_id"
115
+ : title= " property.title"
116
+ : rooms= " property.rooms"
117
+ : beds= " property.beds"
118
+ : bathrooms= " property.bathrooms"
119
+ : square_meters= " property.square_meters"
120
+ : address= " property.address"
121
+ : latitude= " property.latitude"
122
+ : longitude= " property.longitude"
123
+ : image= " property.cover_image"
124
+ : services= " property.services"
125
+ : is_visible= " Boolean(property.is_visible)"
126
+ class = " w-full md:w-full lg:w-1/3 sm:w-full transform transition duration-500 ease-in-out hover:scale-105"
127
+ / >
128
+ < / div>
129
+ < / div>
130
+
131
+ <!-- Bottone per la slide successiva -->
118
132
< button
119
- @click= " NextPage "
120
- class = " absolute top-1/2 -right-20 transform -translate-y-1/2 w-10 h-10 flex items-center justify-center bg-[#B49578] text-white rounded-full shadow-md hover:bg-[#EDEEF0] hover:text-[#B49578] hover:shadow-lg transition-all hover:translate-x-1 duration-300 ease-in-out"
133
+ @click= " NextCard "
134
+ class = " absolute top-1/2 -right-12 transform -translate-y-1/2 w-8 h-8 sm:w- 10 sm: h-10 flex items-center justify-center bg-[#B49578] text-white rounded-full shadow-md hover:bg-[#EDEEF0] hover:text-[#B49578] hover:shadow-lg transition-all hover:translate-x-1 duration-300 ease-in-out z-10 "
121
135
>
122
- < span class = " text-xl font-bold" >
136
+ < span class = " text-sm sm:text- xl font-bold" >
123
137
< i class = " fa-solid fa-arrow-right" >< / i>
124
138
< / span>
125
139
< / button>
@@ -133,6 +147,7 @@ export default {
133
147
< / div>
134
148
< / template>
135
149
150
+
136
151
< style scoped>
137
152
@keyframes fadeIn {
138
153
from {
@@ -157,4 +172,8 @@ export default {
157
172
opacity: 0 ;
158
173
transform: translateX (20px );
159
174
}
175
+
176
+ .scale - 25 {
177
+ scale: 0.25 ;
178
+ }
160
179
< / style>
0 commit comments