mirror of
https://github.com/langgenius/dify.git
synced 2026-05-05 00:57:04 +08:00
feat: explore list use api
This commit is contained in:
parent
a485668429
commit
c42ccdfc6f
@ -1,8 +1,8 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import cn from 'classnames'
|
import cn from 'classnames'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { App } from '@/models/explore'
|
||||||
import AppModeLabel from '@/app/(commonLayout)/apps/AppModeLabel'
|
import AppModeLabel from '@/app/(commonLayout)/apps/AppModeLabel'
|
||||||
import type { App } from '@/types/app'
|
|
||||||
import AppIcon from '@/app/components/base/app-icon'
|
import AppIcon from '@/app/components/base/app-icon'
|
||||||
import { PlusIcon } from '@heroicons/react/20/solid'
|
import { PlusIcon } from '@heroicons/react/20/solid'
|
||||||
import Button from '../../base/button'
|
import Button from '../../base/button'
|
||||||
@ -27,23 +27,23 @@ const AppCard = ({
|
|||||||
onAddToWorkspace
|
onAddToWorkspace
|
||||||
}: AppCardProps) => {
|
}: AppCardProps) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
const {app: appBasicInfo} = app
|
||||||
return (
|
return (
|
||||||
<div className={s.wrap}>
|
<div className={s.wrap}>
|
||||||
<div className='col-span-1 bg-white border-2 border-solid border-transparent rounded-lg shadow-sm min-h-[160px] flex flex-col transition-all duration-200 ease-in-out cursor-pointer hover:shadow-lg'>
|
<div className='col-span-1 bg-white border-2 border-solid border-transparent rounded-lg shadow-sm min-h-[160px] flex flex-col transition-all duration-200 ease-in-out cursor-pointer hover:shadow-lg'>
|
||||||
<div className='flex pt-[14px] px-[14px] pb-3 h-[66px] items-center gap-3 grow-0 shrink-0'>
|
<div className='flex pt-[14px] px-[14px] pb-3 h-[66px] items-center gap-3 grow-0 shrink-0'>
|
||||||
<AppIcon size='small' />
|
<AppIcon size='small' />
|
||||||
<div className='relative h-8 text-sm font-medium leading-8 grow'>
|
<div className='relative h-8 text-sm font-medium leading-8 grow'>
|
||||||
<div className='absolute top-0 left-0 w-full h-full overflow-hidden text-ellipsis whitespace-nowrap'>{app.name}</div>
|
<div className='absolute top-0 left-0 w-full h-full overflow-hidden text-ellipsis whitespace-nowrap'>{appBasicInfo.name}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className='mb-3 px-[14px] h-9 text-xs leading-normal text-gray-500 line-clamp-2'>{app.model_config?.pre_prompt}</div>
|
<div className='mb-3 px-[14px] h-9 text-xs leading-normal text-gray-500 line-clamp-2'>{app.description}</div>
|
||||||
<div className='flex items-center flex-wrap min-h-[42px] px-[14px] pt-2 pb-[10px]'>
|
<div className='flex items-center flex-wrap min-h-[42px] px-[14px] pt-2 pb-[10px]'>
|
||||||
<div className={s.mode}>
|
<div className={s.mode}>
|
||||||
<AppModeLabel mode={app.mode} />
|
<AppModeLabel mode={appBasicInfo.mode} />
|
||||||
</div>
|
</div>
|
||||||
<div className={cn(s.opWrap, 'flex items-center w-full space-x-2')}>
|
<div className={cn(s.opWrap, 'flex items-center w-full space-x-2')}>
|
||||||
<Button type='primary' className='grow flex items-center !h-7' onClick={() => onAddToWorkspace(app.id)}>
|
<Button type='primary' className='grow flex items-center !h-7' onClick={() => onAddToWorkspace(appBasicInfo.id)}>
|
||||||
<PlusIcon className='w-4 h-4 mr-1' />
|
<PlusIcon className='w-4 h-4 mr-1' />
|
||||||
<span className='text-xs'>{t('explore.appCard.addToWorkspace')}</span>
|
<span className='text-xs'>{t('explore.appCard.addToWorkspace')}</span>
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@ -1,70 +1,34 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import React, { FC, useEffect } from 'react'
|
import React, { FC, useEffect } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { App } from '@/models/explore'
|
||||||
import Category from '@/app/components/explore/category'
|
import Category from '@/app/components/explore/category'
|
||||||
import AppCard from '@/app/components/explore/app-card'
|
import AppCard from '@/app/components/explore/app-card'
|
||||||
import { fetchAppList } from '@/service/explore'
|
import { fetchAppList } from '@/service/explore'
|
||||||
import CreateAppModal from '@/app/components/explore/create-app-modal'
|
import CreateAppModal from '@/app/components/explore/create-app-modal'
|
||||||
|
import Loading from '@/app/components/base/loading'
|
||||||
|
|
||||||
import s from './style.module.css'
|
import s from './style.module.css'
|
||||||
|
|
||||||
const mockList = [
|
|
||||||
{
|
|
||||||
id: 1,
|
|
||||||
name: 'Story Bot',
|
|
||||||
mode: 'chat',
|
|
||||||
category: 'music',
|
|
||||||
model_config: {
|
|
||||||
pre_prompt: 'I need you to play the role of a storyteller, and generate creative and vivid short stories based on the keywords I provide.',
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 2,
|
|
||||||
name: 'Code Translate',
|
|
||||||
mode: 'completion',
|
|
||||||
category: 'news',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 3,
|
|
||||||
name: 'Code Translate',
|
|
||||||
mode: 'completion',
|
|
||||||
category: 'news',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 4,
|
|
||||||
name: 'Code Translate',
|
|
||||||
mode: 'completion',
|
|
||||||
category: 'news',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 5,
|
|
||||||
name: 'Code Translate',
|
|
||||||
mode: 'completion',
|
|
||||||
category: 'news',
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
const mockCategories = ['music', 'news']
|
|
||||||
|
|
||||||
const isMock = true
|
|
||||||
const Apps: FC = ({ }) => {
|
const Apps: FC = ({ }) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
|
||||||
const [currCategory, setCurrCategory] = React.useState('')
|
const [currCategory, setCurrCategory] = React.useState('')
|
||||||
const [allList, setAllList] = React.useState(isMock ? mockList : [])
|
const [allList, setAllList] = React.useState<App[]>([])
|
||||||
|
const [isLoaded, setIsLoaded] = React.useState(false)
|
||||||
|
|
||||||
const currList = (() => {
|
const currList = (() => {
|
||||||
if(currCategory === '') return allList
|
if(currCategory === '') return allList
|
||||||
return allList.filter(item => item.category === currCategory)
|
return allList.filter(item => item.category === currCategory)
|
||||||
})()
|
})()
|
||||||
const [categories, setCategories] = React.useState(isMock ? mockCategories : [])
|
const [categories, setCategories] = React.useState([])
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if(!isMock) {
|
(async () => {
|
||||||
(async () => {
|
const {categories, recommended_apps}:any = await fetchAppList()
|
||||||
const {categories, recommended_apps}:any = await fetchAppList()
|
setCategories(categories)
|
||||||
setCategories(categories)
|
setAllList(recommended_apps)
|
||||||
setAllList(recommended_apps)
|
setIsLoaded(true)
|
||||||
})()
|
})()
|
||||||
}
|
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const handleAddToWorkspace = (appId: string) => {
|
const handleAddToWorkspace = (appId: string) => {
|
||||||
@ -76,6 +40,15 @@ const Apps: FC = ({ }) => {
|
|||||||
const onCreate = ({name}: any) => {
|
const onCreate = ({name}: any) => {
|
||||||
console.log({id: currApp.id, name})
|
console.log({id: currApp.id, name})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!isLoaded) {
|
||||||
|
return (
|
||||||
|
<div className='flex h-full items-center'>
|
||||||
|
<Loading type='area' />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='h-full flex flex-col'>
|
<div className='h-full flex flex-col'>
|
||||||
<div className='shrink-0 pt-6 px-12'>
|
<div className='shrink-0 pt-6 px-12'>
|
||||||
@ -88,14 +61,20 @@ const Apps: FC = ({ }) => {
|
|||||||
value={currCategory}
|
value={currCategory}
|
||||||
onChange={setCurrCategory}
|
onChange={setCurrCategory}
|
||||||
/>
|
/>
|
||||||
<div className='flex flex-col overflow-auto bg-gray-100 shrink-0 grow'>
|
<div
|
||||||
<nav className={`${s.appList} grid content-start grid-cols-1 gap-4 px-12 pt-6 md:grid-cols-2 grow shrink-0`}>
|
className='flex mt-6 flex-col overflow-auto bg-gray-100 shrink-0 grow'
|
||||||
{currList.map(item => (
|
style={{
|
||||||
|
maxHeight: 'calc(100vh - 243px)'
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<nav
|
||||||
|
className={`${s.appList} grid content-start grid-cols-1 gap-4 px-12 pb-10 md:grid-cols-2 grow shrink-0`}>
|
||||||
|
{currList.map(app => (
|
||||||
<AppCard
|
<AppCard
|
||||||
key={item.id}
|
key={app.app_id}
|
||||||
app={item as any}
|
app={app}
|
||||||
onCreate={() => {
|
onCreate={() => {
|
||||||
setCurrApp(item)
|
setCurrApp(app)
|
||||||
setIsShowCreateModal(true)
|
setIsShowCreateModal(true)
|
||||||
}}
|
}}
|
||||||
onAddToWorkspace={handleAddToWorkspace}
|
onAddToWorkspace={handleAddToWorkspace}
|
||||||
|
|||||||
@ -2,11 +2,4 @@
|
|||||||
.appList {
|
.appList {
|
||||||
grid-template-columns: repeat(4, minmax(0, 1fr))
|
grid-template-columns: repeat(4, minmax(0, 1fr))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* @media (min-width: 1624px) {
|
|
||||||
.appList {
|
|
||||||
grid-template-columns: repeat(3, minmax(0, 1fr))
|
|
||||||
}
|
|
||||||
} */
|
|
||||||
23
web/models/explore.ts
Normal file
23
web/models/explore.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import { AppMode } from "./app";
|
||||||
|
|
||||||
|
export type AppBasicInfo = {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
mode: AppMode;
|
||||||
|
icon: null;
|
||||||
|
icon_background: null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type App = {
|
||||||
|
app: AppBasicInfo;
|
||||||
|
app_id: string;
|
||||||
|
description: string;
|
||||||
|
copyright: string;
|
||||||
|
privacy_policy: string;
|
||||||
|
category: string;
|
||||||
|
position: number;
|
||||||
|
is_listed: boolean;
|
||||||
|
install_count: number;
|
||||||
|
installed: boolean;
|
||||||
|
editable: boolean;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user