From c42ccdfc6fa4e47e2ceab6bfe345f63192c10682 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=91=E4=BC=9F=E5=BC=BA?= Date: Thu, 18 May 2023 11:08:55 +0800 Subject: [PATCH] feat: explore list use api --- web/app/components/explore/app-card/index.tsx | 12 +-- web/app/components/explore/app-list/index.tsx | 87 +++++++------------ .../explore/app-list/style.module.css | 9 +- web/models/explore.ts | 23 +++++ 4 files changed, 63 insertions(+), 68 deletions(-) create mode 100644 web/models/explore.ts diff --git a/web/app/components/explore/app-card/index.tsx b/web/app/components/explore/app-card/index.tsx index 8a95378710..97906abd7f 100644 --- a/web/app/components/explore/app-card/index.tsx +++ b/web/app/components/explore/app-card/index.tsx @@ -1,8 +1,8 @@ 'use client' import cn from 'classnames' import { useTranslation } from 'react-i18next' +import { App } from '@/models/explore' import AppModeLabel from '@/app/(commonLayout)/apps/AppModeLabel' -import type { App } from '@/types/app' import AppIcon from '@/app/components/base/app-icon' import { PlusIcon } from '@heroicons/react/20/solid' import Button from '../../base/button' @@ -27,23 +27,23 @@ const AppCard = ({ onAddToWorkspace }: AppCardProps) => { const { t } = useTranslation() - + const {app: appBasicInfo} = app return (
-
{app.name}
+
{appBasicInfo.name}
-
{app.model_config?.pre_prompt}
+
{app.description}
- +
- diff --git a/web/app/components/explore/app-list/index.tsx b/web/app/components/explore/app-list/index.tsx index d0fc92c8c7..0c5c5658c9 100644 --- a/web/app/components/explore/app-list/index.tsx +++ b/web/app/components/explore/app-list/index.tsx @@ -1,70 +1,34 @@ 'use client' import React, { FC, useEffect } from 'react' import { useTranslation } from 'react-i18next' +import { App } from '@/models/explore' import Category from '@/app/components/explore/category' import AppCard from '@/app/components/explore/app-card' import { fetchAppList } from '@/service/explore' import CreateAppModal from '@/app/components/explore/create-app-modal' +import Loading from '@/app/components/base/loading' 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 { t } = useTranslation() const [currCategory, setCurrCategory] = React.useState('') - const [allList, setAllList] = React.useState(isMock ? mockList : []) + const [allList, setAllList] = React.useState([]) + const [isLoaded, setIsLoaded] = React.useState(false) + const currList = (() => { if(currCategory === '') return allList return allList.filter(item => item.category === currCategory) })() - const [categories, setCategories] = React.useState(isMock ? mockCategories : []) + const [categories, setCategories] = React.useState([]) useEffect(() => { - if(!isMock) { - (async () => { - const {categories, recommended_apps}:any = await fetchAppList() - setCategories(categories) - setAllList(recommended_apps) - })() - } + (async () => { + const {categories, recommended_apps}:any = await fetchAppList() + setCategories(categories) + setAllList(recommended_apps) + setIsLoaded(true) + })() }, []) const handleAddToWorkspace = (appId: string) => { @@ -76,6 +40,15 @@ const Apps: FC = ({ }) => { const onCreate = ({name}: any) => { console.log({id: currApp.id, name}) } + + if(!isLoaded) { + return ( +
+ +
+ ) + } + return (
@@ -88,14 +61,20 @@ const Apps: FC = ({ }) => { value={currCategory} onChange={setCurrCategory} /> -
-