source: imaps-frontend/src/pages/Maps/Maps.jsx

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 2.0 KB
Line 
1import React, { useState } from "react";
2import styles from "./Maps.module.css";
3import "react-tiles-dnd/esm/index.css";
4import { TilesContainer } from "react-tiles-dnd";
5import { Link } from "react-router-dom";
6import card from "../../assets/card-map.png";
7
8const initialTiles = [
9 { text: "FINKI", cols: 1, rows: 1 },
10 { text: "TMF", cols: 1, rows: 1 },
11 { text: "HOSPITAL", cols: 1, rows: 1 },
12 { text: "POLICE", cols: 1, rows: 1 },
13 { text: "LIBRARY", cols: 1, rows: 1 },
14 { text: "PENTAGON", cols: 1, rows: 1 },
15 { text: "WHITE HOUSE", cols: 1, rows: 1 },
16 { text: "HOME", cols: 1, rows: 1 },
17 { text: "PRESPATEKS", cols: 1, rows: 1 },
18];
19
20const renderTile = ({ data, isDragging }) => (
21 <div style={{ padding: "1rem", width: "100%" }}>
22 <Link to="/Maps/FinkiMaps/View" className={styles.linkStyle}>
23 <div
24 className={`${styles.tile} ${isDragging ? styles.dragging : ""}`}
25 style={{ width: "100%", height: "100%" }}
26 >
27 <img src={card} className={styles.imgStyle} alt="Map Thumbnail" />
28 <div>
29 {data.text} {isDragging ? "DRAGGING" : null}
30 </div>
31 </div>
32 </Link>
33 </div>
34);
35
36const tileSize = (tile) => ({
37 colSpan: tile.cols,
38 rowSpan: tile.rows,
39});
40
41export default function Maps() {
42 const [searchTerm, setSearchTerm] = useState("");
43 const [tiles, setTiles] = useState(initialTiles);
44
45 const handleSearchChange = (e) => {
46 const value = e.target.value.toLowerCase();
47 setSearchTerm(value);
48
49 setTiles(initialTiles.filter((tile) => tile.text.toLowerCase().includes(value)));
50 };
51
52 return (
53 <div className={styles.container}>
54 <h1>Explore Maps</h1>
55
56 <div className={styles.searchBar}>
57 <input
58 type="text"
59 placeholder="Search for maps..."
60 value={searchTerm}
61 onChange={handleSearchChange}
62 />
63 </div>
64
65 <TilesContainer
66 data={tiles}
67 renderTile={renderTile}
68 tileSize={tileSize}
69 forceTileWidth={150}
70 forceTileHeight={170}
71 />
72 </div>
73 );
74}
Note: See TracBrowser for help on using the repository browser.