Skip to content

Commit

Permalink
Sizing on mobile, attribution collapsed by default
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyabo committed Sep 8, 2024
1 parent f721608 commit 35c985e
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 7 deletions.
14 changes: 14 additions & 0 deletions assets/js/components/icons/map-info-icon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React, {FC} from "react";
type Props = {
size?: number;
};
const MapInfoIcon: FC<Props> = (props) => {
const {size = 24} = props;
return (
<svg width={size} height={size} fill-rule="evenodd" viewBox="0 0 20 20">
<path d="M4 10a6 6 0 1 0 12 0 6 6 0 1 0-12 0m5-3a1 1 0 1 0 2 0 1 1 0 1 0-2 0m0 3a1 1 0 1 1 2 0v3a1 1 0 1 1-2 0" />
</svg>
);
};

export default MapInfoIcon;
31 changes: 25 additions & 6 deletions assets/js/map/map-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,26 @@ import React, {
useRef,
useState,
} from "react";
import {MapLayerMouseEvent} from "react-map-gl";
import {
MapRef,
Map as ReactMapGl,
useControl,
AttributionControl,
ViewStateChangeEvent,
} from "react-map-gl/maplibre";
import {useAppStore} from "../store/store";
import {colorToRGBA, findLastLabelLayerId} from "../store/utils";
import {useDrawHandler} from "./use-draw-handlers";

import {MapLayerMouseEvent} from "react-map-gl";
import {CursorPresenceOverlay} from "./cursor-presence-overlay";
import CustomOverlay from "./custom-overlay";
import MapControlsContainer from "./map-controls-container";
import {useDrawHandler} from "./use-draw-handlers";
import {useKeyStrokes} from "./use-key-strokes";
import {usePanning} from "./use-panning";
import CustomOverlay from "./custom-overlay";
import {CursorPresenceOverlay} from "./cursor-presence-overlay";
import {Button} from "../components/ui/button";
import {InfoIcon} from "lucide-react";
import {cn} from "../components/ui/utils";
import MapInfoIcon from "../components/icons/map-info-icon";

const defaultColor: [number, number, number, number] = [150, 150, 150, 200];

Expand Down Expand Up @@ -161,8 +165,10 @@ export const MapContainer: FC = () => {
);
}

const [showAttribution, setShowAttribution] = useState(false);

return (
<div className="map-container absolute w-[100vw] h-[100vh] top-0 left-0">
<div className="map-container absolute inset-0 pb-safe-bottom">
<ReactMapGl
ref={mapRef}
{...mapViewState}
Expand All @@ -172,6 +178,7 @@ export const MapContainer: FC = () => {
onLoad={onMapLoad}
onMove={handleMove}
onMouseMove={handleMouseMove}
attributionControl={false}
>
<DeckGLOverlay
layers={layers}
Expand All @@ -185,6 +192,18 @@ export const MapContainer: FC = () => {
<CustomOverlay>
<CursorPresenceOverlay />
</CustomOverlay>
{showAttribution ? (
<AttributionControl compact customAttribution="© MapCanv" />
) : (
<Button
size="icon"
variant="ghost"
className="absolute bottom-[10px] right-[10px] rounded-full bg-white h-6 w-6"
onClick={() => setShowAttribution(true)}
>
<MapInfoIcon />
</Button>
)}
</ReactMapGl>

<MapControlsContainer mapRef={mapRef} />
Expand Down
2 changes: 1 addition & 1 deletion assets/js/map/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export const DrawingMode = {
SELECT: "select",
SELECT_RECT: "select:rect",
MOVE: "move",
DRAW_LINE: "draw:line",
DRAW_POLYGON_FREEHAND: "draw:polygon-freehand",
DRAW_LINE: "draw:line",
DRAW_POLYGON: "draw:polygon",
// DRAW_HEXAGON: "draw:hexagon",
} as const satisfies Record<string, string>;
Expand Down
6 changes: 6 additions & 0 deletions assets/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ module.exports = {
],
theme: {
extend: {
spacing: {
"safe-bottom": "env(safe-area-inset-bottom)",
"safe-top": "env(safe-area-inset-top)",
"safe-left": "env(safe-area-inset-left)",
"safe-right": "env(safe-area-inset-right)",
},
colors: {
brand: "#FD4F00",
border: "hsl(var(--border))",
Expand Down
7 changes: 7 additions & 0 deletions lib/mapcanv/features_agent.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,11 @@ defmodule MapCanv.FeaturesAgent do
end
end)
end

# Removes the Yjs document for the given GUID
def remove_document(guid) do
Agent.update(__MODULE__, fn state ->
Map.delete(state, guid)
end)
end
end
1 change: 1 addition & 0 deletions lib/mapcanv_web/channels/drawing_channel.ex
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ defmodule MapCanvWeb.DrawingChannel do
# This was the last user, perform the cleanup
#cleanup_ydoc(guid)
IO.inspect("Cleaning up resources for drawing channel with guid: #{guid}")
FeaturesAgent.remove_document(guid)
end

:ok
Expand Down

0 comments on commit 35c985e

Please sign in to comment.