chore: perfect type definition (#1003)

This commit is contained in:
bowen
2023-08-28 19:48:53 +08:00
committed by GitHub
parent 16199e968e
commit f9bec1edf8
35 changed files with 123 additions and 105 deletions

View File

@@ -7,7 +7,7 @@ import { useContext } from 'use-context-selector'
import Toast from '../../base/toast'
import s from './style.module.css'
import ExploreContext from '@/context/explore-context'
import type { App } from '@/models/explore'
import type { App, AppCategory } from '@/models/explore'
import Category from '@/app/components/explore/category'
import AppCard from '@/app/components/explore/app-card'
import { fetchAppDetail, fetchAppList, installApp } from '@/service/explore'
@@ -22,7 +22,7 @@ const Apps: FC = () => {
const { t } = useTranslation()
const router = useRouter()
const { setControlUpdateInstalledApps, hasEditPermission } = useContext(ExploreContext)
const [currCategory, setCurrCategory] = React.useState('')
const [currCategory, setCurrCategory] = React.useState<AppCategory | ''>('')
const [allList, setAllList] = React.useState<App[]>([])
const [isLoaded, setIsLoaded] = React.useState(false)
@@ -31,7 +31,8 @@ const Apps: FC = () => {
return allList
return allList.filter(item => item.category === currCategory)
})()
const [categories, setCategories] = React.useState([])
const [categories, setCategories] = React.useState<AppCategory[]>([])
useEffect(() => {
(async () => {
const { categories, recommended_apps }: any = await fetchAppList()

View File

@@ -4,14 +4,15 @@ import React from 'react'
import { useTranslation } from 'react-i18next'
import cn from 'classnames'
import exploreI18n from '@/i18n/lang/explore.en'
import type { AppCategory } from '@/models/explore'
const categoryI18n = exploreI18n.category
export type ICategoryProps = {
className?: string
list: string[]
list: AppCategory[]
value: string
onChange: (value: string) => void
onChange: (value: AppCategory | '') => void
}
const Category: FC<ICategoryProps> = ({
@@ -40,7 +41,7 @@ const Category: FC<ICategoryProps> = ({
style={itemStyle(name === value)}
onClick={() => onChange(name)}
>
{(categoryI18n as any)[name] ? t(`explore.category.${name}`) : name}
{categoryI18n[name] ? t(`explore.category.${name}`) : name}
</div>
))}
</div>