feat: support scroll into letter

pull/12372/head
Joel 1 year ago
parent 5bba422c0b
commit cab8c6c5a7

@ -49,6 +49,7 @@ export type Collection = {
allow_delete: boolean allow_delete: boolean
labels: string[] labels: string[]
plugin_id?: string plugin_id?: string
letter?: string
} }
export type ToolParameter = { export type ToolParameter = {

@ -6,31 +6,53 @@ import type { BlockEnum } from '../../../types'
import type { ToolDefaultValue } from '../../types' import type { ToolDefaultValue } from '../../types'
import Tool from '../tool' import Tool from '../tool'
import { ViewType } from '../../view-type-select' import { ViewType } from '../../view-type-select'
import { useMemo } from 'react'
type Props = { type Props = {
payload: ToolWithProvider[] payload: ToolWithProvider[]
isShowLetterIndex: boolean isShowLetterIndex: boolean
hasSearchText: boolean hasSearchText: boolean
onSelect: (type: BlockEnum, tool?: ToolDefaultValue) => void onSelect: (type: BlockEnum, tool?: ToolDefaultValue) => void
letters: string[]
toolRefs: any
} }
const ToolViewFlatView: FC<Props> = ({ const ToolViewFlatView: FC<Props> = ({
letters,
payload, payload,
isShowLetterIndex, isShowLetterIndex,
hasSearchText, hasSearchText,
onSelect, onSelect,
toolRefs,
}) => { }) => {
const firstLetterToolIds = useMemo(() => {
const res: Record<string, string> = {}
letters.forEach((letter) => {
const firstToolId = payload.find(tool => tool.letter === letter)?.id
if (firstToolId)
res[firstToolId] = letter
})
return res
}, [payload, letters])
return ( return (
<div> <div>
{payload.map(tool => ( {payload.map(tool => (
<Tool <div
key={tool.id} key={tool.id}
ref={(el) => {
const letter = firstLetterToolIds[tool.id]
if (letter)
toolRefs.current[letter] = el
}}
>
<Tool
payload={tool} payload={tool}
viewType={ViewType.flat} viewType={ViewType.flat}
isShowLetterIndex={isShowLetterIndex} isShowLetterIndex={isShowLetterIndex}
hasSearchText={hasSearchText} hasSearchText={hasSearchText}
onSelect={onSelect} onSelect={onSelect}
/> />
</div>
))} ))}
</div> </div>
) )

@ -71,7 +71,12 @@ const Blocks = ({
const result: ToolWithProvider[] = [] const result: ToolWithProvider[] = []
letters.forEach((letter) => { letters.forEach((letter) => {
Object.keys(withLetterAndGroupViewToolsData[letter]).forEach((groupName) => { Object.keys(withLetterAndGroupViewToolsData[letter]).forEach((groupName) => {
result.push(...withLetterAndGroupViewToolsData[letter][groupName]) result.push(...withLetterAndGroupViewToolsData[letter][groupName].map((item) => {
return {
...item,
letter,
}
}))
}) })
}) })
@ -95,6 +100,8 @@ const Blocks = ({
{!!tools.length && ( {!!tools.length && (
isFlatView ? ( isFlatView ? (
<ToolListFlatView <ToolListFlatView
toolRefs={toolRefs}
letters={letters}
payload={listViewToolData} payload={listViewToolData}
isShowLetterIndex={isShowLetterIndex} isShowLetterIndex={isShowLetterIndex}
hasSearchText={hasSearchText} hasSearchText={hasSearchText}

Loading…
Cancel
Save