feat: scroll to view and fix action hidden

This commit is contained in:
Joel 2024-10-21 18:21:45 +08:00
parent 8f49572f85
commit 8e9d7a229d
4 changed files with 26 additions and 8 deletions

View File

@ -89,6 +89,7 @@ const AllTools = ({
onSelect={onSelect} onSelect={onSelect}
viewType={activeView} viewType={activeView}
/> />
{/* Plugins from marketplace */}
<PluginList wrapElemRef={wrapElemRef} list={[toolNotion, extensionDallE, modelGPT4] as any} ref={pluginRef} /> <PluginList wrapElemRef={wrapElemRef} list={[toolNotion, extensionDallE, modelGPT4] as any} ref={pluginRef} />
</div> </div>
</div> </div>

View File

@ -1,6 +1,6 @@
'use client' 'use client'
import type { FC } from 'react' import type { FC } from 'react'
import React, { useCallback, useRef, useState } from 'react' import React, { useCallback, useRef } from 'react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { RiMoreFill } from '@remixicon/react' import { RiMoreFill } from '@remixicon/react'
import ActionButton from '@/app/components/base/action-button' import ActionButton from '@/app/components/base/action-button'
@ -13,16 +13,20 @@ import {
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
type Props = { type Props = {
open: boolean
onOpenChange: (v: boolean) => void
} }
const OperationDropdown: FC<Props> = () => { const OperationDropdown: FC<Props> = ({
open,
onOpenChange,
}) => {
const { t } = useTranslation() const { t } = useTranslation()
const [open, doSetOpen] = useState(false)
const openRef = useRef(open) const openRef = useRef(open)
const setOpen = useCallback((v: boolean) => { const setOpen = useCallback((v: boolean) => {
doSetOpen(v) onOpenChange(v)
openRef.current = v openRef.current = v
}, [doSetOpen]) }, [onOpenChange])
const handleTrigger = useCallback(() => { const handleTrigger = useCallback(() => {
setOpen(!openRef.current) setOpen(!openRef.current)

View File

@ -6,6 +6,7 @@ import { useTranslation } from 'react-i18next'
import Action from './action' import Action from './action'
import type { Plugin } from '@/app/components/plugins/types.ts' import type { Plugin } from '@/app/components/plugins/types.ts'
import I18n from '@/context/i18n' import I18n from '@/context/i18n'
import cn from '@/utils/classnames'
import { formatNumber } from '@/utils/format' import { formatNumber } from '@/utils/format'
@ -23,6 +24,7 @@ const Item: FC<Props> = ({
payload, payload,
}) => { }) => {
const { t } = useTranslation() const { t } = useTranslation()
const [open, setOpen] = React.useState(false)
const { locale } = useContext(I18n) const { locale } = useContext(I18n)
return ( return (
@ -42,9 +44,12 @@ const Item: FC<Props> = ({
</div> </div>
</div> </div>
{/* Action */} {/* Action */}
<div className='hidden group-hover/plugin:flex items-center space-x-1 h-4 text-components-button-secondary-accent-text system-xs-medium'> <div className={cn(!open ? 'hidden' : 'flex', 'group-hover/plugin:flex items-center space-x-1 h-4 text-components-button-secondary-accent-text system-xs-medium')}>
<div className='px-1.5'>{t('plugin.installAction')}</div> <div className='px-1.5'>{t('plugin.installAction')}</div>
<Action /> <Action
open={open}
onOpenChange={setOpen}
/>
</div> </div>
</div> </div>

View File

@ -39,17 +39,25 @@ const List = ({
handleScroll, handleScroll,
})) }))
const scrollToView = () => {
if (scrollPosition !== ScrollPosition.belowTheWrap)
return
nextToStickyELemRef.current?.scrollIntoView({ behavior: 'smooth', block: 'start' })
}
return ( return (
<> <>
<div <div
className={cn('sticky z-10 flex h-8 px-4 py-1 text-text-primary system-sm-medium', stickyClassName)} className={cn('sticky z-10 flex h-8 px-4 py-1 text-text-primary system-sm-medium', stickyClassName)}
onClick={scrollToView}
> >
<span>{t('plugin.fromMarketplace')}</span> <span>{t('plugin.fromMarketplace')}</span>
{/* {scrollPosition === ScrollPosition.belowTheWrap && ( {/* {scrollPosition === ScrollPosition.belowTheWrap && (
<RiArrowRightUpLine className='ml-0.5 w-3 h-3' /> <RiArrowRightUpLine className='ml-0.5 w-3 h-3' />
)} */} )} */}
</div> </div>
<div className='p-1 pb-[500px]' ref={nextToStickyELemRef}> <div className='p-1' ref={nextToStickyELemRef}>
{list.map((item, index) => ( {list.map((item, index) => (
<Item <Item
key={index} key={index}