fix: toggle tool

This commit is contained in:
Joel 2024-11-13 15:04:23 +08:00
parent 19dc983d30
commit 89b470d0d5
3 changed files with 18 additions and 32 deletions

View File

@ -1,6 +1,6 @@
'use client'
import type { FC } from 'react'
import React, { useEffect } from 'react'
import React from 'react'
import type { ToolWithProvider } from '../../../types'
import type { BlockEnum } from '../../../types'
import type { ToolDefaultValue } from '../../types'
@ -20,16 +20,6 @@ const ToolViewFlatView: FC<Props> = ({
hasSearchText,
onSelect,
}) => {
const [fold, setFold] = React.useState<boolean>(true)
useEffect(() => {
if (hasSearchText && fold) {
setFold(false)
return
}
if (!hasSearchText && !fold)
setFold(true)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [hasSearchText])
return (
<div>
{payload.map(tool => (
@ -38,8 +28,7 @@ const ToolViewFlatView: FC<Props> = ({
payload={tool}
viewType={ViewType.flat}
isShowLetterIndex={isShowLetterIndex}
isFold={fold}
onFoldChange={setFold}
hasSearchText={hasSearchText}
onSelect={onSelect}
/>
))}

View File

@ -1,6 +1,6 @@
'use client'
import type { FC } from 'react'
import React, { useEffect } from 'react'
import React from 'react'
import type { ToolWithProvider } from '../../../types'
import Tool from '../tool'
import type { BlockEnum } from '../../../types'
@ -20,16 +20,6 @@ const Item: FC<Props> = ({
hasSearchText,
onSelect,
}) => {
const [fold, setFold] = React.useState<boolean>(true)
useEffect(() => {
if (hasSearchText && fold) {
setFold(false)
return
}
if (!hasSearchText && !fold)
setFold(true)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [hasSearchText])
return (
<div>
<div className='flex items-center px-3 h-[22px] text-xs font-medium text-gray-500'>
@ -42,8 +32,7 @@ const Item: FC<Props> = ({
payload={tool}
viewType={ViewType.tree}
isShowLetterIndex={false}
isFold={fold}
onFoldChange={setFold}
hasSearchText={hasSearchText}
onSelect={onSelect}
/>
))}

View File

@ -1,6 +1,6 @@
'use client'
import type { FC } from 'react'
import React, { useMemo } from 'react'
import React, { useEffect, useMemo } from 'react'
import cn from '@/utils/classnames'
import { RiArrowDownSLine, RiArrowRightSLine } from '@remixicon/react'
import { useGetLanguage } from '@/context/i18n'
@ -18,8 +18,7 @@ type Props = {
payload: ToolWithProvider
viewType: ViewType
isShowLetterIndex: boolean
isFold: boolean
onFoldChange: (fold: boolean) => void
hasSearchText: boolean
onSelect: (type: BlockEnum, tool?: ToolDefaultValue) => void
}
@ -28,8 +27,7 @@ const Tool: FC<Props> = ({
payload,
viewType,
isShowLetterIndex,
isFold,
onFoldChange,
hasSearchText,
onSelect,
}) => {
const { t } = useTranslation()
@ -37,6 +35,16 @@ const Tool: FC<Props> = ({
const isFlatView = viewType === ViewType.flat
const actions = payload.tools
const hasAction = true // Now always support actions
const [isFold, setFold] = React.useState<boolean>(true)
useEffect(() => {
if (hasSearchText && isFold) {
setFold(false)
return
}
if (!hasSearchText && !isFold)
setFold(true)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [hasSearchText])
const FoldIcon = isFold ? RiArrowRightSLine : RiArrowDownSLine
@ -63,7 +71,7 @@ const Tool: FC<Props> = ({
className='flex items-center justify-between pl-3 pr-1 w-full rounded-lg hover:bg-gray-50 cursor-pointer select-none'
onClick={() => {
if (hasAction)
onFoldChange(!isFold)
setFold(!isFold)
// Now always support actions
// if (payload.parameters) {