diff --git a/package-lock.json b/package-lock.json index e21a55e0..b2608d2b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,7 @@ "react-leaflet": "^4.2.1", "react-leaflet-cluster": "^2.1.0", "react-router-dom": "^6.11.2", + "react-string-replace": "^1.1.1", "react-toastify": "^9.1.3", "tributejs": "^5.1.3", "tw-elements": "^1.0.0-beta2" @@ -3837,6 +3838,14 @@ "react-dom": ">=16.8" } }, + "node_modules/react-string-replace": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/react-string-replace/-/react-string-replace-1.1.1.tgz", + "integrity": "sha512-26TUbLzLfHQ5jO5N7y3Mx88eeKo0Ml0UjCQuX4BMfOd/JX+enQqlKpL1CZnmjeBRvQE8TR+ds9j1rqx9CxhKHQ==", + "engines": { + "node": ">=0.12.0" + } + }, "node_modules/react-toastify": { "version": "9.1.3", "resolved": "https://registry.npmjs.org/react-toastify/-/react-toastify-9.1.3.tgz", diff --git a/package.json b/package.json index b4e670e7..4fc57bdb 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "react-leaflet": "^4.2.1", "react-leaflet-cluster": "^2.1.0", "react-router-dom": "^6.11.2", + "react-string-replace": "^1.1.1", "react-toastify": "^9.1.3", "tributejs": "^5.1.3", "tw-elements": "^1.0.0-beta2" diff --git a/src/Components/Map/Layer.tsx b/src/Components/Map/Layer.tsx index cc2f09b6..fb52ed7c 100644 --- a/src/Components/Map/Layer.tsx +++ b/src/Components/Map/Layer.tsx @@ -39,8 +39,6 @@ export const Layer = (props: LayerProps) => { items.filter(item => item.layer?.name === props.name)?.filter(item => filterTags.length == 0 ? item : item.tags?.some(tag => filterTags.some(filterTag => filterTag.id === tag.id)))?.map((place: Item) => { const tags = place.tags; - if(place.name === "docutopia") - console.log(tags); let color1 = "#666"; let color2 = "RGBA(35, 31, 32, 0.2)"; diff --git a/src/Components/Map/Subcomponents/ItemFormPopup.tsx b/src/Components/Map/Subcomponents/ItemFormPopup.tsx index 6ef65285..120a5091 100644 --- a/src/Components/Map/Subcomponents/ItemFormPopup.tsx +++ b/src/Components/Map/Subcomponents/ItemFormPopup.tsx @@ -6,7 +6,7 @@ import { useAddItem, useUpdateItem } from '../hooks/useItems' import { Geometry, LayerProps, Item, ItemsApi } from '../../../types' import { TextAreaInput } from '../../Input/TextAreaInput' import { TextInput } from '../../Input/TextInput' -import { hashTagRegex } from '../../../Utils/HeighlightTags' +import { hashTagRegex } from '../../../Utils/HashTagRegex' import { useAddTag } from '../hooks/useTags' import { randomColor } from '../../../Utils/RandomColor' diff --git a/src/Components/Map/Subcomponents/ItemPopupComponents/TextView.tsx b/src/Components/Map/Subcomponents/ItemPopupComponents/TextView.tsx index ef581209..3e1504f6 100644 --- a/src/Components/Map/Subcomponents/ItemPopupComponents/TextView.tsx +++ b/src/Components/Map/Subcomponents/ItemPopupComponents/TextView.tsx @@ -2,13 +2,39 @@ import * as React from 'react' import { Item } from '../../../../types' import { useTags } from '../../hooks/useTags'; import { replaceURLs } from '../../../../Utils/ReplaceURLs'; -import { heighlightTags } from '../../../../Utils/HeighlightTags'; +import reactStringReplace from 'react-string-replace'; +import { useAddFilterTag, useResetFilterTags } from '../../hooks/useFilter'; +import { hashTagRegex } from '../../../../Utils/HashTagRegex'; export const TextView = ({item} : {item?: Item}) => { - const all_tags = useTags(); + const tags = useTags(); - return ( -
+ const addFilterTag = useAddFilterTag(); + const resetFilterTags = useResetFilterTags(); + + + return( + <> + { + reactStringReplace(item?.text, hashTagRegex, (match, i) => ( + <> + { + + tags.filter(t => t.id.toLowerCase() == match.slice(1).toLowerCase()).map(tag => + { + resetFilterTags(); + addFilterTag(tag); + }}>#{tag.id} + + + ) + } + > + )) + } + > + ) + + - ) } diff --git a/src/Components/Map/hooks/useFilter.tsx b/src/Components/Map/hooks/useFilter.tsx index 2715625f..cee13e13 100644 --- a/src/Components/Map/hooks/useFilter.tsx +++ b/src/Components/Map/hooks/useFilter.tsx @@ -4,7 +4,8 @@ import {Tag} from "../../../types"; type ActionType = | { type: "ADD"; tag: Tag } - | { type: "REMOVE"; id: string }; + | { type: "REMOVE"; id: string } + | { type: "RESET"}; type UseFilterManagerResult = ReturnType