a little linting

This commit is contained in:
mahula 2026-01-24 09:54:24 +01:00
parent 839fc6cd07
commit 0c41cd2d0f

View File

@ -1,7 +1,7 @@
/* eslint-disable react/prop-types */ /* eslint-disable react/prop-types */
/* eslint-disable @typescript-eslint/no-misused-promises */ /* eslint-disable @typescript-eslint/no-misused-promises */
/* eslint-disable @typescript-eslint/no-floating-promises */ /* eslint-disable @typescript-eslint/no-floating-promises */
/* eslint-disable @typescript-eslint/prefer-optional-chain */
/* eslint-disable @typescript-eslint/no-non-null-assertion */ /* eslint-disable @typescript-eslint/no-non-null-assertion */
/* eslint-disable @typescript-eslint/no-unnecessary-condition */ /* eslint-disable @typescript-eslint/no-unnecessary-condition */
import { useCallback, useReducer, createContext, useContext, useState, useRef } from 'react' import { useCallback, useReducer, createContext, useContext, useState, useRef } from 'react'
@ -132,45 +132,38 @@ function useTagsManager(initialTags: Tag[]): {
) )
// Process all items and create missing tags // Process all items and create missing tags
const processItemsTags = useCallback( const processItemsTags = useCallback((items: Item[]) => {
(items: Item[]) => { const currentTags = tagsRef.current
const currentTags = tagsRef.current const newTags: Tag[] = []
const newTags: Tag[] = []
items.forEach((item) => { items.forEach((item) => {
const text = item.text const text = item.text
text?.match(hashTagRegex)?.forEach((tag) => { text?.match(hashTagRegex)?.forEach((tag) => {
const tagName = tag.slice(1) const tagName = tag.slice(1)
const tagNameLower = tagName.toLocaleLowerCase() const tagNameLower = tagName.toLocaleLowerCase()
// Check if tag exists in current tags or already queued // Check if tag exists in current tags or already queued
const existsInTags = currentTags.some( const existsInTags = currentTags.some((t) => t.name.toLocaleLowerCase() === tagNameLower)
(t) => t.name.toLocaleLowerCase() === tagNameLower, const existsInNew = newTags.some((t) => t.name.toLocaleLowerCase() === tagNameLower)
)
const existsInNew = newTags.some(
(t) => t.name.toLocaleLowerCase() === tagNameLower,
)
if (!existsInTags && !existsInNew) { if (!existsInTags && !existsInNew) {
newTags.push({ newTags.push({
id: crypto.randomUUID(), id: crypto.randomUUID(),
name: tagName, name: tagName,
color: randomColor(), color: randomColor(),
}) })
}
})
})
// Add all new tags
newTags.forEach((tag) => {
dispatch({ type: 'ADD', tag })
if (apiRef.current.createItem) {
apiRef.current.createItem(tag)
} }
}) })
}, })
[],
) // Add all new tags
newTags.forEach((tag) => {
dispatch({ type: 'ADD', tag })
if (apiRef.current.createItem) {
apiRef.current.createItem(tag)
}
})
}, [])
return { tags, addTag, setTagApi, setTagData, getItemTags, processItemsTags, allTagsLoaded } return { tags, addTag, setTagApi, setTagData, getItemTags, processItemsTags, allTagsLoaded }
} }