From 15fbd3e6ce2abf8409186cac9df744e39e537ce0 Mon Sep 17 00:00:00 2001 From: Anton Tranelis <31516529+antontranelis@users.noreply.github.com> Date: Mon, 13 Oct 2025 13:15:06 +0200 Subject: [PATCH] fix(lib): improved item header (#383) Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- app/src/pages/MapContainer.tsx | 2 +- .../development/collections/settings.json | 2 + .../snapshot/fields/types/Header.json | 32 +++ .../snapshot/fields/types/Profile.json | 5 +- .../fields/types/cta_button_label.json | 59 +++++ .../fields/types/header_elements.json | 29 +++ .../fields/types/show_cta_button.json | 45 ++++ .../fields/types/show_navigation_button.json | 45 ++++ .../snapshot/fields/types/show_qr_button.json | 45 ++++ .../fields/types/show_share_button.json | 45 ++++ .../snapshot/fields/types/small_form.json | 5 +- .../snapshot/fields/types/small_view.json | 5 +- .../snapshot/fields/types/subtitle_label.json | 74 ++++++ .../snapshot/fields/types/subtitle_mode.json | 58 +++++ lib/src/Components/Item/PopupView.tsx | 2 +- .../Subcomponents/Controls/SearchControl.tsx | 2 +- .../Map/Subcomponents/ItemFormPopup.tsx | 2 +- .../ItemPopupComponents/HeaderView.tsx | 223 +----------------- .../HeaderView/ActionButtons.tsx | 42 ++++ .../HeaderView/ConnectionStatus.tsx | 46 ++++ .../HeaderView/DeleteModal.tsx | 37 +++ .../HeaderView/EditMenu.tsx | 112 +++++++++ .../HeaderView/ItemAvatar.tsx | 73 ++++++ .../HeaderView/ItemTitle.tsx | 132 +++++++++++ .../HeaderView/QRModal.tsx | 44 ++++ .../HeaderView/ShareButton.tsx | 168 +++++++++++++ .../ItemPopupComponents/HeaderView/hooks.ts | 77 ++++++ .../ItemPopupComponents/HeaderView/index.tsx | 91 +++++++ .../ItemPopupComponents/HeaderView/types.ts | 31 +++ .../ItemPopupComponents/StartEndView.tsx | 22 +- .../Map/Subcomponents/ItemViewPopup.tsx | 6 +- lib/src/Components/Map/UtopiaMapInner.tsx | 2 +- .../Components/Map/hooks/useGeoDistance.tsx | 56 +++++ .../Components/Map/hooks/useReverseGeocode.ts | 108 +++++++++ lib/src/Components/Profile/ProfileView.tsx | 9 +- .../Profile/Subcomponents/ActionsButton.tsx | 2 +- .../Profile/Subcomponents/FormHeader.tsx | 32 +-- .../Subcomponents/GroupSubHeaderView.tsx | 2 +- .../Subcomponents/LinkedItemsHeaderView.tsx | 2 +- .../Subcomponents/ProfileStartEndView.tsx | 2 +- lib/src/Components/Templates/DialogModal.tsx | 6 +- lib/src/types/Item.d.ts | 2 +- lib/src/types/ItemType.d.ts | 10 +- 43 files changed, 1521 insertions(+), 273 deletions(-) create mode 100644 backend/directus-config/development/snapshot/fields/types/Header.json create mode 100644 backend/directus-config/development/snapshot/fields/types/cta_button_label.json create mode 100644 backend/directus-config/development/snapshot/fields/types/header_elements.json create mode 100644 backend/directus-config/development/snapshot/fields/types/show_cta_button.json create mode 100644 backend/directus-config/development/snapshot/fields/types/show_navigation_button.json create mode 100644 backend/directus-config/development/snapshot/fields/types/show_qr_button.json create mode 100644 backend/directus-config/development/snapshot/fields/types/show_share_button.json create mode 100644 backend/directus-config/development/snapshot/fields/types/subtitle_label.json create mode 100644 backend/directus-config/development/snapshot/fields/types/subtitle_mode.json create mode 100644 lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/ActionButtons.tsx create mode 100644 lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/ConnectionStatus.tsx create mode 100644 lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/DeleteModal.tsx create mode 100644 lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/EditMenu.tsx create mode 100644 lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/ItemAvatar.tsx create mode 100644 lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/ItemTitle.tsx create mode 100644 lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/QRModal.tsx create mode 100644 lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/ShareButton.tsx create mode 100644 lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/hooks.ts create mode 100644 lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/index.tsx create mode 100644 lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/types.ts create mode 100644 lib/src/Components/Map/hooks/useGeoDistance.tsx create mode 100644 lib/src/Components/Map/hooks/useReverseGeocode.ts diff --git a/app/src/pages/MapContainer.tsx b/app/src/pages/MapContainer.tsx index 0211ab05..d3317a0a 100644 --- a/app/src/pages/MapContainer.tsx +++ b/app/src/pages/MapContainer.tsx @@ -124,7 +124,7 @@ function MapContainer({ layers, map }: { layers: LayerProps[]; map: any }) { parameterField={ layer.itemType.custom_profile_url ? 'extended.external_profile_id' : 'id' } - text={layer.itemType.botton_label ?? 'Profile'} + text={layer.itemType.button_label ?? 'Profile'} target={layer.itemType.custom_profile_url ? '_blank' : '_self'} /> )} diff --git a/backend/directus-config/development/collections/settings.json b/backend/directus-config/development/collections/settings.json index 3de70c72..09d708cf 100644 --- a/backend/directus-config/development/collections/settings.json +++ b/backend/directus-config/development/collections/settings.json @@ -60,6 +60,8 @@ "public_registration_role": null, "public_registration_email_filter": null, "visual_editor_urls": null, + "accepted_terms": true, + "project_id": "0199aa52-4dd7-7293-984a-f2af93b5f8fd", "_syncId": "55f04445-0c26-4201-ab9c-d6e0fbadf6bf" } ] diff --git a/backend/directus-config/development/snapshot/fields/types/Header.json b/backend/directus-config/development/snapshot/fields/types/Header.json new file mode 100644 index 00000000..7c1d379b --- /dev/null +++ b/backend/directus-config/development/snapshot/fields/types/Header.json @@ -0,0 +1,32 @@ +{ + "collection": "types", + "field": "Header", + "type": "alias", + "meta": { + "collection": "types", + "conditions": null, + "display": null, + "display_options": null, + "field": "Header", + "group": null, + "hidden": false, + "interface": "group-detail", + "note": null, + "options": { + "headerIcon": "credit_card", + "start": "closed" + }, + "readonly": false, + "required": false, + "sort": 7, + "special": [ + "alias", + "no-data", + "group" + ], + "translations": null, + "validation": null, + "validation_message": null, + "width": "full" + } +} diff --git a/backend/directus-config/development/snapshot/fields/types/Profile.json b/backend/directus-config/development/snapshot/fields/types/Profile.json index 4ffa0164..a4d2ed72 100644 --- a/backend/directus-config/development/snapshot/fields/types/Profile.json +++ b/backend/directus-config/development/snapshot/fields/types/Profile.json @@ -13,11 +13,12 @@ "interface": "group-detail", "note": null, "options": { - "headerIcon": "lab_profile" + "headerIcon": "lab_profile", + "start": "closed" }, "readonly": false, "required": false, - "sort": 9, + "sort": 10, "special": [ "alias", "no-data", diff --git a/backend/directus-config/development/snapshot/fields/types/cta_button_label.json b/backend/directus-config/development/snapshot/fields/types/cta_button_label.json new file mode 100644 index 00000000..c5a375d8 --- /dev/null +++ b/backend/directus-config/development/snapshot/fields/types/cta_button_label.json @@ -0,0 +1,59 @@ +{ + "collection": "types", + "field": "cta_button_label", + "type": "string", + "meta": { + "collection": "types", + "conditions": [ + { + "hidden": true, + "name": "show cta button", + "readonly": false, + "required": false, + "rule": { + "_and": [ + { + "show_cta_button": { + "_eq": false + } + } + ] + } + } + ], + "display": null, + "display_options": null, + "field": "cta_button_label", + "group": "header_elements", + "hidden": false, + "interface": "input", + "note": null, + "options": null, + "readonly": false, + "required": false, + "sort": 5, + "special": null, + "translations": null, + "validation": null, + "validation_message": null, + "width": "half" + }, + "schema": { + "name": "cta_button_label", + "table": "types", + "data_type": "character varying", + "default_value": null, + "max_length": 255, + "numeric_precision": null, + "numeric_scale": null, + "is_nullable": true, + "is_unique": false, + "is_indexed": false, + "is_primary_key": false, + "is_generated": false, + "generation_expression": null, + "has_auto_increment": false, + "foreign_key_table": null, + "foreign_key_column": null + } +} diff --git a/backend/directus-config/development/snapshot/fields/types/header_elements.json b/backend/directus-config/development/snapshot/fields/types/header_elements.json new file mode 100644 index 00000000..0df97f33 --- /dev/null +++ b/backend/directus-config/development/snapshot/fields/types/header_elements.json @@ -0,0 +1,29 @@ +{ + "collection": "types", + "field": "header_elements", + "type": "alias", + "meta": { + "collection": "types", + "conditions": null, + "display": null, + "display_options": null, + "field": "header_elements", + "group": "Header", + "hidden": false, + "interface": "group-raw", + "note": null, + "options": null, + "readonly": false, + "required": false, + "sort": 3, + "special": [ + "alias", + "no-data", + "group" + ], + "translations": null, + "validation": null, + "validation_message": null, + "width": "full" + } +} diff --git a/backend/directus-config/development/snapshot/fields/types/show_cta_button.json b/backend/directus-config/development/snapshot/fields/types/show_cta_button.json new file mode 100644 index 00000000..35ceacc9 --- /dev/null +++ b/backend/directus-config/development/snapshot/fields/types/show_cta_button.json @@ -0,0 +1,45 @@ +{ + "collection": "types", + "field": "show_cta_button", + "type": "boolean", + "meta": { + "collection": "types", + "conditions": null, + "display": null, + "display_options": null, + "field": "show_cta_button", + "group": "header_elements", + "hidden": false, + "interface": "boolean", + "note": null, + "options": null, + "readonly": false, + "required": false, + "sort": 4, + "special": [ + "cast-boolean" + ], + "translations": null, + "validation": null, + "validation_message": null, + "width": "half" + }, + "schema": { + "name": "show_cta_button", + "table": "types", + "data_type": "boolean", + "default_value": false, + "max_length": null, + "numeric_precision": null, + "numeric_scale": null, + "is_nullable": true, + "is_unique": false, + "is_indexed": false, + "is_primary_key": false, + "is_generated": false, + "generation_expression": null, + "has_auto_increment": false, + "foreign_key_table": null, + "foreign_key_column": null + } +} diff --git a/backend/directus-config/development/snapshot/fields/types/show_navigation_button.json b/backend/directus-config/development/snapshot/fields/types/show_navigation_button.json new file mode 100644 index 00000000..ac51b712 --- /dev/null +++ b/backend/directus-config/development/snapshot/fields/types/show_navigation_button.json @@ -0,0 +1,45 @@ +{ + "collection": "types", + "field": "show_navigation_button", + "type": "boolean", + "meta": { + "collection": "types", + "conditions": null, + "display": null, + "display_options": null, + "field": "show_navigation_button", + "group": "header_elements", + "hidden": false, + "interface": "boolean", + "note": null, + "options": null, + "readonly": false, + "required": false, + "sort": 2, + "special": [ + "cast-boolean" + ], + "translations": null, + "validation": null, + "validation_message": null, + "width": "half" + }, + "schema": { + "name": "show_navigation_button", + "table": "types", + "data_type": "boolean", + "default_value": false, + "max_length": null, + "numeric_precision": null, + "numeric_scale": null, + "is_nullable": true, + "is_unique": false, + "is_indexed": false, + "is_primary_key": false, + "is_generated": false, + "generation_expression": null, + "has_auto_increment": false, + "foreign_key_table": null, + "foreign_key_column": null + } +} diff --git a/backend/directus-config/development/snapshot/fields/types/show_qr_button.json b/backend/directus-config/development/snapshot/fields/types/show_qr_button.json new file mode 100644 index 00000000..5f95f7e0 --- /dev/null +++ b/backend/directus-config/development/snapshot/fields/types/show_qr_button.json @@ -0,0 +1,45 @@ +{ + "collection": "types", + "field": "show_qr_button", + "type": "boolean", + "meta": { + "collection": "types", + "conditions": null, + "display": null, + "display_options": null, + "field": "show_qr_button", + "group": "header_elements", + "hidden": false, + "interface": "boolean", + "note": null, + "options": null, + "readonly": false, + "required": false, + "sort": 1, + "special": [ + "cast-boolean" + ], + "translations": null, + "validation": null, + "validation_message": null, + "width": "half" + }, + "schema": { + "name": "show_qr_button", + "table": "types", + "data_type": "boolean", + "default_value": false, + "max_length": null, + "numeric_precision": null, + "numeric_scale": null, + "is_nullable": true, + "is_unique": false, + "is_indexed": false, + "is_primary_key": false, + "is_generated": false, + "generation_expression": null, + "has_auto_increment": false, + "foreign_key_table": null, + "foreign_key_column": null + } +} diff --git a/backend/directus-config/development/snapshot/fields/types/show_share_button.json b/backend/directus-config/development/snapshot/fields/types/show_share_button.json new file mode 100644 index 00000000..50fab53c --- /dev/null +++ b/backend/directus-config/development/snapshot/fields/types/show_share_button.json @@ -0,0 +1,45 @@ +{ + "collection": "types", + "field": "show_share_button", + "type": "boolean", + "meta": { + "collection": "types", + "conditions": null, + "display": null, + "display_options": null, + "field": "show_share_button", + "group": "header_elements", + "hidden": false, + "interface": "boolean", + "note": null, + "options": null, + "readonly": false, + "required": false, + "sort": 3, + "special": [ + "cast-boolean" + ], + "translations": null, + "validation": null, + "validation_message": null, + "width": "half" + }, + "schema": { + "name": "show_share_button", + "table": "types", + "data_type": "boolean", + "default_value": false, + "max_length": null, + "numeric_precision": null, + "numeric_scale": null, + "is_nullable": true, + "is_unique": false, + "is_indexed": false, + "is_primary_key": false, + "is_generated": false, + "generation_expression": null, + "has_auto_increment": false, + "foreign_key_table": null, + "foreign_key_column": null + } +} diff --git a/backend/directus-config/development/snapshot/fields/types/small_form.json b/backend/directus-config/development/snapshot/fields/types/small_form.json index 064a143f..61675926 100644 --- a/backend/directus-config/development/snapshot/fields/types/small_form.json +++ b/backend/directus-config/development/snapshot/fields/types/small_form.json @@ -13,11 +13,12 @@ "interface": "group-detail", "note": null, "options": { - "headerIcon": "edit_square" + "headerIcon": "edit_square", + "start": "closed" }, "readonly": false, "required": false, - "sort": 8, + "sort": 9, "special": [ "alias", "no-data", diff --git a/backend/directus-config/development/snapshot/fields/types/small_view.json b/backend/directus-config/development/snapshot/fields/types/small_view.json index 4dddfbc2..6685a81a 100644 --- a/backend/directus-config/development/snapshot/fields/types/small_view.json +++ b/backend/directus-config/development/snapshot/fields/types/small_view.json @@ -13,11 +13,12 @@ "interface": "group-detail", "note": null, "options": { - "headerIcon": "wysiwyg" + "headerIcon": "wysiwyg", + "start": "closed" }, "readonly": false, "required": false, - "sort": 7, + "sort": 8, "special": [ "alias", "no-data", diff --git a/backend/directus-config/development/snapshot/fields/types/subtitle_label.json b/backend/directus-config/development/snapshot/fields/types/subtitle_label.json new file mode 100644 index 00000000..03f0ba86 --- /dev/null +++ b/backend/directus-config/development/snapshot/fields/types/subtitle_label.json @@ -0,0 +1,74 @@ +{ + "collection": "types", + "field": "subtitle_label", + "type": "string", + "meta": { + "collection": "types", + "conditions": [ + { + "hidden": false, + "name": "subtitle=custom", + "readonly": false, + "required": true, + "rule": { + "_and": [ + { + "subtitle_mode": { + "_eq": "custom" + } + } + ] + } + }, + { + "hidden": true, + "name": "subtitle != custom", + "readonly": true, + "required": false, + "rule": { + "_and": [ + { + "subtitle_mode": { + "_neq": "custom" + } + } + ] + } + } + ], + "display": null, + "display_options": null, + "field": "subtitle_label", + "group": "Header", + "hidden": false, + "interface": "input", + "note": null, + "options": null, + "readonly": false, + "required": false, + "sort": 2, + "special": null, + "translations": null, + "validation": null, + "validation_message": null, + "width": "half" + }, + "schema": { + "name": "subtitle_label", + "table": "types", + "data_type": "character varying", + "default_value": "Subname", + "max_length": 255, + "numeric_precision": null, + "numeric_scale": null, + "is_nullable": true, + "is_unique": false, + "is_indexed": false, + "is_primary_key": false, + "is_generated": false, + "generation_expression": null, + "has_auto_increment": false, + "foreign_key_table": null, + "foreign_key_column": null + } +} diff --git a/backend/directus-config/development/snapshot/fields/types/subtitle_mode.json b/backend/directus-config/development/snapshot/fields/types/subtitle_mode.json new file mode 100644 index 00000000..507c912e --- /dev/null +++ b/backend/directus-config/development/snapshot/fields/types/subtitle_mode.json @@ -0,0 +1,58 @@ +{ + "collection": "types", + "field": "subtitle_mode", + "type": "string", + "meta": { + "collection": "types", + "conditions": null, + "display": null, + "display_options": null, + "field": "subtitle_mode", + "group": "Header", + "hidden": false, + "interface": "select-dropdown", + "note": null, + "options": { + "choices": [ + { + "text": "address", + "value": "address" + }, + { + "text": "custom", + "value": "custom" + }, + { + "text": "none", + "value": "none" + } + ] + }, + "readonly": false, + "required": false, + "sort": 1, + "special": null, + "translations": null, + "validation": null, + "validation_message": null, + "width": "half" + }, + "schema": { + "name": "subtitle_mode", + "table": "types", + "data_type": "character varying", + "default_value": "address", + "max_length": 255, + "numeric_precision": null, + "numeric_scale": null, + "is_nullable": true, + "is_unique": false, + "is_indexed": false, + "is_primary_key": false, + "is_generated": false, + "generation_expression": null, + "has_auto_increment": false, + "foreign_key_table": null, + "foreign_key_column": null + } +} diff --git a/lib/src/Components/Item/PopupView.tsx b/lib/src/Components/Item/PopupView.tsx index 7c096262..98640f38 100644 --- a/lib/src/Components/Item/PopupView.tsx +++ b/lib/src/Components/Item/PopupView.tsx @@ -173,7 +173,7 @@ export const PopupView = ({ children }: { children?: React.ReactNode }) => { - {item.name || item.layer?.item_default_name} + {item.name ?? item.layer?.item_default_name} diff --git a/lib/src/Components/Map/Subcomponents/Controls/SearchControl.tsx b/lib/src/Components/Map/Subcomponents/Controls/SearchControl.tsx index fb3d33d8..8f50b056 100644 --- a/lib/src/Components/Map/Subcomponents/Controls/SearchControl.tsx +++ b/lib/src/Components/Map/Subcomponents/Controls/SearchControl.tsx @@ -79,7 +79,7 @@ export const SearchControl = () => { items.filter((item) => { return ( value.length > 2 && - ((item.layer?.listed && item.name.toLowerCase().includes(value.toLowerCase())) || + ((item.layer?.listed && item.name?.toLowerCase().includes(value.toLowerCase())) || item.text?.toLowerCase().includes(value.toLowerCase())) ) }), diff --git a/lib/src/Components/Map/Subcomponents/ItemFormPopup.tsx b/lib/src/Components/Map/Subcomponents/ItemFormPopup.tsx index cbc9ee71..9e0ab2a1 100644 --- a/lib/src/Components/Map/Subcomponents/ItemFormPopup.tsx +++ b/lib/src/Components/Map/Subcomponents/ItemFormPopup.tsx @@ -146,7 +146,7 @@ export function ItemFormPopup(props: Props) { (i) => i.user_created?.id === user?.id && i.layer === popupForm.layer, ) - const itemName = formItem.name || user?.first_name + const itemName = formItem.name ?? user?.first_name if (!itemName) { toast.error('Name must be defined') return false diff --git a/lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView.tsx b/lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView.tsx index 2c0d49f0..21219a4a 100644 --- a/lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView.tsx +++ b/lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView.tsx @@ -1,222 +1 @@ -/* eslint-disable @typescript-eslint/no-unnecessary-condition */ -/* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */ -/* eslint-disable @typescript-eslint/no-misused-promises */ -/* eslint-disable @typescript-eslint/require-await */ -/* eslint-disable @typescript-eslint/restrict-template-expressions */ -/* eslint-disable @typescript-eslint/restrict-plus-operands */ -/* eslint-disable @typescript-eslint/no-unsafe-call */ -/* eslint-disable @typescript-eslint/no-unsafe-return */ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/no-non-null-assertion */ -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ -import EllipsisVerticalIcon from '@heroicons/react/16/solid/EllipsisVerticalIcon' -import PencilIcon from '@heroicons/react/24/solid/PencilIcon' -import TrashIcon from '@heroicons/react/24/solid/TrashIcon' -import { useState } from 'react' -import SVG from 'react-inlinesvg' -import { useNavigate } from 'react-router-dom' - -import TargetDotSVG from '#assets/targetDot.svg' -import { useAppState } from '#components/AppShell/hooks/useAppState' -import { useHasUserPermission } from '#components/Map/hooks/usePermissions' -import DialogModal from '#components/Templates/DialogModal' - -import type { Item } from '#types/Item' -import type { ItemsApi } from '#types/ItemsApi' - -export function HeaderView({ - item, - api, - editCallback, - deleteCallback, - setPositionCallback, - loading, - hideMenu = false, - big = false, - truncateSubname = true, - hideSubname = false, - showAddress = false, -}: { - item?: Item - api?: ItemsApi - editCallback?: any - deleteCallback?: any - setPositionCallback?: any - loading?: boolean - hideMenu?: boolean - big?: boolean - hideSubname?: boolean - truncateSubname?: boolean - showAddress?: boolean -}) { - const [modalOpen, setModalOpen] = useState(false) - - const hasUserPermission = useHasUserPermission() - const navigate = useNavigate() - const appState = useAppState() - - const [imageLoaded, setImageLoaded] = useState(false) - - const avatar = - (item?.image && appState.assetsApi.url + item.image + '?width=160&heigth=160') || - item?.image_external - const title = item?.name ?? item?.layer?.item_default_name - const subtitle = item?.subname - - const [address] = useState('') - - const params = new URLSearchParams(window.location.search) - - const openDeleteModal = async (event: React.MouseEvent) => { - setModalOpen(true) - event.stopPropagation() - } - if (!item) return null - return ( - <> -
-
-
- {avatar && ( -
-
- {item.name setImageLoaded(true)} - onError={() => setImageLoaded(false)} - style={{ display: imageLoaded ? 'block' : 'none' }} - /> - {!imageLoaded && ( -
- )} -
-
- )} -
-
- {title} -
- {showAddress && address && !hideSubname && ( -
- {address} -
- )} - {subtitle && !hideSubname && ( -
- {subtitle} -
- )} -
-
-
-
e.stopPropagation()} className={`${big ? 'tw:mt-5' : 'tw:mt-1'}`}> - {(api?.deleteItem || item.layer?.api?.updateItem) && - (hasUserPermission(api?.collectionName!, 'delete', item) || - hasUserPermission(api?.collectionName!, 'update', item)) && - !hideMenu && ( -
- - -
- )} -
-
- setModalOpen(false)} - > -
e.stopPropagation()}> - - Do you want to delete {item.name}? - -
-
- - -
-
-
-
- - ) -} +export { HeaderView } from './HeaderView/index' diff --git a/lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/ActionButtons.tsx b/lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/ActionButtons.tsx new file mode 100644 index 00000000..e36e70fe --- /dev/null +++ b/lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/ActionButtons.tsx @@ -0,0 +1,42 @@ +import { LuNavigation } from 'react-icons/lu' + +import { useMyProfile } from '#components/Map/hooks/useMyProfile' + +import { useNavigationUrl } from './hooks' +import { ShareButton } from './ShareButton' + +import type { Item } from '#types/Item' + +interface ActionButtonsProps { + item: Item +} + +export function ActionButtons({ item }: ActionButtonsProps) { + const myProfile = useMyProfile() + const { getNavigationUrl, isMobile, isIOS } = useNavigationUrl( + item.position?.coordinates as [number, number] | undefined, + ) + + const showNavigationButton = item.layer?.itemType.show_navigation_button ?? true + const showShareButton = item.layer?.itemType.show_share_button ?? true + const isOtherProfile = myProfile.myProfile?.id !== item.id + + return ( + <> + {item.position?.coordinates && isOtherProfile && showNavigationButton && ( + + + + )} + {isOtherProfile && showShareButton && } + + ) +} diff --git a/lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/ConnectionStatus.tsx b/lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/ConnectionStatus.tsx new file mode 100644 index 00000000..42a21e0d --- /dev/null +++ b/lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/ConnectionStatus.tsx @@ -0,0 +1,46 @@ +import { FaPlus } from 'react-icons/fa6' + +import { useMyProfile } from '#components/Map/hooks/useMyProfile' +import { useGetItemTags } from '#components/Map/hooks/useTags' + +import type { Item } from '#types/Item' + +interface ConnectionStatusProps { + item: Item +} + +export function ConnectionStatus({ item }: ConnectionStatusProps) { + const myProfile = useMyProfile() + const getItemTags = useGetItemTags() + + if (myProfile.myProfile?.id === item.id) { + return null + } + + const isConnected = item.relations?.some( + (r) => + r.type === item.layer?.itemType.cta_relation && + r.related_items_id === myProfile.myProfile?.id, + ) + + if (!item.layer?.itemType.show_cta_button) { + return null + } + + if (isConnected) { + return

✅ Connected

+ } + + const tags = getItemTags(item) + return ( + + ) +} diff --git a/lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/DeleteModal.tsx b/lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/DeleteModal.tsx new file mode 100644 index 00000000..c721ba84 --- /dev/null +++ b/lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/DeleteModal.tsx @@ -0,0 +1,37 @@ +import DialogModal from '#components/Templates/DialogModal' + +import type { Item } from '#types/Item' + +interface DeleteModalProps { + item: Item + isOpen: boolean + onClose: () => void + onConfirm: (e: React.MouseEvent) => void +} + +export function DeleteModal({ item, isOpen, onClose, onConfirm }: DeleteModalProps) { + const handleConfirm = (e: React.MouseEvent) => { + onConfirm(e) + onClose() + } + + return ( + +
e.stopPropagation()}> + + Do you want to delete {item.name}? + +
+
+ + +
+
+
+
+ ) +} diff --git a/lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/EditMenu.tsx b/lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/EditMenu.tsx new file mode 100644 index 00000000..ade02db1 --- /dev/null +++ b/lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/EditMenu.tsx @@ -0,0 +1,112 @@ +import EllipsisVerticalIcon from '@heroicons/react/16/solid/EllipsisVerticalIcon' +import PencilIcon from '@heroicons/react/24/solid/PencilIcon' +import TrashIcon from '@heroicons/react/24/solid/TrashIcon' +import SVG from 'react-inlinesvg' +import { useNavigate } from 'react-router-dom' + +import TargetDotSVG from '#assets/targetDot.svg' +import { useHasUserPermission } from '#components/Map/hooks/usePermissions' + +import type { Item } from '#types/Item' +import type { ItemsApi } from '#types/ItemsApi' + +interface EditMenuProps { + item: Item + api?: ItemsApi + editCallback?: (e: React.MouseEvent) => void + deleteCallback?: (e: React.MouseEvent) => void + setPositionCallback?: () => void + loading?: boolean + hideMenu?: boolean + big?: boolean + onDeleteModalOpen: () => void +} + +export function EditMenu({ + item, + api, + editCallback, + deleteCallback, + setPositionCallback, + loading = false, + hideMenu = false, + big = false, + onDeleteModalOpen, +}: EditMenuProps) { + const hasUserPermission = useHasUserPermission() + const navigate = useNavigate() + + const params = new URLSearchParams(window.location.search) + + const handleDeleteClick = (event: React.MouseEvent) => { + onDeleteModalOpen() + event.stopPropagation() + } + + if (hideMenu) return null + + const hasDeletePermission = + api?.deleteItem && api.collectionName && hasUserPermission(api.collectionName, 'delete', item) + const hasUpdatePermission = + api?.updateItem && api.collectionName && hasUserPermission(api.collectionName, 'update', item) + + if (!hasDeletePermission && !hasUpdatePermission) return null + + return ( +
e.stopPropagation()} className={`${big ? 'tw:mt-5' : 'tw:mt-1'}`}> +
+ + +
+
+ ) +} diff --git a/lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/ItemAvatar.tsx b/lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/ItemAvatar.tsx new file mode 100644 index 00000000..90fa7f07 --- /dev/null +++ b/lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/ItemAvatar.tsx @@ -0,0 +1,73 @@ +import { QrCodeIcon } from '@heroicons/react/24/solid' +import { useState } from 'react' + +import { useAppState } from '#components/AppShell/hooks/useAppState' + +import type { Item } from '#types/Item' + +interface ItemAvatarProps { + item: Item + big?: boolean + extraLarge?: boolean + showQrButton?: boolean + onQrClick?: () => void +} + +export function ItemAvatar({ + item, + big = false, + extraLarge = false, + showQrButton = false, + onQrClick, +}: ItemAvatarProps) { + const appState = useAppState() + const [imageLoaded, setImageLoaded] = useState(false) + + const imageSize = extraLarge ? 320 : 160 + const avatar = + (item.image && + appState.assetsApi.url + item.image + `?width=${imageSize}&height=${imageSize}`) ?? + item.image_external + + const hasAvatar = !!avatar + + // If no avatar but QR button should be shown, show only the QR button + if (!hasAvatar && showQrButton) { + return ( + + ) + } + + if (!hasAvatar) return null + + const avatarSize = extraLarge ? 'tw:w-32' : big ? 'tw:w-16' : 'tw:w-10' + + return ( +
+
+ {(item.name setImageLoaded(true)} + onError={() => setImageLoaded(false)} + style={{ display: imageLoaded ? 'block' : 'none' }} + /> + {!imageLoaded &&
} +
+ {showQrButton && ( + + )} +
+ ) +} diff --git a/lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/ItemTitle.tsx b/lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/ItemTitle.tsx new file mode 100644 index 00000000..713f3373 --- /dev/null +++ b/lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/ItemTitle.tsx @@ -0,0 +1,132 @@ +import { MapPinIcon } from '@heroicons/react/24/solid' +import { useEffect, useRef, useState } from 'react' + +import { useGeoDistance } from '#components/Map/hooks/useGeoDistance' +import { useReverseGeocode } from '#components/Map/hooks/useReverseGeocode' + +import { useFormatDistance } from './hooks' + +import type { Item } from '#types/Item' + +interface ItemTitleProps { + item: Item + big?: boolean + truncateSubname?: boolean + subtitleMode?: 'address' | 'custom' | 'none' + hasAvatar?: boolean +} + +export function ItemTitle({ + item, + big = false, + truncateSubname = true, + subtitleMode = 'address', + hasAvatar = false, +}: ItemTitleProps) { + const { distance } = useGeoDistance(item.position ?? undefined) + const { formatDistance } = useFormatDistance() + const titleRef = useRef(null) + const containerRef = useRef(null) + const [fontSize, setFontSize] = useState('tw:text-xl') + + const { address } = useReverseGeocode( + item.position?.coordinates as [number, number] | undefined, + subtitleMode === 'address', + 'municipality', + ) + + const title = item.name ?? item.layer?.item_default_name + const subtitle = item.subname + + useEffect(() => { + if (!containerRef.current || !title) { + return + } + + const calculateFontSize = () => { + const container = containerRef.current + if (!container) return + + const containerWidth = container.offsetWidth + + // Create temporary element to measure text width + const measureElement = document.createElement('span') + measureElement.style.position = 'absolute' + measureElement.style.visibility = 'hidden' + measureElement.style.whiteSpace = 'nowrap' + measureElement.style.fontWeight = '700' // font-bold + measureElement.textContent = title + document.body.appendChild(measureElement) + + // Measure at different font sizes - include larger sizes only if big is true + const fontSizes = big + ? [ + { class: 'tw:text-2xl', pixels: 24 }, + { class: 'tw:text-xl', pixels: 20 }, + { class: 'tw:text-lg', pixels: 18 }, + ] + : [ + { class: 'tw:text-xl', pixels: 20 }, + { class: 'tw:text-lg', pixels: 18 }, + ] + + let selectedSize = 'tw:text-lg' + + for (const size of fontSizes) { + measureElement.style.fontSize = `${size.pixels}px` + const textWidth = measureElement.offsetWidth + + if (textWidth <= containerWidth) { + selectedSize = size.class + break + } + } + + document.body.removeChild(measureElement) + setFontSize(selectedSize) + } + + // Initial calculation + calculateFontSize() + + // Watch for container size changes + const resizeObserver = new ResizeObserver(calculateFontSize) + resizeObserver.observe(containerRef.current) + + return () => { + resizeObserver.disconnect() + } + }, [title, big]) + + return ( +
+
+ {title} +
+ {subtitleMode === 'address' && address && ( +
+ + + {address} + {distance && distance >= 0.1 ? ` (${formatDistance(distance) ?? ''})` : ''} + +
+ )} + {subtitleMode === 'custom' && subtitle && ( +
+ {subtitle} +
+ )} +
+ ) +} diff --git a/lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/QRModal.tsx b/lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/QRModal.tsx new file mode 100644 index 00000000..66f93d12 --- /dev/null +++ b/lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/QRModal.tsx @@ -0,0 +1,44 @@ +import QRCode from 'react-qr-code' + +import DialogModal from '#components/Templates/DialogModal' + +import { useShareLogic } from './hooks' +import { ItemAvatar } from './ItemAvatar' +import { ShareButton } from './ShareButton' + +import type { Item } from '#types/Item' + +interface QRModalProps { + item: Item + isOpen: boolean + onClose: () => void +} + +export function QRModal({ item, isOpen, onClose }: QRModalProps) { + const { inviteLink } = useShareLogic(item) + + return ( + +
e.stopPropagation()} className='tw:text-center tw:p-4'> +

Share your Profile to expand your Network!

+ +
+ +
+ +
+
+ +
+ {inviteLink} + +
+
+
+ ) +} diff --git a/lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/ShareButton.tsx b/lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/ShareButton.tsx new file mode 100644 index 00000000..b1605066 --- /dev/null +++ b/lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/ShareButton.tsx @@ -0,0 +1,168 @@ +import { ShareIcon } from '@heroicons/react/24/solid' +import { useRef } from 'react' + +import ChevronSVG from '#assets/chevron.svg' +import ClipboardSVG from '#assets/share/clipboard.svg' +import FacebookSVG from '#assets/share/facebook.svg' +import LinkedinSVG from '#assets/share/linkedin.svg' +import TelegramSVG from '#assets/share/telegram.svg' +import TwitterSVG from '#assets/share/twitter.svg' +import WhatsappSVG from '#assets/share/whatsapp.svg' +import XingSVG from '#assets/share/xing.svg' + +import { useShareLogic } from './hooks' + +import type { Item } from '#types/Item' +import type { PlatformConfig, SharePlatformConfigs } from './types' + +interface ShareButtonProps { + item: Item + dropdownDirection?: 'up' | 'down' +} + +export function ShareButton({ item, dropdownDirection = 'down' }: ShareButtonProps) { + const { shareUrl, shareTitle, copyLink, getShareUrl } = useShareLogic(item) + const detailsRef = useRef(null) + + const closeDropdown = () => { + if (detailsRef.current) { + detailsRef.current.open = false + } + } + + const handleCopyLink = () => { + copyLink() + closeDropdown() + } + + const canUseNativeShare = + typeof navigator !== 'undefined' && typeof navigator.share !== 'undefined' + + const handleNativeShare = () => { + void navigator + .share({ + title: shareTitle, + url: shareUrl, + }) + .then(closeDropdown) + .catch(() => { + // User cancelled or error occurred - ignore + }) + } + + const platformConfigs: SharePlatformConfigs = { + facebook: { + shareUrl: 'https://www.facebook.com/sharer/sharer.php?u={url}', + icon: Facebook, + label: 'Facebook', + bgColor: '#3b5998', + }, + twitter: { + shareUrl: 'https://twitter.com/intent/tweet?text={title}:%20{url}', + icon: Twitter, + label: 'Twitter', + bgColor: '#55acee', + }, + linkedin: { + shareUrl: 'http://www.linkedin.com/shareArticle?mini=true&url={url}&title={title}', + icon: Linkedin, + label: 'LinkedIn', + bgColor: '#4875b4', + }, + whatsapp: { + shareUrl: 'https://api.whatsapp.com/send?text={title}%20{url}', + icon: Whatsapp, + label: 'WhatsApp', + bgColor: '#25D366', + }, + telegram: { + shareUrl: 'https://t.me/share/url?url={url}&text={title}', + icon: Telegram, + label: 'Telegram', + bgColor: '#0088cc', + }, + xing: { + shareUrl: 'https://www.xing-share.com/app/user?op=share;sc_p=xing-share;url={url}', + icon: Xing, + label: 'Xing', + bgColor: '#026466', + }, + } + + const dropdownClass = dropdownDirection === 'up' ? 'tw:dropdown-top' : '' + + // If native share is available, render a simple button instead of dropdown + if (canUseNativeShare) { + return ( + + ) + } + + // Otherwise, render the dropdown with manual share options + return ( +
+ + + + +
+ ) +} diff --git a/lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/hooks.ts b/lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/hooks.ts new file mode 100644 index 00000000..5d13af9b --- /dev/null +++ b/lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/hooks.ts @@ -0,0 +1,77 @@ +import { toast } from 'react-toastify' + +import type { Item } from '#types/Item' +import type { SharePlatformConfigs } from './types' + +export const useNavigationUrl = (coordinates?: [number, number]) => { + const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) + const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test( + navigator.userAgent, + ) + + const getNavigationUrl = () => { + if (!coordinates) return '' + + const [longitude, latitude] = coordinates + + if (isIOS) { + return `https://maps.apple.com/?daddr=${latitude},${longitude}` + } else if (isMobile) { + return `geo:${latitude},${longitude}` + } else { + return `https://www.google.com/maps/dir/?api=1&destination=${latitude},${longitude}` + } + } + + return { + getNavigationUrl, + isMobile, + isIOS, + } +} + +export const useShareLogic = (item?: Item) => { + const shareUrl = window.location.href + const shareTitle = item?.name ?? 'Utopia Map Item' + const inviteLink = shareUrl + + const copyLink = () => { + navigator.clipboard + .writeText(inviteLink) + .then(() => { + toast.success('Link copied to clipboard') + return null + }) + .catch(() => { + toast.error('Error copying link') + }) + } + + const getShareUrl = ( + platform: keyof SharePlatformConfigs, + platformConfigs: SharePlatformConfigs, + ) => { + // eslint-disable-next-line security/detect-object-injection + const config = platformConfigs[platform] + return config.shareUrl + .replace('{url}', encodeURIComponent(shareUrl)) + .replace('{title}', encodeURIComponent(shareTitle)) + } + + return { + shareUrl, + shareTitle, + inviteLink, + copyLink, + getShareUrl, + } +} + +export const useFormatDistance = () => { + const formatDistance = (dist: number | null): string | null => { + if (!dist) return null + return dist < 10 ? `${dist.toFixed(1)} km` : `${Math.round(dist)} km` + } + + return { formatDistance } +} diff --git a/lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/index.tsx b/lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/index.tsx new file mode 100644 index 00000000..1befab1c --- /dev/null +++ b/lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/index.tsx @@ -0,0 +1,91 @@ +import { useState } from 'react' + +import { useMyProfile } from '#components/Map/hooks/useMyProfile' + +import { ActionButtons } from './ActionButtons' +import { ConnectionStatus } from './ConnectionStatus' +import { DeleteModal } from './DeleteModal' +import { EditMenu } from './EditMenu' +import { ItemAvatar } from './ItemAvatar' +import { ItemTitle } from './ItemTitle' +import { QRModal } from './QRModal' + +import type { HeaderViewProps } from './types' + +export function HeaderView({ + item, + api, + editCallback, + deleteCallback, + setPositionCallback, + loading, + hideMenu = false, + big = false, + truncateSubname = true, + showAddress = true, +}: HeaderViewProps) { + const [modalOpen, setModalOpen] = useState(false) + const [qrModalOpen, setQrModalOpen] = useState(false) + const myProfile = useMyProfile() + + if (!item) return null + + const hasAvatar = !!(item.image ?? item.image_external) + const isMyProfile = myProfile.myProfile?.id === item.id + const showQrButton = big && isMyProfile && (item.layer?.itemType.show_qr_button ?? true) + const subtitleMode = item.layer?.itemType.subtitle_mode ?? (showAddress ? 'address' : 'none') + + return ( + <> +
+
+
+ setQrModalOpen(true)} + /> + +
+
+ setModalOpen(true)} + /> +
+ + {big && ( +
+
+
+ + +
+
+ )} + + setModalOpen(false)} + onConfirm={deleteCallback ?? (() => undefined)} + /> + + setQrModalOpen(false)} /> + + ) +} diff --git a/lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/types.ts b/lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/types.ts new file mode 100644 index 00000000..6f95df4a --- /dev/null +++ b/lib/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView/types.ts @@ -0,0 +1,31 @@ +import type { Item } from '#types/Item' +import type { ItemsApi } from '#types/ItemsApi' + +export interface HeaderViewProps { + item?: Item + api?: ItemsApi + editCallback?: (e: React.MouseEvent) => void + deleteCallback?: (e: React.MouseEvent) => void + setPositionCallback?: () => void + loading?: boolean + hideMenu?: boolean + big?: boolean + truncateSubname?: boolean + showAddress?: boolean +} + +export interface PlatformConfig { + shareUrl: string + icon: JSX.Element + label: string + bgColor: string +} + +export interface SharePlatformConfigs { + facebook: PlatformConfig + twitter: PlatformConfig + linkedin: PlatformConfig + whatsapp: PlatformConfig + telegram: PlatformConfig + xing: PlatformConfig +} diff --git a/lib/src/Components/Map/Subcomponents/ItemPopupComponents/StartEndView.tsx b/lib/src/Components/Map/Subcomponents/ItemPopupComponents/StartEndView.tsx index 0855d2c2..7402053d 100644 --- a/lib/src/Components/Map/Subcomponents/ItemPopupComponents/StartEndView.tsx +++ b/lib/src/Components/Map/Subcomponents/ItemPopupComponents/StartEndView.tsx @@ -8,25 +8,19 @@ import type { Item } from '#types/Item' */ export const StartEndView = ({ item }: { item?: Item }) => { return ( -
-
- -