fixing hash tag issue

This commit is contained in:
Anton 2023-09-14 12:10:56 +02:00
parent 8fd1f6e0a6
commit 60427cb3d7
4 changed files with 635 additions and 562 deletions

File diff suppressed because it is too large Load Diff

Before

Width:  |  Height:  |  Size: 98 KiB

After

Width:  |  Height:  |  Size: 100 KiB

View File

@ -49,8 +49,8 @@ export function ItemFormPopup(props: ItemFormPopupProps) {
setSpinner(true);
formItem.text.toLocaleLowerCase().match(hashTagRegex)?.map(tag=> {
if (!tags.find((t) => t.id === tag.slice(1))) {
addTag({id: tag.slice(1), color: randomColor()})
if (!tags.find((t) => t.id.toLocaleLowerCase() === tag.slice(1).toLocaleLowerCase())) {
addTag({id: tag.slice(1).toLocaleLowerCase(), color: randomColor()})
}
});

View File

@ -12,29 +12,11 @@ import { useEffect, useRef } from 'react';
export const TextView = ({ item }: { item?: Item }) => {
const tags = useTags();
const addTag = useAddTag();
const groupRef = useRef(null);
const addFilterTag = useAddFilterTag();
const map = useMap();
let replacedText;
// use init-Ref to prevent react18 from calling useEffect twice
const init = useRef(false)
useEffect(() => {
if (!init.current) {
item?.text.toLocaleLowerCase().match(hashTagRegex)?.map(tag=> {
if (!tags.find((t) => t.id === tag.slice(1))) {
addTag({id: tag.slice(1), color: randomColor()})
}
});
init.current = true;
}
}, [])
if (item && item.text) replacedText = fixUrls(item.text);

View File

@ -30,11 +30,11 @@ function useTagsManager(initialTags: Tag[]): {
switch (action.type) {
case "ADD":
const exist = state.find((tag) =>
tag.id === action.tag.id ? true : false
tag.id.toLocaleLowerCase() === action.tag.id.toLocaleLowerCase() ? true : false
);
if (!exist) return [
...state,
{...action.tag, id: action.tag.id}
{...action.tag, id: action.tag.id.toLocaleLowerCase()}
];
else return state;
@ -71,7 +71,7 @@ function useTagsManager(initialTags: Tag[]): {
tag,
});
if (!tags.some((t) => t.id === tag.id)) {
if (!tags.some((t) => t.id.toLocaleLowerCase() === tag.id.toLocaleLowerCase())) {
api?.createItem && api.createItem(tag);
}
};