From b49a4eab6224c4ac0718964963e0d4bd748c0c91 Mon Sep 17 00:00:00 2001 From: Joel Date: Fri, 24 Oct 2025 18:33:54 +0800 Subject: [PATCH] feat: add app list context --- .../app/create-app-dialog/app-card/index.tsx | 23 +++++++++++++++-- web/app/components/apps/index.tsx | 25 ++++++++++++++++--- web/context/app-list-context.ts | 17 +++++++++++++ 3 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 web/context/app-list-context.ts diff --git a/web/app/components/app/create-app-dialog/app-card/index.tsx b/web/app/components/app/create-app-dialog/app-card/index.tsx index 7f7ede0065..82f10a2d6f 100644 --- a/web/app/components/app/create-app-dialog/app-card/index.tsx +++ b/web/app/components/app/create-app-dialog/app-card/index.tsx @@ -6,6 +6,11 @@ import Button from '@/app/components/base/button' import cn from '@/utils/classnames' import type { App } from '@/models/explore' import AppIcon from '@/app/components/base/app-icon' +import { useGlobalPublicStore } from '@/context/global-public-context' +import { RiInformation2Line } from '@remixicon/react' +import { useCallback } from 'react' +import AppListContext from '@/context/app-list-context' +import { useContextSelector } from 'use-context-selector' export type AppCardProps = { app: App @@ -19,6 +24,14 @@ const AppCard = ({ }: AppCardProps) => { const { t } = useTranslation() const { app: appBasicInfo } = app + const { systemFeatures } = useGlobalPublicStore() + const isTrialApp = app.can_trial && systemFeatures.enable_trial_app + const setShowTryAppPanel = useContextSelector(AppListContext, ctx => ctx.setShowTryAppPanel) + const showTryAPPPanel = useCallback((appId: string) => { + return () => { + setShowTryAppPanel?.(true, { appId, app }) + } + }, [setShowTryAppPanel, app.category]) return (
@@ -46,11 +59,17 @@ const AppCard = ({
diff --git a/web/app/components/apps/index.tsx b/web/app/components/apps/index.tsx index 6d21800421..c02741705f 100644 --- a/web/app/components/apps/index.tsx +++ b/web/app/components/apps/index.tsx @@ -3,6 +3,9 @@ import { useEducationInit } from '@/app/education-apply/hooks' import List from './list' import useDocumentTitle from '@/hooks/use-document-title' import { useTranslation } from 'react-i18next' +import AppListContext from '@/context/app-list-context' +import { useState } from 'react' +import type { CurrentTryAppParams } from '@/context/explore-context' const Apps = () => { const { t } = useTranslation() @@ -10,10 +13,26 @@ const Apps = () => { useDocumentTitle(t('common.menus.apps')) useEducationInit() + const [currentTryAppParams, setCurrentTryAppParams] = useState(undefined) + const [isShowTryAppPanel, setIsShowTryAppPanel] = useState(false) + const setShowTryAppPanel = (showTryAppPanel: boolean, params?: CurrentTryAppParams) => { + if (showTryAppPanel) + setCurrentTryAppParams(params) + else + setCurrentTryAppParams(undefined) + setIsShowTryAppPanel(showTryAppPanel) + } + return ( -
- -
+ +
+ +
+
) } diff --git a/web/context/app-list-context.ts b/web/context/app-list-context.ts new file mode 100644 index 0000000000..bdd1766bb2 --- /dev/null +++ b/web/context/app-list-context.ts @@ -0,0 +1,17 @@ +import { createContext } from 'use-context-selector' +import { noop } from 'lodash-es' +import type { CurrentTryAppParams } from './explore-context' + +type Props = { + currentApp?: CurrentTryAppParams + isShowTryAppPanel: boolean + setShowTryAppPanel: (showTryAppPanel: boolean, params?: CurrentTryAppParams) => void +} + +const AppListContext = createContext({ + isShowTryAppPanel: false, + setShowTryAppPanel: noop, + currentApp: undefined, +}) + +export default AppListContext