From 8ced9d39e7da0c6e39e669532ffc0f4d99f96932 Mon Sep 17 00:00:00 2001 From: Anton Date: Wed, 20 Dec 2023 20:38:16 +0100 Subject: [PATCH] profile layer basics --- src/Components/Map/ItemView.tsx | 4 +-- src/Components/Map/Layer.tsx | 5 +-- .../ItemPopupComponents/HeaderView.tsx | 35 +++++++++++++------ .../Map/Subcomponents/ItemViewPopup.tsx | 18 +++++++++- .../Map/Subcomponents/LayerControl.tsx | 4 +-- .../Map/Subcomponents/QuestControl.tsx | 2 +- src/types.ts | 6 +++- 7 files changed, 54 insertions(+), 20 deletions(-) diff --git a/src/Components/Map/ItemView.tsx b/src/Components/Map/ItemView.tsx index 354613ba..50eba914 100644 --- a/src/Components/Map/ItemView.tsx +++ b/src/Components/Map/ItemView.tsx @@ -8,8 +8,8 @@ export const ItemView = ({ children, item }: { children?: React.ReactNode, item?
{children ? React.Children.toArray(children).map((child) => - React.isValidElement<{ item: Item, test: string }>(child) ? - React.cloneElement(child, { item: item, test: "test" }) : "" + React.isValidElement<{ item: Item }>(child) ? + React.cloneElement(child, { item: item }) : "" ) : ""}
) diff --git a/src/Components/Map/Layer.tsx b/src/Components/Map/Layer.tsx index d0c3884e..2a18ab7a 100644 --- a/src/Components/Map/Layer.tsx +++ b/src/Components/Map/Layer.tsx @@ -85,6 +85,7 @@ export const Layer = (props: LayerProps) => { <> {items && items. + filter(item => item.text). filter(item => item.layer?.name === props.name)?. filter(item => filterTags.length == 0 ? item : filterTags.every(tag => getItemTags(item).some(filterTag => filterTag.id === tag.id)))?. @@ -117,7 +118,7 @@ export const Layer = (props: LayerProps) => { { if (!(item.id in leafletRefs)) r && addPopup(item, r as Popup); - }} key={item.id + item.name} item={item} setItemFormPopup={props.setItemFormPopup} >{child} + }} key={item.id + item.name} itemTitleField={props.itemTitleField} itemAvatarField={props.itemAvatarField} item={item} setItemFormPopup={props.setItemFormPopup} >{child} : "" ) : @@ -125,7 +126,7 @@ export const Layer = (props: LayerProps) => { { if (!(item.id in leafletRefs)) r && addPopup(item, r as Popup); - }} item={item} setItemFormPopup={props.setItemFormPopup} /> + }} item={item} itemTitleField={props.itemTitleField} itemAvatarField={props.itemAvatarField} setItemFormPopup={props.setItemFormPopup} /> ) } {item.name} diff --git a/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView.tsx b/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView.tsx index 58ae0eb0..3a77908a 100644 --- a/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView.tsx +++ b/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView.tsx @@ -9,8 +9,10 @@ import { useHasUserPermission } from "../../hooks/usePermissions"; -export function HeaderView({ item, setItemFormPopup }: { +export function HeaderView({ item, title, avatar, setItemFormPopup }: { item: Item, + title?: string, + avatar?: string, setItemFormPopup?: React.Dispatch> }) { @@ -25,15 +27,15 @@ export function HeaderView({ item, setItemFormPopup }: { setLoading(true); let success = false; try { - await item.layer?.api?.deleteItem!(item.id) - success = true; + await item.layer?.api?.deleteItem!(item.id) + success = true; } catch (error) { - toast.error(error.toString()); + toast.error(error.toString()); } - if(success) { + if (success) { removeItem(item); - toast.success("Item deleted"); - } + toast.success("Item deleted"); + } setLoading(false); map.closePopup(); @@ -47,11 +49,22 @@ export function HeaderView({ item, setItemFormPopup }: { setItemFormPopup({ position: new LatLng(item.position.coordinates[1], item.position.coordinates[0]), layer: item.layer!, item: item, setItemFormPopup: setItemFormPopup }) } - + console.log(title); + + return (
- {item.name} +
{ + avatar ? +
+ +
+ : + "" + } + {title ? title : item.name} +
{item.layer?.api && @@ -62,7 +75,7 @@ export function HeaderView({ item, setItemFormPopup }: {