From bd57c87e95d78b052f13cf25d7fab80e55308508 Mon Sep 17 00:00:00 2001 From: Anton Date: Fri, 21 Jul 2023 19:29:13 +0200 Subject: [PATCH] basic textbased #tags --- src/Components/Map/Layer.tsx | 36 +++++++++++----- .../Map/Subcomponents/AddButton.tsx | 5 +-- .../Map/Subcomponents/ItemViewPopup.tsx | 19 +++++--- src/Components/Map/hooks/useTags.tsx | 43 +++++++++++-------- src/Utils/HeighlightTags.ts | 18 ++++++++ src/types.ts | 3 +- 6 files changed, 83 insertions(+), 41 deletions(-) create mode 100644 src/Utils/HeighlightTags.ts diff --git a/src/Components/Map/Layer.tsx b/src/Components/Map/Layer.tsx index c8020454..c8cb7b6a 100644 --- a/src/Components/Map/Layer.tsx +++ b/src/Components/Map/Layer.tsx @@ -15,21 +15,37 @@ export const Layer = (props: LayerProps) => { const tags = useTags(); + console.log(tags); + + + + // create a JS-Map with all Tags const tagMap = new Map(tags?.map(key => [key.id, key])); + console.log(tagMap); + + // returns all tags for passed item const getTags = (item: Item) => { + console.log(item.text); + const regex = /(^|\B)#(?![0-9_]+\b)([a-zA-Z0-9_]{1,30})(\b|\r)/g; + const strings = item.text.match(regex); + console.log(strings); const tags: Tag[] = []; - item.tags && item.tags.forEach(element => { - if (tagMap.has(element)) { tags.push(tagMap.get(element)!) } - }); + strings?.map(tag => { + console.log(tag.slice(1)); + + if (tagMap.has(tag.slice(1))) { tags.push(tagMap.get(tag.slice(1))!) } + }) + console.log(tags); + return tags; }; - + const items = useItems(); const addItem = useAddItem() @@ -46,18 +62,18 @@ export const Layer = (props: LayerProps) => { } }) - props.api?.getItems().then(result => { + props.api?.getItems().then(result => { if (result.data) { result.data.map(item => { if (item.position) { - addItem(({layer: props, api: props.api, ...item})); + addItem(({ layer: props, api: props.api, ...item })); } }); } }) - if(props.api || props.api) { - addLayer(props); - } + if (props.api || props.api) { + addLayer(props); + } }, [props.data, props.api]) @@ -84,7 +100,7 @@ export const Layer = (props: LayerProps) => { } {props.children} {props.itemFormPopup && props.itemFormPopup.layer.name == props.name && - + } ) diff --git a/src/Components/Map/Subcomponents/AddButton.tsx b/src/Components/Map/Subcomponents/AddButton.tsx index 15095840..2599abdb 100644 --- a/src/Components/Map/Subcomponents/AddButton.tsx +++ b/src/Components/Map/Subcomponents/AddButton.tsx @@ -6,10 +6,7 @@ import { useLayers } from '../hooks/useLayers' export default function AddButton({setSelectMode} : {setSelectMode: React.Dispatch>}) { const layers = useLayers(); - console.log(layers); - - - + return (
{item.api && -
-