Ignore:
Timestamp:
01/21/25 03:08:24 (2 weeks ago)
Author:
stefan toskovski <stefantoska84@…>
Branches:
main
Parents:
0c6b92a
Message:

F4 Finalna Verzija

File:
1 edited

Legend:

Unmodified
Added
Removed
  • imaps-frontend/src/pages/MyMaps/MyMaps.jsx

    r0c6b92a r79a0317  
    1010import {useAppContext} from "../../components/AppContext/AppContext.jsx";
    1111import config from "../../scripts/net/netconfig.js";
    12 import {element} from "prop-types";
    1312import Toast from "../../components/Toast/Toast.jsx";
     13import plus_icon from "../../assets/plus_icon.png";
    1414
    1515const renderTile = ({data, isDragging}, openMapInfo) => (
     
    6565        setToastMessage(message);
    6666        setToastType(type);
    67         setTimeout(() => setToastMessage(null), 3000); // Automatically hide the toast after 3 seconds
    68     };
    69 
     67        setTimeout(() => setToastMessage(null), 3000);
     68    };
    7069
    7170    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        }
    7384    };
    7485
     
    8394                setTiles((prevTiles) => prevTiles.filter((tile) => tile.mapName !== mapName));
    8495                setAllTiles((prevTiles) => prevTiles.filter((tile) => tile.mapName !== mapName));
    85                 showToast("Map deleted", 1)
     96                showToast("Map deleted", 1);
    8697            })
    8798            .catch((error) => {
    8899                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);
    91101            });
    92102    };
     
    97107
    98108        httpService
    99             .put(`${config.my_maps.add}?username=${username}`, mapDetails)
     109            .put(`${config.my_maps.add}?username=${encodeURI(username)}`, mapDetails)
    100110            .then((respMap) => {
    101                 console.log("RESP NEW MAP: " + respMap)
    102111                const mapTile = {
    103112                    mapName: respMap.mapName,
     
    108117                    modified_at: respMap.modifiedAt,
    109118                    published_at: respMap.published_at,
    110                     gmaps_url: respMap.gmaps_url,
     119                    gmaps_url: respMap.gmapsUrl,
    111120                    image_url: card,
    112121                    is_published: respMap.is_published,
     122                    mapType: respMap.mapType
    113123                };
    114124
     
    116126                setTiles((prevTiles) => [...prevTiles, mapTile]);
    117127                showToast("Map added successfully!");
    118 
    119 
    120128            })
    121129            .catch((error) => {
    122                 showToast("Map name already taken", 0)
     130                showToast("Map name already taken", 0);
    123131            });
    124132    };
     
    129137            httpService.setAuthenticated();
    130138
    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            );
    132142
    133143            const mapTiles = respMaps.map((elem) => ({
     
    139149                modified_at: elem.modifiedAt,
    140150                published_at: elem.published_at,
    141                 gmaps_url: elem.gMapsUrl,
     151                gmaps_url: elem.gmapsUrl,
    142152                image_url: card,
    143153                numFavourites: elem.numFavourites,
    144154            }));
    145 
    146155
    147156            setTiles(mapTiles);
     
    154163        setPublicMaps(tiles.filter((tile) => tile.status === "PUBLIC"));
    155164        setPrivateMaps(tiles.filter((tile) => tile.status === "PRIVATE"));
    156         setPendingMaps(tiles.filter((tile) => tile.status === "INVALID"));
     165        setPendingMaps(tiles.filter((tile) => tile.status === "PENDING"));
    157166    }, [tiles]);
    158167
     
    164173    return (
    165174        <div className={styles.container}>
    166             <Logo/>
    167             <Profile/>
     175
     176            <div className={`${styles.logoWrapper}`}>
     177                <Logo/>
     178            </div>
    168179            <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
    175184
    176185            <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                />
    178191            </div>
    179192
     
    201214                        forceTileHeight={170}
    202215                    />
     216                    <button className={styles.plusButton} onClick={openCreateModal}>
     217                        <img src={plus_icon} alt="Add Map"/>
     218                    </button>
    203219                </div>
    204220
     
    222238                onDelete={deleteMap}
    223239                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                    }
    225254                    showToast(`Map ${selectedMap.mapName} published successfully!`);
    226255                    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])
    228257                    closeMapInfoModal()
    229258                }}
     
    236265            />
    237266
    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            )}
    239274        </div>
    240275    );
Note: See TracChangeset for help on using the changeset viewer.