1
|
|
|
import React from "react"; |
2
|
|
|
import { Link, NavLink } from "react-router-dom"; |
3
|
|
|
import { AiOutlineRight } from "react-icons/ai"; |
4
|
|
|
|
5
|
|
|
const ScooterList = ({ filterPhrase, scooterData }) => { |
6
|
|
|
const scooters = () => { |
7
|
|
|
return scooterData |
8
|
|
|
.sort((a, b) => { |
9
|
|
|
return a.owner.localeCompare(b.owner); |
10
|
|
|
}) |
11
|
|
|
.filter((item) => { |
12
|
|
|
if (filterPhrase === "") { |
13
|
|
|
return item; |
14
|
|
|
} else if ( |
15
|
|
|
item.owner.toLowerCase().includes(filterPhrase.toLowerCase()) |
16
|
|
|
) { |
17
|
|
|
return item; |
18
|
|
|
} else if ( |
19
|
|
|
item.status.toLowerCase().includes(filterPhrase.toLowerCase()) |
20
|
|
|
) { |
21
|
|
|
return item; |
22
|
|
|
} else if ( |
23
|
|
|
item.name.toLowerCase().includes(filterPhrase.toLowerCase()) |
24
|
|
|
) { |
25
|
|
|
return item; |
26
|
|
|
} |
27
|
|
|
return; |
28
|
|
|
}) |
29
|
|
|
.map((item, index) => { |
30
|
|
|
return ( |
31
|
|
|
<tr key={index} className="border-b text-base border-gray-400"> |
32
|
|
|
<td className="py-3 px-6">{item.name}</td> |
33
|
|
|
<td className="py-3 px-6">{item.owner}</td> |
34
|
|
|
<td className="py-3 px-6">{item.status}</td> |
35
|
|
|
<td className="py-3 px-6">{item.battery.toFixed(0)}%</td> |
36
|
|
|
<td className="py-3 px-6 w-2"> |
37
|
|
|
<Link to={"/scooters/select"} state={{ id: item._id }}> |
38
|
|
|
<span> |
39
|
|
|
<AiOutlineRight /> |
40
|
|
|
</span> |
41
|
|
|
</Link> |
42
|
|
|
</td> |
43
|
|
|
</tr> |
44
|
|
|
); |
45
|
|
|
}); |
46
|
|
|
}; |
47
|
|
|
|
48
|
|
|
if (!scooterData) { |
49
|
|
|
return <div>Loading</div>; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
return ( |
53
|
|
|
<> |
54
|
|
|
<table className="w-full text-lg text-left content-between"> |
55
|
|
|
<thead className=" bg-sidebarBlue text-gray-200"> |
56
|
|
|
<tr> |
57
|
|
|
<th className="font-normal px-6">Name</th> |
58
|
|
|
<th className="font-normal px-6">City</th> |
59
|
|
|
<th className="font-normal px-6"> Status</th> |
60
|
|
|
{/* <th className="font-normal ">Current Position</th> */} |
61
|
|
|
<th className="font-normal px-6">Battery</th> |
62
|
|
|
<th className="font-normal px-6">View</th> |
63
|
|
|
</tr> |
64
|
|
|
</thead> |
65
|
|
|
<tbody>{scooters()}</tbody> |
66
|
|
|
</table> |
67
|
|
|
</> |
68
|
|
|
); |
69
|
|
|
}; |
70
|
|
|
|
71
|
|
|
export default ScooterList; |
72
|
|
|
|