chore: update the 'Update plugin from GitHub'

This commit is contained in:
Yi
2024-11-06 16:49:16 +08:00
parent 0d08b6cf51
commit 4c0e4e490a
8 changed files with 54 additions and 25 deletions

View File

@ -2,18 +2,19 @@
import React from 'react'
import Button from '@/app/components/base/button'
import type { PluginDeclaration } from '../../../types'
import type { PluginDeclaration, UpdateFromGitHubPayload } from '../../../types'
import Card from '../../../card'
import Badge, { BadgeState } from '@/app/components/base/badge/index'
import { pluginManifestToCardPluginProps } from '../../utils'
import { useTranslation } from 'react-i18next'
import { installPackageFromGitHub } from '@/service/plugins'
import { installPackageFromGitHub, uninstallPlugin } from '@/service/plugins'
import { RiLoader2Line } from '@remixicon/react'
import { usePluginTasksStore } from '@/app/components/plugins/plugin-page/store'
import checkTaskStatus from '../../base/check-task-status'
import { parseGitHubUrl } from '../../utils'
type LoadedProps = {
updatePayload: UpdateFromGitHubPayload
uniqueIdentifier: string
payload: PluginDeclaration
repoUrl: string
@ -27,6 +28,7 @@ type LoadedProps = {
const i18nPrefix = 'plugin.installModal'
const Loaded: React.FC<LoadedProps> = ({
updatePayload,
uniqueIdentifier,
payload,
repoUrl,
@ -54,6 +56,9 @@ const Loaded: React.FC<LoadedProps> = ({
uniqueIdentifier,
)
if (updatePayload && isInstalled)
await uninstallPlugin(updatePayload.originalPackageInfo.id)
if (isInstalled) {
onInstalled()
return
@ -64,10 +69,15 @@ const Loaded: React.FC<LoadedProps> = ({
taskId,
pluginUniqueIdentifier: uniqueIdentifier,
})
onInstalled()
}
catch (e) {
onFailed(e instanceof Error ? e.message : String(e))
if (typeof e === 'string') {
onFailed(e)
return
}
onFailed()
}
finally {
setIsInstalling(false)

View File

@ -41,7 +41,7 @@ const SelectPackage: React.FC<SelectPackageProps> = ({
const { t } = useTranslation()
const isEdit = Boolean(updatePayload)
const [isUploading, setIsUploading] = React.useState(false)
const { handleUpload, error } = useGitHubUpload()
const { handleUpload } = useGitHubUpload()
const handleUploadPackage = async () => {
if (isUploading) return
@ -59,7 +59,6 @@ const SelectPackage: React.FC<SelectPackageProps> = ({
catch (e: any) {
if (e.response?.message)
onFailed(e.response?.message)
else
onFailed(t('plugin.error.uploadFailed'))
}
@ -74,16 +73,15 @@ const SelectPackage: React.FC<SelectPackageProps> = ({
htmlFor='version'
className='flex flex-col justify-center items-start self-stretch text-text-secondary'
>
<span className='system-sm-semibold'>{isEdit ? t('plugin.installFromGitHub.updateVersion')
: t('plugin.installFromGitHub.selectVersion')}
</span>
<span className='system-sm-semibold'>{t('plugin.installFromGitHub.selectVersion')}</span>
</label>
<PortalSelect
value={selectedVersion}
onSelect={onSelectVersion}
items={versions}
installedValue={updatePayload?.originalPackageInfo.version}
placeholder={t('plugin.installFromGitHub.selectVersionPlaceholder') || ''}
popupClassName='w-[432px] z-[1001]'
popupClassName='w-[512px] z-[1001]'
/>
<label
htmlFor='package'
@ -96,7 +94,7 @@ const SelectPackage: React.FC<SelectPackageProps> = ({
onSelect={onSelectPackage}
items={packages}
placeholder={t('plugin.installFromGitHub.selectPackagePlaceholder') || ''}
popupClassName='w-[432px] z-[1001]'
popupClassName='w-[512px] z-[1001]'
/>
<div className='flex justify-end items-center gap-2 self-stretch mt-4'>
{!isEdit