@ -6,36 +6,43 @@ import { useMemoFilterStore } from "@/store/v1";
interface Tag {
key : string ;
text : string ;
amount : number ;
subTags : Tag [ ] ;
}
interface Props {
tag s: string [ ] ;
tag Amount s: [ tag : string , amount : number ] [ ] ;
}
const TagTree = ( { tag s: rawTag s } : Props ) = > {
const TagTree = ( { tag Amount s: rawTag Amount s } : Props ) = > {
const [ tags , setTags ] = useState < Tag [ ] > ( [ ] ) ;
useEffect ( ( ) = > {
const sortedTag s = Array . from ( rawTag s) . sort ( ) ;
const sortedTag Amount s = Array . from ( rawTag Amount s) . sort ( ) ;
const root : Tag = {
key : "" ,
text : "" ,
amount : 0 ,
subTags : [ ] ,
} ;
for ( const tag of sortedTag s) {
const subtags = tag . split ( "/" ) ;
for ( const tag Amount of sortedTag Amount s) {
const subtags = tag Amount[ 0 ] . split ( "/" ) ;
let tempObj = root ;
let tagText = "" ;
for ( let i = 0 ; i < subtags . length ; i ++ ) {
const key = subtags [ i ] ;
let amount : number = 0 ;
if ( i === 0 ) {
tagText += key ;
} else {
tagText += "/" + key ;
}
if ( sortedTagAmounts . some ( ( [ tag , amount ] ) = > tag === tagText && amount > 1 ) ) {
amount = tagAmount [ 1 ] ;
}
let obj = null ;
@ -50,6 +57,7 @@ const TagTree = ({ tags: rawTags }: Props) => {
obj = {
key ,
text : tagText ,
amount : amount ,
subTags : [ ] ,
} ;
tempObj . subTags . push ( obj ) ;
@ -60,7 +68,7 @@ const TagTree = ({ tags: rawTags }: Props) => {
}
setTags ( root . subTags as Tag [ ] ) ;
} , [ rawTag s] ) ;
} , [ rawTag Amount s] ) ;
return (
< div className = "flex flex-col justify-start items-start relative w-full h-auto flex-nowrap gap-2 mt-1" >
@ -111,7 +119,7 @@ const TagItemContainer: React.FC<TagItemContainerProps> = (props: TagItemContain
< HashIcon className = "w-4 h-auto shrink-0 mr-1 text-gray-400 dark:text-gray-500" / >
< / div >
< span className = "truncate cursor-pointer hover:opacity-80" onClick = { handleTagClick } >
{ tag . key }
{ tag . key } { tag . amount > 1 && ` ( ${ tag . amount } ) ` }
< / span >
< / div >
< div className = "flex flex-row justify-end items-center" >