fix: install handle of list refresh

pull/12372/head
JzoNg 2 years ago
parent 56f573ecfb
commit ac42ba880a

@ -4,8 +4,6 @@ import React from 'react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import Card from '../../card' import Card from '../../card'
import Button from '@/app/components/base/button' import Button from '@/app/components/base/button'
import { useUpdateModelProviders } from '@/app/components/header/account-setting/model-provider-page/hooks'
import { PluginType } from '../../types'
import type { Plugin, PluginDeclaration, PluginManifestInMarket } from '../../types' import type { Plugin, PluginDeclaration, PluginManifestInMarket } from '../../types'
import { pluginManifestInMarketToPluginProps, pluginManifestToCardPluginProps } from '../utils' import { pluginManifestInMarketToPluginProps, pluginManifestToCardPluginProps } from '../utils'
import Badge, { BadgeState } from '@/app/components/base/badge/index' import Badge, { BadgeState } from '@/app/components/base/badge/index'
@ -26,12 +24,9 @@ const Installed: FC<Props> = ({
onCancel, onCancel,
}) => { }) => {
const { t } = useTranslation() const { t } = useTranslation()
const updateModelProviders = useUpdateModelProviders()
const handleClose = () => { const handleClose = () => {
onCancel() onCancel()
if (payload?.category === PluginType.model)
updateModelProviders()
} }
return ( return (
<> <>

@ -7,7 +7,7 @@ import type { InstallState } from '@/app/components/plugins/types'
import { useGitHubReleases } from '../hooks' import { useGitHubReleases } from '../hooks'
import { convertRepoToUrl, parseGitHubUrl } from '../utils' import { convertRepoToUrl, parseGitHubUrl } from '../utils'
import type { PluginDeclaration, UpdateFromGitHubPayload } from '../../types' import type { PluginDeclaration, UpdateFromGitHubPayload } from '../../types'
import { InstallStepFromGitHub } from '../../types' import { InstallStepFromGitHub, PluginType } from '../../types'
import Toast from '@/app/components/base/toast' import Toast from '@/app/components/base/toast'
import SetURL from './steps/setURL' import SetURL from './steps/setURL'
import SelectPackage from './steps/selectPackage' import SelectPackage from './steps/selectPackage'
@ -15,6 +15,8 @@ import Installed from '../base/installed'
import Loaded from './steps/loaded' import Loaded from './steps/loaded'
import useGetIcon from '@/app/components/plugins/install-plugin/base/use-get-icon' import useGetIcon from '@/app/components/plugins/install-plugin/base/use-get-icon'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { useUpdateModelProviders } from '@/app/components/header/account-setting/model-provider-page/hooks'
import { useInvalidateAllToolProviders } from '@/service/use-tools'
const i18nPrefix = 'plugin.installFromGitHub' const i18nPrefix = 'plugin.installFromGitHub'
@ -28,6 +30,8 @@ const InstallFromGitHub: React.FC<InstallFromGitHubProps> = ({ updatePayload, on
const { t } = useTranslation() const { t } = useTranslation()
const { getIconUrl } = useGetIcon() const { getIconUrl } = useGetIcon()
const { fetchReleases } = useGitHubReleases() const { fetchReleases } = useGitHubReleases()
const updateModelProviders = useUpdateModelProviders()
const invalidateAllToolProviders = useInvalidateAllToolProviders()
const [state, setState] = useState<InstallState>({ const [state, setState] = useState<InstallState>({
step: updatePayload ? InstallStepFromGitHub.selectPackage : InstallStepFromGitHub.setUrl, step: updatePayload ? InstallStepFromGitHub.selectPackage : InstallStepFromGitHub.setUrl,
repoUrl: updatePayload?.originalPackageInfo?.repo repoUrl: updatePayload?.originalPackageInfo?.repo
@ -63,7 +67,7 @@ const InstallFromGitHub: React.FC<InstallFromGitHubProps> = ({ updatePayload, on
return t(`${i18nPrefix}.installFailed`) return t(`${i18nPrefix}.installFailed`)
return updatePayload ? t(`${i18nPrefix}.updatePlugin`) : t(`${i18nPrefix}.installPlugin`) return updatePayload ? t(`${i18nPrefix}.updatePlugin`) : t(`${i18nPrefix}.installPlugin`)
}, [state.step]) }, [state.step, t, updatePayload])
const handleUrlSubmit = async () => { const handleUrlSubmit = async () => {
const { isValid, owner, repo } = parseGitHubUrl(state.repoUrl) const { isValid, owner, repo } = parseGitHubUrl(state.repoUrl)
@ -111,8 +115,14 @@ const InstallFromGitHub: React.FC<InstallFromGitHubProps> = ({ updatePayload, on
const handleInstalled = useCallback(() => { const handleInstalled = useCallback(() => {
setState(prevState => ({ ...prevState, step: InstallStepFromGitHub.installed })) setState(prevState => ({ ...prevState, step: InstallStepFromGitHub.installed }))
if (!manifest)
return
if (PluginType.model.includes(manifest.category))
updateModelProviders()
if (PluginType.tool.includes(manifest.category))
invalidateAllToolProviders()
onSuccess() onSuccess()
}, [onSuccess]) }, [invalidateAllToolProviders, manifest, onSuccess, updateModelProviders])
const handleFailed = useCallback((errorMsg?: string) => { const handleFailed = useCallback((errorMsg?: string) => {
setState(prevState => ({ ...prevState, step: InstallStepFromGitHub.installFailed })) setState(prevState => ({ ...prevState, step: InstallStepFromGitHub.installFailed }))
@ -142,7 +152,7 @@ const InstallFromGitHub: React.FC<InstallFromGitHubProps> = ({ updatePayload, on
closable closable
> >
<div className='flex pt-6 pl-6 pb-3 pr-14 items-start gap-2 self-stretch'> <div className='flex pt-6 pl-6 pb-3 pr-14 items-start gap-2 self-stretch'>
<div className='flex flex-col items-start gap-1 flex-grow'> <div className='flex flex-col items-start gap-1 grow'>
<div className='self-stretch text-text-primary title-2xl-semi-bold'> <div className='self-stretch text-text-primary title-2xl-semi-bold'>
{getTitle()} {getTitle()}
</div> </div>

@ -2,11 +2,12 @@
import type { FC } from 'react' import type { FC } from 'react'
import React, { useCallback } from 'react' import React, { useCallback } from 'react'
import type { PluginDeclaration } from '../../types' import type { PluginDeclaration } from '../../types'
import { InstallStep } from '../../types' import { InstallStep, PluginType } from '../../types'
import Install from './steps/install' import Install from './steps/install'
import Installed from '../base/installed' import Installed from '../base/installed'
import { useInvalidateInstalledPluginList } from '@/service/use-plugins' import { useInvalidateInstalledPluginList } from '@/service/use-plugins'
import { useUpdateModelProviders } from '@/app/components/header/account-setting/model-provider-page/hooks'
import { useInvalidateAllToolProviders } from '@/service/use-tools'
type Props = { type Props = {
step: InstallStep step: InstallStep
onStepChange: (step: InstallStep) => void, onStepChange: (step: InstallStep) => void,
@ -27,11 +28,19 @@ const ReadyToInstall: FC<Props> = ({
onError, onError,
}) => { }) => {
const invalidateInstalledPluginList = useInvalidateInstalledPluginList() const invalidateInstalledPluginList = useInvalidateInstalledPluginList()
const updateModelProviders = useUpdateModelProviders()
const invalidateAllToolProviders = useInvalidateAllToolProviders()
const handleInstalled = useCallback(() => { const handleInstalled = useCallback(() => {
invalidateInstalledPluginList()
onStepChange(InstallStep.installed) onStepChange(InstallStep.installed)
}, [invalidateInstalledPluginList, onStepChange]) invalidateInstalledPluginList()
if (!manifest)
return
if (PluginType.model.includes(manifest.category))
updateModelProviders()
if (PluginType.tool.includes(manifest.category))
invalidateAllToolProviders()
}, [invalidateAllToolProviders, invalidateInstalledPluginList, manifest, onStepChange, updateModelProviders])
const handleFailed = useCallback((errorMsg?: string) => { const handleFailed = useCallback((errorMsg?: string) => {
onStepChange(InstallStep.installFailed) onStepChange(InstallStep.installFailed)

@ -3,10 +3,13 @@
import React, { useCallback, useState } from 'react' import React, { useCallback, useState } from 'react'
import Modal from '@/app/components/base/modal' import Modal from '@/app/components/base/modal'
import type { Plugin, PluginManifestInMarket } from '../../types' import type { Plugin, PluginManifestInMarket } from '../../types'
import { InstallStep } from '../../types' import { InstallStep, PluginType } from '../../types'
import Install from './steps/install' import Install from './steps/install'
import Installed from '../base/installed' import Installed from '../base/installed'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { useUpdateModelProviders } from '@/app/components/header/account-setting/model-provider-page/hooks'
import { useInvalidateInstalledPluginList } from '@/service/use-plugins'
import { useInvalidateAllToolProviders } from '@/service/use-tools'
const i18nPrefix = 'plugin.installModal' const i18nPrefix = 'plugin.installModal'
@ -27,7 +30,9 @@ const InstallFromMarketplace: React.FC<InstallFromMarketplaceProps> = ({
// readyToInstall -> check installed -> installed/failed // readyToInstall -> check installed -> installed/failed
const [step, setStep] = useState<InstallStep>(InstallStep.readyToInstall) const [step, setStep] = useState<InstallStep>(InstallStep.readyToInstall)
const [errorMsg, setErrorMsg] = useState<string | null>(null) const [errorMsg, setErrorMsg] = useState<string | null>(null)
const updateModelProviders = useUpdateModelProviders()
const invalidateAllToolProviders = useInvalidateAllToolProviders()
const invalidateInstalledPluginList = useInvalidateInstalledPluginList()
// TODO: check installed in beta version. // TODO: check installed in beta version.
const getTitle = useCallback(() => { const getTitle = useCallback(() => {
@ -40,7 +45,12 @@ const InstallFromMarketplace: React.FC<InstallFromMarketplaceProps> = ({
const handleInstalled = useCallback(() => { const handleInstalled = useCallback(() => {
setStep(InstallStep.installed) setStep(InstallStep.installed)
}, []) invalidateInstalledPluginList()
if (PluginType.model.includes(manifest.category))
updateModelProviders()
if (PluginType.tool.includes(manifest.category))
invalidateAllToolProviders()
}, [invalidateAllToolProviders, invalidateInstalledPluginList, manifest.category, updateModelProviders])
const handleFailed = useCallback((errorMsg?: string) => { const handleFailed = useCallback((errorMsg?: string) => {
setStep(InstallStep.installFailed) setStep(InstallStep.installFailed)

@ -31,6 +31,7 @@ import { uninstallPlugin } from '@/service/plugins'
import { useGetLanguage } from '@/context/i18n' import { useGetLanguage } from '@/context/i18n'
import { useModalContext } from '@/context/modal-context' import { useModalContext } from '@/context/modal-context'
import { useProviderContext } from '@/context/provider-context' import { useProviderContext } from '@/context/provider-context'
import { useInvalidateAllToolProviders } from '@/service/use-tools'
import { API_PREFIX, MARKETPLACE_URL_PREFIX } from '@/config' import { API_PREFIX, MARKETPLACE_URL_PREFIX } from '@/config'
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
@ -52,6 +53,7 @@ const DetailHeader = ({
const { checkForUpdates, fetchReleases } = useGitHubReleases() const { checkForUpdates, fetchReleases } = useGitHubReleases()
const { setShowUpdatePluginModal } = useModalContext() const { setShowUpdatePluginModal } = useModalContext()
const { refreshModelProviders } = useProviderContext() const { refreshModelProviders } = useProviderContext()
const invalidateAllToolProviders = useInvalidateAllToolProviders()
const { const {
installation_id, installation_id,
@ -150,10 +152,12 @@ const DetailHeader = ({
if (res.success) { if (res.success) {
hideDeleteConfirm() hideDeleteConfirm()
onUpdate(true) onUpdate(true)
if (category === PluginType.model) if (PluginType.model.includes(category))
refreshModelProviders() refreshModelProviders()
if (PluginType.tool.includes(category))
invalidateAllToolProviders()
} }
}, [showDeleting, installation_id, hideDeleting, hideDeleteConfirm, onUpdate, category, refreshModelProviders]) }, [showDeleting, installation_id, hideDeleting, hideDeleteConfirm, onUpdate, category, refreshModelProviders, invalidateAllToolProviders])
// #plugin TODO# used in apps // #plugin TODO# used in apps
// const usedInApps = 3 // const usedInApps = 3

@ -22,6 +22,7 @@ import cn from '@/utils/classnames'
import { API_PREFIX, MARKETPLACE_URL_PREFIX } from '@/config' import { API_PREFIX, MARKETPLACE_URL_PREFIX } from '@/config'
import { useLanguage } from '../../header/account-setting/model-provider-page/hooks' import { useLanguage } from '../../header/account-setting/model-provider-page/hooks'
import { useInvalidateInstalledPluginList } from '@/service/use-plugins' import { useInvalidateInstalledPluginList } from '@/service/use-plugins'
import { useInvalidateAllToolProviders } from '@/service/use-tools'
import { useCategories } from '../hooks' import { useCategories } from '../hooks'
import { useProviderContext } from '@/context/provider-context' import { useProviderContext } from '@/context/provider-context'
@ -40,6 +41,7 @@ const PluginItem: FC<Props> = ({
const currentPluginID = usePluginPageContext(v => v.currentPluginID) const currentPluginID = usePluginPageContext(v => v.currentPluginID)
const setCurrentPluginID = usePluginPageContext(v => v.setCurrentPluginID) const setCurrentPluginID = usePluginPageContext(v => v.setCurrentPluginID)
const invalidateInstalledPluginList = useInvalidateInstalledPluginList() const invalidateInstalledPluginList = useInvalidateInstalledPluginList()
const invalidateAllToolProviders = useInvalidateAllToolProviders()
const { refreshModelProviders } = useProviderContext() const { refreshModelProviders } = useProviderContext()
const { const {
@ -59,8 +61,10 @@ const PluginItem: FC<Props> = ({
const handleDelete = () => { const handleDelete = () => {
invalidateInstalledPluginList() invalidateInstalledPluginList()
if (category === PluginType.model) if (PluginType.model.includes(category))
refreshModelProviders() refreshModelProviders()
if (PluginType.tool.includes(category))
invalidateAllToolProviders()
} }
return ( return (
<div <div

@ -21,6 +21,10 @@ export const useAllToolProviders = () => {
}) })
} }
export const useInvalidateAllToolProviders = () => {
return useInvalid(useAllToolProvidersKey)
}
const useAllBuiltInToolsKey = [NAME_SPACE, 'builtIn'] const useAllBuiltInToolsKey = [NAME_SPACE, 'builtIn']
export const useAllBuiltInTools = () => { export const useAllBuiltInTools = () => {
return useQuery<ToolWithProvider[]>({ return useQuery<ToolWithProvider[]>({

Loading…
Cancel
Save