Skip to content

Commit

Permalink
feat(component): update map settings display
Browse files Browse the repository at this point in the history
Pin is now like the Map page and, when clicked, displays the popup

fix ONEARMY#3856
  • Loading branch information
Lahuen Garcia committed Sep 26, 2024
1 parent b887ef1 commit ffef4d1
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 37 deletions.
8 changes: 8 additions & 0 deletions packages/components/src/Map/index.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
.markercluster-map .closed {
display: none;
}

.leaflet-marker-icon:hover {
cursor: grab;
}

.leaflet-drag-target {
cursor: grabbing;
}
7 changes: 0 additions & 7 deletions packages/components/src/MapWithPin/MapPin.css

This file was deleted.

19 changes: 6 additions & 13 deletions packages/components/src/MapWithPin/MapPin.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import { useRef, useState } from 'react'
import { useRef } from 'react'
import { Marker } from 'react-leaflet'
import L from 'leaflet'

import customMarkerIcon from '../../assets/icons/map-marker.png'
import customMarker from '../../assets/icons/map-marker.png'

import type { DivIcon } from 'leaflet'

import './MapPin.css'

const customMarker = L.icon({
iconUrl: customMarkerIcon,
const customMarkerIcon = L.icon({
iconUrl: customMarker,
iconSize: [20, 28],
iconAnchor: [10, 28],
})

export interface IProps {
interface IProps {
position: {
lat: number
lng: number
Expand All @@ -26,7 +24,6 @@ export interface IProps {

export const MapPin = (props: IProps) => {
const markerRef = useRef(null)
const [isDragging, setIsDragging] = useState(false)

const handleDrag = () => {
const marker: any = markerRef.current
Expand All @@ -43,15 +40,11 @@ export const MapPin = (props: IProps) => {

return (
<Marker
className={`map-pin ${isDragging ? 'dragging' : ''}`}
draggable
onDrag={handleDrag}
position={[props.position.lat, props.position.lng]}
ref={markerRef}
icon={props.markerIcon || customMarker}
onMouseDown={() => setIsDragging(true)}
onMouseUp={() => setIsDragging(false)}
onMouseLeave={() => setIsDragging(false)}
icon={props.markerIcon || customMarkerIcon}
onclick={props.onClick}
/>
)
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/MapWithPin/MapWithPin.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import { useRef } from 'react'

import { MapWithPin } from './MapWithPin'

Expand All @@ -12,7 +12,7 @@ export default {

export const Default: StoryFn<typeof MapWithPin> = () => {
const position = { lat: 0, lng: 0 }
const newMapRef = React.useRef<Map>(null)
const newMapRef = useRef<Map>(null)

return (
<MapWithPin
Expand Down
7 changes: 2 additions & 5 deletions src/models/common.models.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// A reminder that dates should be saved in the ISOString format
// i.e. new Date().toISOString() => 2011-10-05T14:48:00.000Z
import type { ILatLng } from "oa-shared"

// This is more consistent than others and allows better querying
export type ISODateString = string

Expand All @@ -24,9 +26,4 @@ export interface ILocation {
value: string
}

export interface ILatLng {
lat: number
lng: number
}

export type FetchState = 'idle' | 'fetching' | 'completed'
3 changes: 2 additions & 1 deletion src/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { IComment } from './discussion.models'

export * from './common.models'
export * from './discussion.models'
export * from './howto.models'
Expand All @@ -15,4 +17,3 @@ export * from './moderation.model'
export interface UserComment extends IComment {
isEditable: boolean
}
export * from './userPreciousPlastic.models'
14 changes: 5 additions & 9 deletions src/pages/UserSettings/SettingsPageMapPin.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react'
import { useEffect, useRef, useState } from 'react'
import { Field, Form } from 'react-final-form'
import { toJS } from 'mobx'
import {
Expand Down Expand Up @@ -28,13 +28,9 @@ import { SettingsFormNotifications } from './content/SettingsFormNotifications'
import { MAX_PIN_LENGTH } from './constants'

import type { DivIcon } from 'leaflet'
import type { ILatLng } from 'oa-shared'
import type { Map } from 'react-leaflet'
import type {
ILatLng,
ILocation,
IMapPinWithDetail,
IUserPPDB,
} from 'src/models'
import type { ILocation, IMapPinWithDetail, IUserDB } from 'src/models'
import type { IFormNotification } from './content/SettingsFormNotifications'

interface IPinProps {
Expand Down Expand Up @@ -172,7 +168,7 @@ export const SettingsPageMapPin = () => {

const currentTheme = themeStore.currentTheme

const newMapRef = React.useRef<Map>(null)
const newMapRef = useRef<Map>(null)

useEffect(() => {
const init = async () => {
Expand Down Expand Up @@ -245,7 +241,7 @@ export const SettingsPageMapPin = () => {
>
<Flex sx={{ flexDirection: 'column', gap: 1 }}>
<Heading as="h2" id="your-map-pin">
{mapPin ? yourPinTitle : addPinTitle}
{mapPin ? addPinTitle: yourPinTitle}
</Heading>
{isMember && (
<Text
Expand Down

0 comments on commit ffef4d1

Please sign in to comment.