- {props.children ? (
- Children.toArray(props.children).map((child) =>
- isValidElement<{ item: Item; test: string }>(child)
- ? cloneElement(child, { item: props.item })
- : '',
- )
- ) : (
-
- )}
+ {props.children ?? }
{infoExpanded ? (
diff --git a/src/Components/Map/UtopiaMapInner.tsx b/src/Components/Map/UtopiaMapInner.tsx
index ca5056fa..64860a1a 100644
--- a/src/Components/Map/UtopiaMapInner.tsx
+++ b/src/Components/Map/UtopiaMapInner.tsx
@@ -6,7 +6,7 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-call */
/* eslint-disable @typescript-eslint/no-unsafe-argument */
-import { Children, cloneElement, isValidElement, useEffect, useRef, useState } from 'react'
+import { useEffect, useRef } from 'react'
import { TileLayer, useMapEvents, GeoJSON, useMap } from 'react-leaflet'
import MarkerClusterGroup from 'react-leaflet-cluster'
import { Outlet, useLocation } from 'react-router-dom'
@@ -20,6 +20,7 @@ import { useClusterRef, useSetClusterRef } from './hooks/useClusterRef'
import { useAddVisibleLayer } from './hooks/useFilter'
import { useLayers } from './hooks/useLayers'
import { useLeafletRefs } from './hooks/useLeafletRefs'
+import { usePopupForm } from './hooks/usePopupForm'
import {
useSelectPosition,
useSetMapClicked,
@@ -35,7 +36,6 @@ import { TagsControl } from './Subcomponents/Controls/TagsControl'
import { TextView } from './Subcomponents/ItemPopupComponents/TextView'
import { SelectPosition } from './Subcomponents/SelectPosition'
-import type { ItemFormPopupProps } from '#types/ItemFormPopupProps'
import type { Feature, Geometry as GeoJSONGeometry, GeoJsonObject } from 'geojson'
export function UtopiaMapInner({
@@ -62,17 +62,15 @@ export function UtopiaMapInner({
const setClusterRef = useSetClusterRef()
const clusterRef = useClusterRef()
const setMapClicked = useSetMapClicked()
- const [itemFormPopup, setItemFormPopup] = useState
(null)
-
- useTheme(defaultTheme)
-
+ const { setPopupForm } = usePopupForm()
const layers = useLayers()
const addVisibleLayer = useAddVisibleLayer()
const leafletRefs = useLeafletRefs()
-
const location = useLocation()
const map = useMap()
+ useTheme(defaultTheme)
+
useEffect(() => {
layers.forEach((layer) => addVisibleLayer(layer))
// eslint-disable-next-line react-hooks/exhaustive-deps
@@ -119,7 +117,7 @@ export function UtopiaMapInner({
// eslint-disable-next-line no-console
console.log(e.latlng.lat + ',' + e.latlng.lng)
if (selectNewItemPosition) {
- setMapClicked({ position: e.latlng, setItemFormPopup })
+ setMapClicked({ position: e.latlng, setItemFormPopup: setPopupForm })
}
},
moveend: () => {},
@@ -224,15 +222,7 @@ export function UtopiaMapInner({
maxClusterRadius={50}
removeOutsideVisibleBounds={false}
>
- {Children.toArray(children).map((child) =>
- isValidElement<{
- setItemFormPopup: React.Dispatch>
- itemFormPopup: ItemFormPopupProps | null
- clusterRef: React.MutableRefObject
- }>(child)
- ? cloneElement(child, { setItemFormPopup, itemFormPopup, clusterRef })
- : child,
- )}
+ {children}
{geo && (
{
if (selectNewItemPosition) {
e.layer.closePopup()
- setMapClicked({ position: e.latlng, setItemFormPopup })
+ setMapClicked({ position: e.latlng, setItemFormPopup: setPopupForm })
}
},
}}
diff --git a/src/Components/Map/hooks/usePopupForm.tsx b/src/Components/Map/hooks/usePopupForm.tsx
new file mode 100644
index 00000000..497c5931
--- /dev/null
+++ b/src/Components/Map/hooks/usePopupForm.tsx
@@ -0,0 +1,34 @@
+import { createContext, useContext, useState } from 'react'
+
+import type { PopupFormState } from '#types/PopupFormState'
+
+type UsePopupFormManagerResult = ReturnType
+
+const PoupFormContext = createContext({
+ popupForm: {} as PopupFormState | null,
+ setPopupForm: () => {
+ /* empty function */
+ },
+})
+
+function usePopupFormManager(): {
+ popupForm: PopupFormState | null
+ setPopupForm: React.Dispatch>
+} {
+ const [popupForm, setPopupForm] = useState(null)
+
+ return { popupForm, setPopupForm }
+}
+
+interface Props {
+ children?: React.ReactNode
+}
+
+export const PopupFormProvider: React.FunctionComponent = ({ children }: Props) => (
+ {children}
+)
+
+export const usePopupForm = (): UsePopupFormManagerResult => {
+ const { popupForm, setPopupForm } = useContext(PoupFormContext)
+ return { popupForm, setPopupForm }
+}
diff --git a/src/Components/Map/hooks/useSelectPosition.tsx b/src/Components/Map/hooks/useSelectPosition.tsx
index e53e0193..e1ebf9dc 100644
--- a/src/Components/Map/hooks/useSelectPosition.tsx
+++ b/src/Components/Map/hooks/useSelectPosition.tsx
@@ -15,14 +15,14 @@ import { useUpdateItem } from './useItems'
import { useHasUserPermission } from './usePermissions'
import type { Item } from '#types/Item'
-import type { ItemFormPopupProps } from '#types/ItemFormPopupProps'
import type { LayerProps } from '#types/LayerProps'
+import type { PopupFormState } from '#types/PopupFormState'
import type { Point } from 'geojson'
import type { LatLng } from 'leaflet'
interface PolygonClickedProps {
position: LatLng
- setItemFormPopup: React.Dispatch>
+ setItemFormPopup: React.Dispatch>
}
type UseSelectPositionManagerResult = ReturnType
@@ -60,7 +60,9 @@ function useSelectPositionManager(): {
useEffect(() => {
if (selectPosition != null) {
+ // selectPosition can be null, Layer or Item
if ('menuIcon' in selectPosition) {
+ // if selectPosition is a Layer
mapClicked &&
mapClicked.setItemFormPopup({
layer: selectPosition,
@@ -69,6 +71,7 @@ function useSelectPositionManager(): {
setSelectPosition(null)
}
if ('text' in selectPosition) {
+ // if selectPosition is an Item
const position =
mapClicked?.position.lng &&
({
diff --git a/src/Components/Map/index.tsx b/src/Components/Map/index.tsx
index 6ef08d6c..0dbcc233 100644
--- a/src/Components/Map/index.tsx
+++ b/src/Components/Map/index.tsx
@@ -2,8 +2,7 @@ export { UtopiaMap } from './UtopiaMap'
export * from './Layer'
export { Tags } from './Tags'
export * from './Permissions'
-export { ItemForm } from './ItemForm'
-export { ItemView } from './ItemView'
+/*
export { PopupTextAreaInput } from './Subcomponents/ItemPopupComponents/PopupTextAreaInput'
export { PopupStartEndInput } from './Subcomponents/ItemPopupComponents/PopupStartEndInput'
export { PopupTextInput } from './Subcomponents/ItemPopupComponents/PopupTextInput'
@@ -11,3 +10,4 @@ export { PopupCheckboxInput } from './Subcomponents/ItemPopupComponents/PopupChe
export { TextView } from './Subcomponents/ItemPopupComponents/TextView'
export { StartEndView } from './Subcomponents/ItemPopupComponents/StartEndView'
export { PopupButton } from './Subcomponents/ItemPopupComponents/PopupButton'
+*/
diff --git a/src/Components/Profile/Subcomponents/ProfileStartEndForm.tsx b/src/Components/Profile/Subcomponents/ProfileStartEndForm.tsx
index e5f67ffe..fa7d20c4 100644
--- a/src/Components/Profile/Subcomponents/ProfileStartEndForm.tsx
+++ b/src/Components/Profile/Subcomponents/ProfileStartEndForm.tsx
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-unsafe-return */
-import { PopupStartEndInput } from '#components/Map'
+import { PopupStartEndInput } from '#components/Map/Subcomponents/ItemPopupComponents'
import type { Item } from '#types/Item'
diff --git a/src/Components/Profile/Subcomponents/ProfileStartEndView.tsx b/src/Components/Profile/Subcomponents/ProfileStartEndView.tsx
index d490d725..67ac93f3 100644
--- a/src/Components/Profile/Subcomponents/ProfileStartEndView.tsx
+++ b/src/Components/Profile/Subcomponents/ProfileStartEndView.tsx
@@ -1,4 +1,4 @@
-import { StartEndView } from '#components/Map'
+import { StartEndView } from '#components/Map/Subcomponents/ItemPopupComponents'
import type { Item } from '#types/Item'
diff --git a/src/Components/Profile/Subcomponents/ProfileTextView.tsx b/src/Components/Profile/Subcomponents/ProfileTextView.tsx
index df1d5e77..2adbb3e1 100644
--- a/src/Components/Profile/Subcomponents/ProfileTextView.tsx
+++ b/src/Components/Profile/Subcomponents/ProfileTextView.tsx
@@ -1,6 +1,6 @@
import { get } from 'radash'
-import { TextView } from '#components/Map'
+import { TextView } from '#components/Map/Subcomponents/ItemPopupComponents'
import type { Item } from '#types/Item'
diff --git a/src/Components/Profile/Templates/OnepagerView.tsx b/src/Components/Profile/Templates/OnepagerView.tsx
index 088b92a6..7c2d8077 100644
--- a/src/Components/Profile/Templates/OnepagerView.tsx
+++ b/src/Components/Profile/Templates/OnepagerView.tsx
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/restrict-template-expressions */
-import { TextView } from '#components/Map'
+import { TextView } from '#components/Map/Subcomponents/ItemPopupComponents'
import { ContactInfoView } from '#components/Profile/Subcomponents/ContactInfoView'
import { GroupSubHeaderView } from '#components/Profile/Subcomponents/GroupSubHeaderView'
diff --git a/src/Components/Profile/Templates/SimpleView.tsx b/src/Components/Profile/Templates/SimpleView.tsx
index 894c3459..46b0d7ba 100644
--- a/src/Components/Profile/Templates/SimpleView.tsx
+++ b/src/Components/Profile/Templates/SimpleView.tsx
@@ -1,4 +1,4 @@
-import { TextView } from '#components/Map'
+import { TextView } from '#components/Map/Subcomponents/ItemPopupComponents'
import type { Item } from '#types/Item'
diff --git a/src/Components/Profile/Templates/TabsForm.tsx b/src/Components/Profile/Templates/TabsForm.tsx
index 0a735955..f9931b28 100644
--- a/src/Components/Profile/Templates/TabsForm.tsx
+++ b/src/Components/Profile/Templates/TabsForm.tsx
@@ -10,8 +10,8 @@ import { useCallback, useEffect, useState } from 'react'
import { useNavigate } from 'react-router-dom'
import { TextAreaInput } from '#components/Input'
-import { PopupStartEndInput, TextView } from '#components/Map'
import { useUpdateItem } from '#components/Map/hooks/useItems'
+import { PopupStartEndInput, TextView } from '#components/Map/Subcomponents/ItemPopupComponents'
import { ActionButton } from '#components/Profile/Subcomponents/ActionsButton'
import { LinkedItemsHeaderView } from '#components/Profile/Subcomponents/LinkedItemsHeaderView'
import { TagsWidget } from '#components/Profile/Subcomponents/TagsWidget'
diff --git a/src/Components/Profile/Templates/TabsView.tsx b/src/Components/Profile/Templates/TabsView.tsx
index c14ca054..5dce43a4 100644
--- a/src/Components/Profile/Templates/TabsView.tsx
+++ b/src/Components/Profile/Templates/TabsView.tsx
@@ -10,9 +10,9 @@ import { useCallback, useEffect, useRef, useState } from 'react'
import { Link, useNavigate } from 'react-router-dom'
import { useAppState } from '#components/AppShell/hooks/useAppState'
-import { StartEndView, TextView } from '#components/Map'
import { useAddFilterTag } from '#components/Map/hooks/useFilter'
import { useItems } from '#components/Map/hooks/useItems'
+import { StartEndView, TextView } from '#components/Map/Subcomponents/ItemPopupComponents'
import { ActionButton } from '#components/Profile/Subcomponents/ActionsButton'
import { LinkedItemsHeaderView } from '#components/Profile/Subcomponents/LinkedItemsHeaderView'
import { TagView } from '#components/Templates/TagView'
diff --git a/src/Components/Templates/ItemCard.tsx b/src/Components/Templates/ItemCard.tsx
index 02d86240..6e07688e 100644
--- a/src/Components/Templates/ItemCard.tsx
+++ b/src/Components/Templates/ItemCard.tsx
@@ -1,7 +1,7 @@
import { useNavigate } from 'react-router-dom'
-import { StartEndView, TextView } from '#components/Map'
import useWindowDimensions from '#components/Map/hooks/useWindowDimension'
+import { StartEndView, TextView } from '#components/Map/Subcomponents/ItemPopupComponents'
import { HeaderView } from '#components/Map/Subcomponents/ItemPopupComponents/HeaderView'
import { DateUserInfo } from './DateUserInfo'
diff --git a/src/Components/Templates/OverlayItemsIndexPage.tsx b/src/Components/Templates/OverlayItemsIndexPage.tsx
index 482d639e..68818dfe 100644
--- a/src/Components/Templates/OverlayItemsIndexPage.tsx
+++ b/src/Components/Templates/OverlayItemsIndexPage.tsx
@@ -9,7 +9,6 @@ import { toast } from 'react-toastify'
import { useAuth } from '#components/Auth/useAuth'
import { TextInput, TextAreaInput } from '#components/Input'
-import { PopupStartEndInput } from '#components/Map'
import { useFilterTags } from '#components/Map/hooks/useFilter'
import { useAddItem, useItems, useRemoveItem } from '#components/Map/hooks/useItems'
import { useLayers } from '#components/Map/hooks/useLayers'
@@ -17,6 +16,7 @@ import { useAddTag, useGetItemTags, useTags } from '#components/Map/hooks/useTag
import { Control } from '#components/Map/Subcomponents/Controls/Control'
import { SearchControl } from '#components/Map/Subcomponents/Controls/SearchControl'
import { TagsControl } from '#components/Map/Subcomponents/Controls/TagsControl'
+import { PopupStartEndInput } from '#components/Map/Subcomponents/ItemPopupComponents'
import { PlusButton } from '#components/Profile/Subcomponents/PlusButton'
import { hashTagRegex } from '#utils/HashTagRegex'
import { randomColor } from '#utils/RandomColor'
diff --git a/src/index.tsx b/src/index.tsx
index b84d77a2..07ec6212 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -8,6 +8,7 @@ export * from './Components/Profile'
export * from './Components/Gaming'
export * from './Components/Templates'
export * from './Components/Input'
+export * from './Components/Item'
declare global {
interface Window {
diff --git a/src/types/LayerProps.d.ts b/src/types/LayerProps.d.ts
index b625d830..771688b1 100644
--- a/src/types/LayerProps.d.ts
+++ b/src/types/LayerProps.d.ts
@@ -1,5 +1,4 @@
import type { Item } from './Item'
-import type { ItemFormPopupProps } from './ItemFormPopupProps'
import type { ItemsApi } from './ItemsApi'
import type { ItemType } from './ItemType'
import type { MarkerIcon } from './MarkerIcon'
@@ -27,8 +26,4 @@ export interface LayerProps {
public_edit_items?: boolean
listed?: boolean
item_presets?: Record
- setItemFormPopup?: React.Dispatch>
- itemFormPopup?: ItemFormPopupProps | null
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- clusterRef?: any
}
diff --git a/src/types/ItemFormPopupProps.d.ts b/src/types/PopupFormState.ts
similarity index 53%
rename from src/types/ItemFormPopupProps.d.ts
rename to src/types/PopupFormState.ts
index 64e880bb..1cf0890d 100644
--- a/src/types/ItemFormPopupProps.d.ts
+++ b/src/types/PopupFormState.ts
@@ -2,10 +2,8 @@ import type { Item } from './Item'
import type { LayerProps } from './LayerProps'
import type { LatLng } from 'leaflet'
-export interface ItemFormPopupProps {
+export interface PopupFormState {
position: LatLng
layer: LayerProps
item?: Item
- children?: React.ReactNode
- setItemFormPopup?: React.Dispatch>
}