Changeset 79a0317 for imaps-frontend/src/pages/MyMaps/MyMaps.jsx
- Timestamp:
- 01/21/25 03:08:24 (2 weeks ago)
- Branches:
- main
- Parents:
- 0c6b92a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
imaps-frontend/src/pages/MyMaps/MyMaps.jsx
r0c6b92a r79a0317 10 10 import {useAppContext} from "../../components/AppContext/AppContext.jsx"; 11 11 import config from "../../scripts/net/netconfig.js"; 12 import {element} from "prop-types";13 12 import Toast from "../../components/Toast/Toast.jsx"; 13 import plus_icon from "../../assets/plus_icon.png"; 14 14 15 15 const renderTile = ({data, isDragging}, openMapInfo) => ( … … 65 65 setToastMessage(message); 66 66 setToastType(type); 67 setTimeout(() => setToastMessage(null), 3000); // Automatically hide the toast after 3 seconds 68 }; 69 67 setTimeout(() => setToastMessage(null), 3000); 68 }; 70 69 71 70 const handleUpdate = async (updatedMap) => { 72 // Placeholder for map update logic 71 try { 72 let httpService = new HttpService(true); 73 const response = await httpService.post( 74 config.my_maps.edit_map_info, 75 updatedMap 76 ); 77 closeMapInfoModal() 78 window.location.reload(); 79 80 } catch (error) { 81 showToast("Map Name already taken", 0) 82 closeMapInfoModal() 83 } 73 84 }; 74 85 … … 83 94 setTiles((prevTiles) => prevTiles.filter((tile) => tile.mapName !== mapName)); 84 95 setAllTiles((prevTiles) => prevTiles.filter((tile) => tile.mapName !== mapName)); 85 showToast("Map deleted", 1) 96 showToast("Map deleted", 1); 86 97 }) 87 98 .catch((error) => { 88 99 const errorMessage = error.response?.data?.error || error.message || "Unknown error"; 89 // alert(`Error deleting the map: ${errorMessage}`); 90 showToast(`Error deleting the map: ${errorMessage}`, 0) 100 showToast(`Error deleting the map: ${errorMessage}`, 0); 91 101 }); 92 102 }; … … 97 107 98 108 httpService 99 .put(`${config.my_maps.add}?username=${ username}`, mapDetails)109 .put(`${config.my_maps.add}?username=${encodeURI(username)}`, mapDetails) 100 110 .then((respMap) => { 101 console.log("RESP NEW MAP: " + respMap)102 111 const mapTile = { 103 112 mapName: respMap.mapName, … … 108 117 modified_at: respMap.modifiedAt, 109 118 published_at: respMap.published_at, 110 gmaps_url: respMap.gmaps _url,119 gmaps_url: respMap.gmapsUrl, 111 120 image_url: card, 112 121 is_published: respMap.is_published, 122 mapType: respMap.mapType 113 123 }; 114 124 … … 116 126 setTiles((prevTiles) => [...prevTiles, mapTile]); 117 127 showToast("Map added successfully!"); 118 119 120 128 }) 121 129 .catch((error) => { 122 showToast("Map name already taken", 0) 130 showToast("Map name already taken", 0); 123 131 }); 124 132 }; … … 129 137 httpService.setAuthenticated(); 130 138 131 const respMaps = await httpService.get(`${config.my_maps.display}?username=${username}`); 139 const respMaps = await httpService.get( 140 `${config.my_maps.display}?username=${encodeURI(username)}` 141 ); 132 142 133 143 const mapTiles = respMaps.map((elem) => ({ … … 139 149 modified_at: elem.modifiedAt, 140 150 published_at: elem.published_at, 141 gmaps_url: elem.g MapsUrl,151 gmaps_url: elem.gmapsUrl, 142 152 image_url: card, 143 153 numFavourites: elem.numFavourites, 144 154 })); 145 146 155 147 156 setTiles(mapTiles); … … 154 163 setPublicMaps(tiles.filter((tile) => tile.status === "PUBLIC")); 155 164 setPrivateMaps(tiles.filter((tile) => tile.status === "PRIVATE")); 156 setPendingMaps(tiles.filter((tile) => tile.status === " INVALID"));165 setPendingMaps(tiles.filter((tile) => tile.status === "PENDING")); 157 166 }, [tiles]); 158 167 … … 164 173 return ( 165 174 <div className={styles.container}> 166 <Logo/> 167 <Profile/> 175 176 <div className={`${styles.logoWrapper}`}> 177 <Logo/> 178 </div> 168 179 <h1>Your Maps</h1> 169 170 <div className={styles.actionButtons}> 171 <button className={styles.createMapsButton} onClick={openCreateModal}> 172 Create Map 173 </button> 174 </div> 180 <div className={`${styles.profileWrapper}`}> 181 <Profile/> 182 </div> 183 175 184 176 185 <div className={styles.searchBar}> 177 <input type="text" placeholder="Search for maps..." onChange={handleSearch}/> 186 <input 187 type="text" 188 placeholder="Search for maps..." 189 onChange={handleSearch} 190 /> 178 191 </div> 179 192 … … 201 214 forceTileHeight={170} 202 215 /> 216 <button className={styles.plusButton} onClick={openCreateModal}> 217 <img src={plus_icon} alt="Add Map"/> 218 </button> 203 219 </div> 204 220 … … 222 238 onDelete={deleteMap} 223 239 onUpdate={handleUpdate} 224 onPublish={() => { 240 onPublish={(updatedMap = null) => { 241 242 const updatedTile = { 243 mapName: updatedMap.mapName, 244 cols: 1, 245 rows: 1, 246 status: updatedMap.mapStatus, 247 created_at: updatedMap.createdAt, 248 modified_at: updatedMap.modifiedAt, 249 published_at: updatedMap.published_at, 250 gmaps_url: updatedMap.gMapsUrl, 251 image_url: card, 252 numFavourites: updatedMap.numFavourites, 253 } 225 254 showToast(`Map ${selectedMap.mapName} published successfully!`); 226 255 setPrivateMaps((prevMaps) => prevMaps.filter(m => m.mapName !== selectedMap.mapName)) 227 setPendingMaps((prevMaps) => [...prevMaps, allTiles.find(m => m.mapName = selectedMap.mapName)])256 setPendingMaps((prevMaps) => [...prevMaps, updatedTile]) 228 257 closeMapInfoModal() 229 258 }} … … 236 265 /> 237 266 238 {toastMessage && <Toast message={toastMessage} type={toastType} onClose={() => setToastMessage(null)}/>} 267 {toastMessage && ( 268 <Toast 269 message={toastMessage} 270 type={toastType} 271 onClose={() => setToastMessage(null)} 272 /> 273 )} 239 274 </div> 240 275 );
Note:
See TracChangeset
for help on using the changeset viewer.