-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbike.jsx
183 lines (172 loc) · 6.24 KB
/
bike.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import React, { useState } from "react";
import { FaBatteryHalf, FaClock, FaMapMarkedAlt, FaListUl } from "react-icons/fa";
import { motion, AnimatePresence } from "framer-motion";
import "react-map-gl";
import Map from "react-map-gl";
import "mapbox-gl/dist/mapbox-gl.css";
const BikeRentalInterface = () => {
const [isMapView, setIsMapView] = useState(false);
const [currentSlide, setCurrentSlide] = useState(0);
const [error, setError] = useState(null);
const vehicles = [
{
id: 1,
name: "Electric Bike Pro",
type: "Bike",
image: "images.unsplash.com/photo-1531608139434-1912ae0713cd",
battery: 85,
cost: "$12/hour",
available: true,
location: { lat: 40.7128, lng: -74.006 }
},
{
id: 2,
name: "City Scooter X",
type: "Scooter",
image: "images.unsplash.com/photo-1604868189265-219ba7bf7ea3",
battery: 92,
cost: "$10/hour",
available: true,
location: { lat: 40.7148, lng: -74.008 }
},
{
id: 3,
name: "Mountain Bike Elite",
type: "Bike",
image: "images.unsplash.com/photo-1532298229144-0ec0c57515c7",
battery: 78,
cost: "$15/hour",
available: false,
location: { lat: 40.7138, lng: -74.004 }
}
];
const nextSlide = () => {
setCurrentSlide((prev) => (prev + 1) % vehicles.length);
};
const prevSlide = () => {
setCurrentSlide((prev) => (prev - 1 + vehicles.length) % vehicles.length);
};
const ListView = () => (
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 p-4">
{vehicles.map((vehicle) => (
<motion.div
key={vehicle.id}
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
className="bg-white rounded-lg shadow-md p-4 hover:shadow-lg transition-shadow"
>
<img
src={`https://${vehicle.image}`}
alt={vehicle.name}
className="w-full h-48 object-cover rounded-lg mb-4"
onError={(e) => {
e.target.src = "https://images.unsplash.com/photo-1581235720704-06d3acfcb36f";
setError("Some images failed to load");
}}
/>
<h3 className="text-xl font-semibold mb-2">{vehicle.name}</h3>
<div className="flex items-center justify-between mb-2">
<span className="flex items-center">
<FaBatteryHalf className="text-green-500 mr-2" />
{vehicle.battery}%
</span>
<span className="text-gray-600">{vehicle.cost}</span>
</div>
<button
className={`w-full py-2 px-4 rounded-lg ${vehicle.available
? "bg-green-500 hover:bg-green-600"
: "bg-gray-400 cursor-not-allowed"
} text-white transition-colors`}
disabled={!vehicle.available}
>
{vehicle.available ? "Rent Now" : "Unavailable"}
</button>
</motion.div>
))}
</div>
);
const MapView = () => (
<div className="h-[600px] w-full rounded-lg overflow-hidden">
<Map
initialViewState={{
longitude: -74.006,
latitude: 40.7128,
zoom: 13
}}
style={{ width: "100%", height: "100%" }}
mapStyle="mapbox://styles/mapbox/streets-v11"
mapboxAccessToken="YOUR_MAPBOX_TOKEN"
>
{/* Map markers would go here */}
</Map>
</div>
);
return (
<div className="max-w-7xl mx-auto px-4 py-8">
{error && (
<div className="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative mb-4" role="alert">
<span className="block sm:inline">{error}</span>
</div>
)}
<div className="flex items-center justify-between mb-8">
<h1 className="text-3xl font-bold text-gray-800">Rent a Bike or Scooter</h1>
<button
onClick={() => setIsMapView(!isMapView)}
className="flex items-center space-x-2 bg-white px-4 py-2 rounded-lg shadow-md hover:shadow-lg transition-shadow"
aria-label={isMapView ? "Switch to list view" : "Switch to map view"}
>
{isMapView ? <FaListUl className="text-gray-600" /> : <FaMapMarkedAlt className="text-gray-600" />}
<span>{isMapView ? "List View" : "Map View"}</span>
</button>
</div>
<div className="relative mb-8">
<div className="overflow-hidden">
<motion.div
className="flex transition-transform duration-300 ease-in-out"
style={{ transform: `translateX(-${currentSlide * 100}%)` }}
>
{vehicles.map((vehicle) => (
<div key={vehicle.id} className="w-full flex-shrink-0">
<img
src={`https://${vehicle.image}`}
alt={vehicle.name}
className="w-full h-64 object-cover rounded-lg"
onError={(e) => {
e.target.src = "https://images.unsplash.com/photo-1581235720704-06d3acfcb36f";
setError("Some images failed to load");
}}
/>
</div>
))}
</motion.div>
</div>
<button
onClick={prevSlide}
className="absolute left-0 top-1/2 transform -translate-y-1/2 bg-white p-2 rounded-full shadow-md hover:shadow-lg transition-shadow"
aria-label="Previous slide"
>
←
</button>
<button
onClick={nextSlide}
className="absolute right-0 top-1/2 transform -translate-y-1/2 bg-white p-2 rounded-full shadow-md hover:shadow-lg transition-shadow"
aria-label="Next slide"
>
→
</button>
</div>
<AnimatePresence mode="wait">
<motion.div
key={isMapView ? "map" : "list"}
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, y: -20 }}
transition={{ duration: 0.3 }}
>
{isMapView ? <MapView /> : <ListView />}
</motion.div>
</AnimatePresence>
</div>
);
};
export default BikeRentalInterface;