diff --git a/web/app/(commonLayout)/explore/apps/page.tsx b/web/app/(commonLayout)/explore/apps/page.tsx index 883df5cf73..8066728562 100644 --- a/web/app/(commonLayout)/explore/apps/page.tsx +++ b/web/app/(commonLayout)/explore/apps/page.tsx @@ -1,37 +1,8 @@ -import React, { FC } from 'react' -import AppCard from '@/app/components/explore/app-card' +import AppList from "@/app/components/explore/app-list" +import React from 'react' -export interface IAppsProps { } -const list = [ - { - id: 1, - name: 'Story Bot', - mode: 'chat', - 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', - }, -] -const Apps: FC = ({ }) => { - return ( -
-
-
Explore Apps by Dify
-
Use these template apps instantly or customize your own apps based on the templates.
-
-
- -
-
- ) +const Apps = ({ }) => { + return } + export default React.memo(Apps) diff --git a/web/app/components/explore/app-list/index.tsx b/web/app/components/explore/app-list/index.tsx new file mode 100644 index 0000000000..e15a572e46 --- /dev/null +++ b/web/app/components/explore/app-list/index.tsx @@ -0,0 +1,70 @@ +'use client' + +import React, { FC, useEffect } from 'react' +import Category from '@/app/components/explore/category' +import AppCard from '@/app/components/explore/app-card' +import { fetchAppList } from '@/service/explore' + + +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', + }, +] + +const mockCategories = ['music', 'news'] + +const isMock = true +const Apps: FC = ({ }) => { + const [currCategory, setCurrCategory] = React.useState('') + const [allList, setAllList] = React.useState(isMock ? mockList : []) + const currList = (() => { + if(currCategory === '') return allList + return allList.filter(item => item.category === currCategory) + })() + const [categories, setCategories] = React.useState(isMock ? mockCategories : []) + useEffect(() => { + if(!isMock) { + (async () => { + const {categories, recommended_apps}:any = await fetchAppList() + setCategories(categories) + setAllList(recommended_apps) + })() + } + }, []) + return ( +
+
+
Explore Apps by Dify
+
Use these template apps instantly or customize your own apps based on the templates.
+
+ +
+ +
+
+ ) +} + +export default React.memo(Apps) diff --git a/web/app/components/explore/category.tsx b/web/app/components/explore/category.tsx new file mode 100644 index 0000000000..da27a5863b --- /dev/null +++ b/web/app/components/explore/category.tsx @@ -0,0 +1,42 @@ +'use client' +import React, { FC } from 'react' +import cn from 'classnames' + +export interface ICategoryProps { + className?: string + list: string[] + value: string + onChange: (value: string) => void +} + +const Category: FC = ({ + className, + list, + value, + onChange +}) => { + const itemClassName = (isSelected: boolean) => cn(isSelected ? 'bg-white text-primary-600 border-gray-200 font-semibold' : 'border-transparent font-medium','flex items-center h-7 px-3 border cursor-pointer rounded') + const itemStyle = (isSelected: boolean) => isSelected ? {boxShadow: '0px 1px 2px rgba(16, 24, 40, 0.05)'} : {} + return ( +
+
onChange('')} + > + All Categories +
+ {list.map(name => ( +
onChange(name)} + > + {name} +
+ ))} +
+ ) +} +export default React.memo(Category) diff --git a/web/service/explore.ts b/web/service/explore.ts new file mode 100644 index 0000000000..093e83f267 --- /dev/null +++ b/web/service/explore.ts @@ -0,0 +1,5 @@ +import { get } from './base' + +export const fetchAppList = () => { + return get('/explore/apps') +} \ No newline at end of file