Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

✨ feat(share): expose app entry actions in topic share header (#21477)

Tsuki896f58a28978
diff --git a/apps/share/app/routes/shareTopic.tsx b/apps/share/app/routes/shareTopic.tsx
index 7669b7e2f64..d53f7b81f03 100644
--- a/apps/share/app/routes/shareTopic.tsx
+++ b/apps/share/app/routes/shareTopic.tsx
@@ -1,4 +1,4 @@
-import { BRANDING_NAME } from '@lobechat/business-const';
+import { APPLE_APP_STORE_ID, BRANDING_NAME } from '@lobechat/business-const';
import type { ClientLoaderFunctionArgs, LoaderFunctionArgs, MetaFunction } from 'react-router';
import { useLoaderData } from 'react-router';
import { SWRConfig, unstable_serialize } from 'swr';
@@ -35,6 +35,7 @@ export const loader = async ({ context, params, request }: LoaderFunctionArgs) =
]);
return {
+ appArgument: `${new URL(request.url).origin}/share/t/${encodeURIComponent(shareId)}`,
firstPage,
messageReadMode,
byline: topic ? buildTopicByline(topic) : undefined,
@@ -61,7 +62,7 @@ clientLoader.hydrate = true as const;
export const meta: MetaFunction<typeof loader> = ({ loaderData }) => {
const title = loaderData?.topic?.title;
- return buildPageMeta({
+ const metas = buildPageMeta({
description: [truncateDescription(loaderData?.byline), loaderData?.description]
.filter(Boolean)
.join(' · '),
@@ -69,6 +70,12 @@ export const meta: MetaFunction<typeof loader> = ({ loaderData }) => {
title: title ? `${title} · ${BRANDING_NAME}` : BRANDING_NAME,
type: 'article',
});
+ if (APPLE_APP_STORE_ID && loaderData?.appArgument)
+ metas.push({
+ name: 'apple-itunes-app',
+ content: `app-id=${APPLE_APP_STORE_ID}, app-argument=${loaderData.appArgument}`,
+ });
+ return metas;
};
export default function ShareTopicRoute() {
diff --git a/apps/share/src/features/topic/ExplainTopic.tsx b/apps/share/src/features/topic/ExplainTopic.tsx
index 6f3edcf1d3e..6eff9667525 100644
--- a/apps/share/src/features/topic/ExplainTopic.tsx
+++ b/apps/share/src/features/topic/ExplainTopic.tsx
@@ -3,7 +3,7 @@ import { Sparkles } from 'lucide-react';
import { useState } from 'react';
import { useTranslation } from 'react-i18next';
-export default function ExplainTopic({ shareId }: { shareId: string }) {
+export function useExplainTopicAction(shareId: string) {
const { t } = useTranslation('chat');
const [loading, setLoading] = useState(false);
@@ -23,9 +23,18 @@ export default function ExplainTopic({ shareId }: { shareId: string }) {
}
};
+ return { copyPrompt, loading, label: t('sharePage.explain.action') };
+}
+
+export default function ExplainTopic({
+ action,
+}: {
+ action: ReturnType<typeof useExplainTopicAction>;
+}) {
+ const { copyPrompt, loading, label } = action;
return (
<Button icon={Sparkles} loading={loading} size={'small'} type={'fill'} onClick={copyPrompt}>
- {t('sharePage.explain.action')}
+ {label}
</Button>
);
}
diff --git a/apps/share/src/features/topic/SharedTopicView.tsx b/apps/share/src/features/topic/SharedTopicView.tsx
index 591c52a7a60..675bae43ad4 100644
--- a/apps/share/src/features/topic/SharedTopicView.tsx
+++ b/apps/share/src/features/topic/SharedTopicView.tsx
@@ -16,7 +16,7 @@ import { type SharedTopicData } from '@/types/topic';
import { clientOnly } from '../../shell/clientOnly';
import ShareLayout from '../../shell/ShareLayout';
-import ExplainTopic from './ExplainTopic';
+import ExplainTopic, { useExplainTopicAction } from './ExplainTopic';
import {
primeSharedTopicMessages,
type SharedTopicFirstPage,
@@ -47,6 +47,7 @@ interface SharedTopicViewProps {
const SharedTopicView = memo<SharedTopicViewProps>(({ messageReadMode }) => {
const wideScreen = useGlobalStore(systemStatusSelectors.wideScreen);
const { id } = useParams<{ id: string }>();
+ const explain = useExplainTopicAction(id ?? '');
const { data, error, isLoading } = useSWR(
id ? shareKeys.topic(id) : null,
@@ -74,14 +75,25 @@ const SharedTopicView = memo<SharedTopicViewProps>(({ messageReadMode }) => {
return (
<ShareLayout
- actions={id && data?.visibility === 'link' ? <ExplainTopic shareId={id} /> : undefined}
+ actions={id && data?.visibility === 'link' ? <ExplainTopic action={explain} /> : undefined}
aside={<SharedTopicAside />}
contentWidth={wideScreen ? undefined : CONVERSATION_MIN_WIDTH}
error={error}
- // The SSR document already carries the hero, and SWR revalidates on mount
- // with that data in cache — gating on `isLoading` alone would blank it.
loading={isLoading && !data}
title={data?.title}
+ compactActions={
+ id && data?.visibility === 'link'
+ ? [
+ {
+ key: 'explain-topic',
+ label: explain.label,
+ onClick: () => {
+ void explain.copyPrompt();
+ },
+ },
+ ]
+ : undefined
+ }
>
{id && data ? (
<SharedTopicBody fallback={hero} messageReadMode={messageReadMode} shareId={id} />
diff --git a/apps/share/src/shell/ShareLayout.tsx b/apps/share/src/shell/ShareLayout.tsx
index 89a90410276..d65f7f4122c 100644
--- a/apps/share/src/shell/ShareLayout.tsx
+++ b/apps/share/src/shell/ShareLayout.tsx
@@ -1,18 +1,39 @@
'use client';
-import { copyToClipboard, Flexbox } from '@lobehub/ui';
-import { ActionIcon, Text, toast } from '@lobehub/ui';
-import { createStaticStyles } from '@lobehub/ui';
+import { ActionIcon, copyToClipboard, createStaticStyles, Flexbox, Text, toast } from '@lobehub/ui';
import { LinkIcon } from 'lucide-react';
-import { type CSSProperties, type ReactNode } from 'react';
+import { type ComponentType, type CSSProperties, type ReactNode } from 'react';
import { useTranslation } from 'react-i18next';
-import { ShareHeaderMenu, ShareLogoLink } from '@/business/client/features/ShareChrome';
+import * as ShareChrome from '@/business/client/features/ShareChrome';
import { ProductLogo } from '@/components/Branding';
import Loading from '@/components/Loading/BrandTextLoading';
import { DESKTOP_HEADER_ICON_SMALL_SIZE } from '@/const/layoutTokens';
import ShareErrorView from '@/features/Share/ErrorView';
+type HeaderActionsProps = {
+ actions?: ReactNode;
+ compactActions?: { key: string; label: string; onClick: () => void }[];
+ copyLink?: ReactNode;
+};
+
+// The OSS build can be overlaid with Cloud main before its companion PR lands.
+// Read the optional extension at runtime so that older overlays still build.
+const ShareHeaderActions = (props: HeaderActionsProps) => {
+ const Extension = Reflect.get(ShareChrome, 'ShareHeaderActions') as
+ ComponentType<HeaderActionsProps> | undefined;
+ return Extension ? (
+ <Extension {...props} />
+ ) : (
+ <>
+ {props.actions}
+ {props.copyLink}
+ <ShareChrome.ShareHeaderMenu />
+ </>
+ );
+};
+const ShareLogoLink = ShareChrome.ShareLogoLink;
+
const HEADER_HEIGHT = 44;
const GUTTER_MIN_WIDTH = 316;
@@ -106,6 +127,7 @@ export interface ShareLayoutProps {
actions?: ReactNode;
aside?: ReactNode;
children?: ReactNode;
+ compactActions?: { key: string; label: string; onClick: () => void }[];
contentWidth?: number;
error?: unknown;
loading?: boolean;
@@ -133,6 +155,7 @@ const CopyLinkAction = () => {
const ShareLayout = ({
actions,
+ compactActions,
aside,
children,
contentWidth,
@@ -174,9 +197,11 @@ const ShareLayout = ({
)}
</div>
<Flexbox horizontal align={'center'} flex={'none'} gap={2}>
- {!error && !loading && actions}
- {!error && <CopyLinkAction />}
- <ShareHeaderMenu />
+ <ShareHeaderActions
+ actions={!error && !loading ? actions : undefined}
+ compactActions={!error && !loading ? compactActions : undefined}
+ copyLink={!error ? <CopyLinkAction /> : undefined}
+ />
</Flexbox>
</header>
<Flexbox className={styles.body} flex={1}>
diff --git a/locales/en-US/chat.json b/locales/en-US/chat.json
index 05d568860c2..1f2547ba35b 100644
--- a/locales/en-US/chat.json
+++ b/locales/en-US/chat.json
@@ -2227,6 +2227,9 @@
"shareModal.withRole": "Include Message Role",
"shareModal.withSystemRole": "Include Agent Profile",
"sharePage.actions.tryItYourself": "Try it yourself",
+ "sharePage.app.help": "Trouble opening the app?",
+ "sharePage.app.helpDescription": "If this browser prevents opening the app, use its menu to open this page in your system browser. You can also keep reading here.",
+ "sharePage.app.open": "Open app",
"sharePage.error.forbidden.subtitle": "This share is private and not accessible.",
"sharePage.error.forbidden.title": "Access Denied",
"sharePage.error.notFound.subtitle": "This topic does not exist or has been removed.",
diff --git a/locales/zh-CN/chat.json b/locales/zh-CN/chat.json
index 641e0745649..7c9fda42336 100644
--- a/locales/zh-CN/chat.json
+++ b/locales/zh-CN/chat.json
@@ -2227,6 +2227,9 @@
"shareModal.withRole": "包含消息角色",
"shareModal.withSystemRole": "包含助理档案",
"sharePage.actions.tryItYourself": "做同款",
+ "sharePage.app.help": "打开 App 遇到问题?",
+ "sharePage.app.helpDescription": "如果当前浏览器阻止打开 App,可以通过浏览器菜单在系统浏览器中打开此页面。你也可以继续在这里阅读。",
+ "sharePage.app.open": "打开 App",
"sharePage.error.forbidden.subtitle": "此分享为私密状态,无法访问。",
"sharePage.error.forbidden.title": "无权访问",
"sharePage.error.notFound.subtitle": "该话题不存在或已被删除。",
diff --git a/packages/locales/src/default/chat.ts b/packages/locales/src/default/chat.ts
index fd2bbbc995e..fceb6404be4 100644
--- a/packages/locales/src/default/chat.ts
+++ b/packages/locales/src/default/chat.ts
@@ -1,4 +1,9 @@
export default {
+ 'sharePage.app.open': 'Open app',
+ 'sharePage.app.help': 'Trouble opening the app?',
+ 'sharePage.app.helpDescription':
+ 'If this browser prevents opening the app, use its menu to open this page in your system browser. You can also keep reading here.',
+
'backgroundActivity.alertDesc': '{{name}} is using {{memory}} of memory and {{cpu}} CPU.',
'backgroundActivity.cpu': 'CPU',
'backgroundActivity.details': 'View details',
diff --git a/src/business/client/features/ShareChrome/index.tsx b/src/business/client/features/ShareChrome/index.tsx
index ed25232dbb0..03f1a34759b 100644
--- a/src/business/client/features/ShareChrome/index.tsx
+++ b/src/business/client/features/ShareChrome/index.tsx
@@ -9,3 +9,18 @@ export const ShareLogoLink = ({ children }: { children: ReactNode }) => (
);
export const ShareHeaderMenu = () => null;
+
+// Cloud can supply native-app entry and compact actions without replacing the share layout.
+export interface ShareHeaderActionsProps {
+ actions?: ReactNode;
+ compactActions?: { key: string; label: string; onClick: () => void }[];
+ copyLink?: ReactNode;
+}
+
+export const ShareHeaderActions = ({ actions, copyLink }: ShareHeaderActionsProps) => (
+ <>
+ {actions}
+ {copyLink}
+ <ShareHeaderMenu />
+ </>
+);