fix: handle empty fetched releases and update locale usage in plugin item

This commit is contained in:
twwu 2024-11-07 16:06:08 +08:00
parent 65285965b6
commit de24d9c145
3 changed files with 9 additions and 14 deletions

View File

@ -57,6 +57,8 @@ const Action: FC<Props> = ({
const handleFetchNewVersion = async () => {
try {
const fetchedReleases = await fetchReleases(author, pluginName)
if (fetchedReleases.length === 0)
return
const versions = fetchedReleases.map(release => release.tag_name)
const latestVersion = getLatestVersion(versions)
if (compareVersion(latestVersion, version) === 1) {

View File

@ -1,7 +1,6 @@
'use client'
import type { FC } from 'react'
import React, { useMemo } from 'react'
import { useContext } from 'use-context-selector'
import {
RiArrowRightUpLine,
RiBugLine,
@ -20,8 +19,8 @@ import OrgInfo from '../card/base/org-info'
import Title from '../card/base/title'
import Action from './action'
import cn from '@/utils/classnames'
import I18n from '@/context/i18n'
import { API_PREFIX, MARKETPLACE_URL_PREFIX } from '@/config'
import { useLanguage } from '../../header/account-setting/model-provider-page/hooks'
type Props = {
className?: string
@ -32,7 +31,7 @@ const PluginItem: FC<Props> = ({
className,
plugin,
}) => {
const { locale } = useContext(I18n)
const locale = useLanguage()
const { t } = useTranslation()
const currentPluginDetail = usePluginPageContext(v => v.currentPluginDetail)
const setCurrentPluginDetail = usePluginPageContext(v => v.setCurrentPluginDetail)
@ -52,10 +51,6 @@ const PluginItem: FC<Props> = ({
const orgName = useMemo(() => {
return [PluginSource.github, PluginSource.marketplace].includes(source) ? author : ''
}, [source, author])
const tLocale = useMemo(() => {
return locale.replace('-', '_')
}, [locale])
return (
<div
className={cn(
@ -80,12 +75,12 @@ const PluginItem: FC<Props> = ({
</div>
<div className="ml-3 w-0 grow">
<div className="flex items-center h-5">
<Title title={label[tLocale]} />
<Title title={label[locale]} />
{verified && <RiVerifiedBadgeLine className="shrink-0 ml-0.5 w-4 h-4 text-text-accent" />}
<Badge className='ml-1' text={plugin.version} />
</div>
<div className='flex items-center justify-between'>
<Description text={description[tLocale]} descriptionLineRows={1}></Description>
<Description text={description[locale]} descriptionLineRows={1}></Description>
<div onClick={e => e.stopPropagation()}>
<Action
installationId={installation_id}

View File

@ -2,6 +2,7 @@ import React, { useState } from 'react'
import CategoriesFilter from './category-filter'
import TagFilter from './tag-filter'
import SearchBox from './search-box'
import { usePluginPageContext } from '../context'
export type FilterState = {
categories: string[]
@ -14,11 +15,8 @@ type FilterManagementProps = {
}
const FilterManagement: React.FC<FilterManagementProps> = ({ onFilterChange }) => {
const [filters, setFilters] = useState<FilterState>({
categories: [],
tags: [],
searchQuery: '',
})
const initFilters = usePluginPageContext(v => v.filters) as FilterState
const [filters, setFilters] = useState<FilterState>(initFilters)
const updateFilters = (newFilters: Partial<FilterState>) => {
const updatedFilters = { ...filters, ...newFilters }