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 #3856
  • Loading branch information
Lahuen Garcia committed Sep 26, 2024
1 parent b887ef1 commit 4cfeca1
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 27 deletions.
4 changes: 2 additions & 2 deletions packages/components/src/MapWithPin/MapPin.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.leaflet-marker-icon:hover {
cursor: grab !important;
.markercluster-map.settings-page .leaflet-marker-icon:hover {
cursor: grab;
}

.leaflet-drag-target {
Expand Down
9 changes: 2 additions & 7 deletions packages/components/src/MapWithPin/MapPin.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useRef, useState } from 'react'
import { useRef } from 'react'
import { Marker } from 'react-leaflet'
import L from 'leaflet'

Expand All @@ -14,7 +14,7 @@ const customMarker = L.icon({
iconAnchor: [10, 28],
})

export interface IProps {
interface IProps {
position: {
lat: number
lng: number
Expand All @@ -26,7 +26,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 +42,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)}
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
2 changes: 1 addition & 1 deletion packages/components/src/MapWithPin/MapWithPin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export const MapWithPin = (props: Props) => {
</Box>
<Map
ref={mapRef}
className="markercluster-map"
className="markercluster-map settings-page"
center={center}
zoom={zoom}
zoomControl={false}
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 4cfeca1

Please sign in to comment.