1 | import styles from "./Draw.module.css";
|
---|
2 | import plus_icon from "../../assets/plus_icon.png";
|
---|
3 |
|
---|
4 | export const FloorSelector = ({floorConfig}) => {
|
---|
5 |
|
---|
6 | const {floors,searchParams,addFloorHandler,setSearchParams,deleteFloorHandler} = floorConfig;
|
---|
7 |
|
---|
8 | return (
|
---|
9 | <div className={styles.floorSection}>
|
---|
10 | <div className={styles.floorList}>
|
---|
11 | <label className={styles.floorLabel}>Available Floors:</label>
|
---|
12 | <div className={styles.floorItems}>
|
---|
13 | {/* Add new positive floor above */}
|
---|
14 | <button
|
---|
15 | className={styles.addFloorButton}
|
---|
16 | onClick={() => {
|
---|
17 | const newFloor = Math.max(...floors.map((f) => f.num)) + 1;
|
---|
18 | addFloorHandler(newFloor);
|
---|
19 | }}
|
---|
20 | >
|
---|
21 | <img src={plus_icon} alt="Add Positive Floor" className={styles.icon}/>
|
---|
22 | </button>
|
---|
23 |
|
---|
24 | {/* Display editable floors */}
|
---|
25 | {floors
|
---|
26 | .sort((a, b) => b.num - a.num)
|
---|
27 | .map((floor) => (
|
---|
28 | <div key={floor.num} className={styles.floorItemWrapper}>
|
---|
29 | <button
|
---|
30 | onClick={() => setSearchParams({floor: floor.num}, {replace: true})}
|
---|
31 | className={`${styles.floorItem} ${
|
---|
32 | searchParams.get("floor") == floor.num ? styles.activeFloor : ""
|
---|
33 | }`}
|
---|
34 | >
|
---|
35 | Floor {floor.num}
|
---|
36 | </button>
|
---|
37 | <button
|
---|
38 | className={styles.deleteFloorButton}
|
---|
39 | onClick={() => deleteFloorHandler(floor.num)}
|
---|
40 | >
|
---|
41 | 🗑️
|
---|
42 | </button>
|
---|
43 | </div>
|
---|
44 | ))}
|
---|
45 |
|
---|
46 | {/* Add new negative floor below */}
|
---|
47 | <button
|
---|
48 | className={styles.addFloorButton}
|
---|
49 | onClick={() => {
|
---|
50 | const newFloor = Math.min(...floors.map((f) => f.num)) - 1;
|
---|
51 | addFloorHandler(newFloor);
|
---|
52 | }}
|
---|
53 | >
|
---|
54 | <img src={plus_icon} alt="Add Negative Floor" className={styles.icon}/>
|
---|
55 | </button>
|
---|
56 | </div>
|
---|
57 | </div>
|
---|
58 | </div>
|
---|
59 | )
|
---|
60 | } |
---|