Skip to content

Commit

Permalink
fix: maps to leafllet everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Patek committed Feb 7, 2025
1 parent 10c8c4f commit b209260
Show file tree
Hide file tree
Showing 19 changed files with 5,297 additions and 228 deletions.
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
registry=https://registry.npmjs.org/
76 changes: 0 additions & 76 deletions app/(with-navbar)/(authenticated)/profil/DynamicMap.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions app/(with-navbar)/(authenticated)/profil/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import DynamicMap from "./DynamicMap";
import ProfileBox from "./ProfileBox";
import TabsAndContent from "./TabsAndContent";
import { getAllUserFavouritesIds } from "@/actions/favourites/favourites.action";
import { getAllUserVisits } from "@/actions/visits/visits.action";
import { getAllUserRatings } from "@/actions/ratings/ratings.action";
import { getTowersByIDs } from "@/actions/towers/towers.action";
import ProfileMapFixed from "@/components/shared/map/ProfileMapFixed";

async function ProfilePage() {
const promises = [getAllUserFavouritesIds(), getAllUserVisits(), getAllUserRatings()];
Expand All @@ -17,7 +17,7 @@ async function ProfilePage() {
<div className="flex max-w-[calc(min(99vw,80rem))] w-full items-center sm:items-start justify-center flex-col sm:flex-row sm:h-[687px] gap-3">
<ProfileBox score={visits.length} changes={0} favs={favouritesIds.length} ratings={ratings.length} visits={visits.length} />
<div className="flex h-[170px] w-[97vw] flex-grow sm:h-full">
<DynamicMap lat={49.8237572} long={15.6086383} towers={towers} visits={visits.map((v) => v.tower_id)} favs={favouritesIds} />
<ProfileMapFixed towers={towers} visits={visits} favourites={favouritesIds} />
</div>
</div>
<TabsAndContent visits={visits} favs={favouritesIds} towers={towers} ratings={ratings} />
Expand Down
4 changes: 2 additions & 2 deletions app/(with-navbar)/(with-footer)/[type]/[nameID]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Metadata } from "next";
import HistoryText from "@/components/tower/tiles/HistoryText";
import Map from "@/components/tower/tiles/Map";
import Parameters from "@/components/tower/tiles/parameters/Parameters";
import OpeningHours from "@/components/tower/tiles/openingHours/OpeningHoursTile";
import Admission from "@/components/tower/tiles/Admission";
Expand All @@ -15,6 +14,7 @@ import RatingFormProvider from "@/components/tower/rating/RatingProvider";
import Carousel from "@/components/tower/top/Carousel";
import { notFound } from "next/navigation";
import ChangesHistory from "@/components/tower/tiles/ChangesHistory";
import TowerMapFixed from "@/components/shared/map/TowerMapFixed";

async function TowerPage({ params }: { params }) {
const { nameID } = await params;
Expand Down Expand Up @@ -45,7 +45,7 @@ async function TowerPage({ params }: { params }) {
</div>
{tower.history && <HistoryText text={tower.history} />}
<RatingFormProvider tower={tower} />
<Map lat={tower.gps.latitude} long={tower.gps.longitude} name={tower.name} />
<TowerMapFixed tower={tower} />
<ChangesHistory tower={tower} />
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/(with-navbar)/mapa/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Metadata } from "next";
import { getAllUserFavouritesIds } from "@/actions/favourites/favourites.action";
import { getAllTowers } from "@/actions/towers/towers.action";
import { getAllUserVisits } from "@/actions/visits/visits.action";
import MainMap from "@/components/shared/map/Map";
import MainMapFixed from "@/components/shared/map/MainMapFixed";

export const metadata: Metadata = {
title: "Mapa",
Expand All @@ -13,7 +13,7 @@ async function MapPage() {

return (
<div className="flex justify-center items-stretch flex-grow h-[calc(100dvh-66px)] md:h-[calc(100dvh-69px)]">
<MainMap towers={towers} visits={visits} favourites={favouriteTowersIds} />
<MainMapFixed towers={towers} visits={visits} favourites={favouriteTowersIds} />
</div>
);
}
Expand Down
7 changes: 7 additions & 0 deletions components/shared/map/MainMapFixed.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"use client";

import dynamic from "next/dynamic";

const MainMapFixed = dynamic(() => import("@/components/shared/map/base/MainMap"), { ssr: false });

export default MainMapFixed;
7 changes: 0 additions & 7 deletions components/shared/map/Map.tsx

This file was deleted.

7 changes: 7 additions & 0 deletions components/shared/map/ProfileMapFixed.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"use client";

import dynamic from "next/dynamic";

const ProfileMapFixed = dynamic(() => import("@/components/shared/map/base/ProfileMap"), { ssr: false });

export default ProfileMapFixed;
7 changes: 7 additions & 0 deletions components/shared/map/TowerMapFixed.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"use client";

import dynamic from "next/dynamic";

const TowerMapFixed = dynamic(() => import("@/components/shared/map/base/TowerMap"), { ssr: false });

export default TowerMapFixed;
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,19 @@

import { Tower } from "@/types/Tower";
import { Visit } from "@/types/Visit";
import { MapContainer, TileLayer } from "react-leaflet";
import "leaflet/dist/leaflet.css";
import "leaflet/dist/images/marker-shadow.png";
import TowerMarker from "@/components/shared/map/TowerMarker";
import TowerMarker from "@/components/shared/map/base/TowerMarker";
import MapBase from "@/components/shared/map/base/MapBase";

const MainMap = ({ towers, visits, favourites }: { towers: Tower[]; visits: Visit[]; favourites: string[] }) => {
return (
<MapContainer center={[49.8237572, 15.6086383]} zoom={8} scrollWheelZoom={true} className="w-full h-full z-0">
<TileLayer
attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
/>
<MapBase center={{ lat: 49.8237572, lng: 15.6086383 }} zoom={8}>
{towers.map((tower) => {
const isVisited = visits.some((visit) => visit.tower_id === tower.id);
const isFavourite = favourites.includes(tower.id);

return <TowerMarker key={tower.id} tower={tower} isFavourite={isFavourite} isVisited={isVisited} />;
})}
</MapContainer>
</MapBase>
);
};

Expand Down
20 changes: 20 additions & 0 deletions components/shared/map/base/MapBase.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"use client";

import { ReactNode } from "react";
import { MapContainer, TileLayer } from "react-leaflet";
import "leaflet/dist/leaflet.css";
import "leaflet/dist/images/marker-shadow.png";

const MapBase = ({ center, zoom, children }: { center: { lat: number; lng: number }; zoom: number; children: ReactNode }) => {
return (
<MapContainer center={[center.lat, center.lng]} zoom={zoom} scrollWheelZoom={true} className="w-full h-full z-0">
<TileLayer
attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
/>
{children}
</MapContainer>
);
};

export default MapBase;
File renamed without changes.
27 changes: 27 additions & 0 deletions components/shared/map/base/ProfileMap.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"use client";

import { Tower } from "@/types/Tower";
import MapBase from "@/components/shared/map/base/MapBase";
import { Visit } from "@/types/Visit";
import TowerMarker from "@/components/shared/map/base/TowerMarker";

const TowerMap = ({ towers, visits, favourites }: { towers: Tower[]; visits: Visit[]; favourites: string[] }) => {
return (
<div className="mx-auto w-full max-w-7xl h-96 sm:h-[30rem] lg:h-[34rem] rounded-xl mb-5 overflow-hidden touch-none">
<MapBase center={{ lat: 49.8237572, lng: 15.6086383 }} zoom={8}>
{towers.map((tower) => {
const isVisited = visits.some((visit) => visit.tower_id === tower.id);
const isFavourite = favourites.includes(tower.id);

if (!isVisited && !isFavourite) {
return null;
}

return <TowerMarker key={tower.id} tower={tower} isFavourite={isFavourite} isVisited={isVisited} />;
})}
</MapBase>
</div>
);
};

export default TowerMap;
18 changes: 18 additions & 0 deletions components/shared/map/base/TowerMap.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"use client";

import { Tower } from "@/types/Tower";
import { Marker } from "react-leaflet";
import { defaultIcon } from "@/components/shared/map/base/icons";
import MapBase from "@/components/shared/map/base/MapBase";

const TowerMap = ({ tower }: { tower: Tower }) => {
return (
<div className="mx-auto w-full max-w-7xl h-96 sm:h-[30rem] lg:h-[34rem] rounded-xl mb-5 overflow-hidden touch-none">
<MapBase center={{ lat: tower.gps.latitude, lng: tower.gps.longitude }} zoom={12}>
<Marker position={{ lat: tower.gps.latitude, lng: tower.gps.longitude }} icon={defaultIcon} title={tower.name} />
</MapBase>
</div>
);
};

export default TowerMap;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defaultIcon, favouriteIcon, visitedIcon } from "@/components/shared/map/icons";
import MapTowerCard from "@/components/shared/map/MapTowerCard";
import { defaultIcon, favouriteIcon, visitedIcon } from "@/components/shared/map/base/icons";
import MapTowerCard from "@/components/shared/map/base/MapTowerCard";
import { Tower } from "@/types/Tower";
import { Marker, Popup } from "react-leaflet";

Expand Down
File renamed without changes.
45 changes: 0 additions & 45 deletions components/tower/tiles/Map.tsx

This file was deleted.

Loading

0 comments on commit b209260

Please sign in to comment.