Changeset 79a0317 for imaps-frontend/src/pages/BrowseMaps/BrowseMaps.jsx
Legend:
- Unmodified
- Added
- Removed
-
imaps-frontend/src/pages/BrowseMaps/BrowseMaps.jsx
r0c6b92a r79a0317 1 1 import styles from "./Maps.module.css"; 2 2 import "react-tiles-dnd/esm/index.css"; 3 import { TilesContainer} from "react-tiles-dnd";4 import { Link} from "react-router-dom";3 import {TilesContainer} from "react-tiles-dnd"; 4 import {Link} from "react-router-dom"; 5 5 import card from "../../assets/card-map.png"; 6 6 import star_icon from "../../assets/star_icon.png"; // Unfilled star icon 7 7 import star_filled_icon from "../../assets/star_filled_icon.png"; // Filled star icon 8 import { useEffect, useState} from "react";8 import {useEffect, useState} from "react"; 9 9 import HttpService from "../../scripts/net/HttpService.js"; 10 10 import Logo from "../../components/Logo/Logo.jsx"; 11 11 import Profile from "../../components/Profile/Profile.jsx"; 12 12 import config from "../../scripts/net/netconfig.js"; 13 import { useAppContext } from "../../components/AppContext/AppContext.jsx"; 13 import {useAppContext} from "../../components/AppContext/AppContext.jsx"; 14 import FilterMaps from "../../components/FilterMaps/FilterMaps.jsx"; 14 15 15 16 let loadedTiles = []; 16 17 17 const renderTile = ({ data, isDragging, toggleFavorite}) => (18 <div style={{ padding: "1rem", width: "100%", position: "relative"}}>19 <Link to={`/Maps/ ${data.text}/View`} className={styles.linkStyle}>18 const renderTile = ({data, isDragging, toggleFavorite}) => ( 19 <div style={{padding: "1rem", width: "100%", position: "relative"}}> 20 <Link to={`/Maps/View/${data.text}`} className={styles.linkStyle}> 20 21 <div 21 22 className={`${styles.tile} ${isDragging ? styles.dragging : ""}`} 22 style={{ width: "100%", height: "100%"}}23 style={{width: "100%", height: "100%"}} 23 24 > 24 <img src={card} className={styles.imgStyle} alt="Map Thumbnail" 25 <div style={{ fontFamily: "exo"}}>25 <img src={card} className={styles.imgStyle} alt="Map Thumbnail"/> 26 <div style={{fontFamily: "exo"}}> 26 27 {data.text} {isDragging ? "DRAGGING" : null} 27 28 </div> … … 32 33 src={data.isFavorite ? star_filled_icon : star_icon} 33 34 alt="Favorite Icon" 34 style={{ width: "20px", height: "20px"}}35 style={{width: "20px", height: "20px"}} 35 36 /> 36 37 </div> … … 46 47 const [searchTerm, setSearchTerm] = useState(""); 47 48 const [tiles, setTiles] = useState([]); 48 const { username, isAuthenticated } = useAppContext(); 49 const {username, isAuthenticated} = useAppContext(); 50 const [filter, setFilter] = useState("all") 51 const [mapFilters, setMapFilters] = useState([]) 49 52 50 53 useEffect(() => { … … 52 55 const httpService = new HttpService(); 53 56 let mapTiles = []; 54 57 let mapTypes = ['Hospital', 'Faculty', 'House', 'Other']; 55 58 if (isAuthenticated) { 56 59 // :D … … 63 66 rows: 1, 64 67 isFavorite: true, 68 type: elem.mapType, 65 69 })); 66 70 71 console.log("TUKA") 67 72 // Load all maps 68 73 const allResp = await httpService.get(config.view_maps.display); 69 74 console.log("RESPONSE MAPS PUBLIC", allResp); 75 76 // mapTypes = allResp.filter(elem => elem.mapType != null && elem.mapType !== "").map(elem => elem.mapType); 77 70 78 71 79 const nonFavMapTiles = allResp … … 76 84 rows: 1, 77 85 isFavorite: false, 86 type: elem.mapType, 78 87 })); 88 79 89 80 90 mapTiles = [...favMapTiles, ...nonFavMapTiles]; … … 82 92 const allResp = await httpService.get(config.view_maps.display); 83 93 console.log("RESPONSE MAPS PUBLIC", allResp); 94 // mapTypes = allResp.filter(elem => elem.mapType != null && elem.mapType !== "").map(elem => elem.mapType); 84 95 85 96 mapTiles = allResp.map((elem) => ({ … … 88 99 rows: 1, 89 100 isFavorite: false, 101 type: elem.mapType, 90 102 })); 91 103 } 104 105 console.log("TYPES:", mapTypes); 106 setMapFilters(mapTypes); 92 107 93 108 loadedTiles = [...mapTiles]; … … 114 129 115 130 const updatedTiles = tiles.map((tile) => 116 tile.text === tileName ? { ...tile, isFavorite: !tile.isFavorite} : tile131 tile.text === tileName ? {...tile, isFavorite: !tile.isFavorite} : tile 117 132 ); 118 133 … … 140 155 }; 141 156 157 const onFilter = (selectedFilter) => { 158 setFilter(selectedFilter); 159 160 if (selectedFilter === "all") { 161 // Show all tiles 162 setTiles(loadedTiles); 163 } else { 164 // Filter tiles by selected type 165 const filteredTiles = loadedTiles.filter((tile) => tile.type === selectedFilter); 166 setTiles(filteredTiles); 167 } 168 }; 169 170 142 171 return ( 143 172 <div className={styles.container}> … … 152 181 onChange={handleSearchChange} 153 182 /> 183 154 184 </div> 155 185 <div className={styles.filterBar}> 186 <FilterMaps mapTypes={mapFilters} setFilter={onFilter}></FilterMaps> 187 </div> 188 {filter !== "all" && tiles.length === 0 && <p>No maps of type {filter} found</p>} 156 189 <TilesContainer 157 190 data={tiles} 158 renderTile={(props) => renderTile({ ...props, toggleFavorite})}191 renderTile={(props) => renderTile({...props, toggleFavorite})} 159 192 tileSize={tileSize} 160 forceTileWidth={1 50}161 forceTileHeight={ 170}193 forceTileWidth={170} 194 forceTileHeight={200} 162 195 /> 163 196 </div>
Note:
See TracChangeset
for help on using the changeset viewer.