mirror of
https://github.com/lobehub/lobehub.git
synced 2026-03-27 13:29:15 +07:00
♻️ refactor: upgrade agents/group detail pages tabs、hidden like button (#12127)
* refactor: upgrade agents/group detail pages tabs、hidden like button * fix: delete useless code
This commit is contained in:
@@ -6,10 +6,7 @@ import { createStaticStyles } from 'antd-style';
|
||||
import { BookOpenIcon, HistoryIcon, LayersIcon, ListIcon, SquareUserIcon } from 'lucide-react';
|
||||
import { memo } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import urlJoin from 'url-join';
|
||||
|
||||
import { AGENTS_INDEX_GITHUB, AGENTS_OFFICIAL_URL } from '@/const/url';
|
||||
import { useQuery } from '@/hooks/useQuery';
|
||||
import { AssistantNavKey } from '@/types/discover';
|
||||
|
||||
import { useDetailContext } from '../DetailProvider';
|
||||
@@ -46,14 +43,7 @@ interface NavProps {
|
||||
|
||||
const Nav = memo<NavProps>(({ mobile, setActiveTab, activeTab = AssistantNavKey.Overview }) => {
|
||||
const { t } = useTranslation('discover');
|
||||
const { pluginCount, knowledgeCount, identifier } = useDetailContext();
|
||||
const { source } = useQuery() as { source?: string };
|
||||
const isLegacy = source === 'legacy';
|
||||
const marketplaceLink = identifier
|
||||
? isLegacy
|
||||
? urlJoin(AGENTS_INDEX_GITHUB, 'tree/main/locales', identifier)
|
||||
: urlJoin(AGENTS_OFFICIAL_URL, identifier)
|
||||
: undefined;
|
||||
const { pluginCount, knowledgeCount } = useDetailContext();
|
||||
|
||||
const capabilitiesCount = Number(pluginCount) + Number(knowledgeCount);
|
||||
|
||||
@@ -116,19 +106,6 @@ const Nav = memo<NavProps>(({ mobile, setActiveTab, activeTab = AssistantNavKey.
|
||||
<a className={styles.link} href={SOCIAL_URL.discord} rel="noreferrer" target="_blank">
|
||||
{t('mcp.details.nav.needHelp')}
|
||||
</a>
|
||||
{identifier && marketplaceLink && (
|
||||
<a className={styles.link} href={marketplaceLink} rel="noreferrer" target="_blank">
|
||||
{t('mcp.details.nav.viewSourceCode')}
|
||||
</a>
|
||||
)}
|
||||
<a
|
||||
className={styles.link}
|
||||
href="https://github.com/lobehub/lobe-chat-agents/issues/new/choose"
|
||||
rel="noreferrer"
|
||||
target="_blank"
|
||||
>
|
||||
{t('mcp.details.nav.reportIssue')}
|
||||
</a>
|
||||
</Flexbox>
|
||||
</Flexbox>
|
||||
);
|
||||
|
||||
@@ -21,7 +21,6 @@ import {
|
||||
CoinsIcon,
|
||||
DotIcon,
|
||||
GitBranchIcon,
|
||||
HeartIcon,
|
||||
} from 'lucide-react';
|
||||
import qs from 'query-string';
|
||||
import { memo, useState } from 'react';
|
||||
@@ -65,7 +64,6 @@ const Header = memo<{ mobile?: boolean }>(({ mobile: isMobile }) => {
|
||||
const { mobile = isMobile } = useResponsive();
|
||||
const { isAuthenticated, signIn, session } = useMarketAuth();
|
||||
const [favoriteLoading, setFavoriteLoading] = useState(false);
|
||||
const [likeLoading, setLikeLoading] = useState(false);
|
||||
|
||||
// Set access token for social service
|
||||
if (session?.accessToken) {
|
||||
@@ -81,14 +79,6 @@ const Header = memo<{ mobile?: boolean }>(({ mobile: isMobile }) => {
|
||||
|
||||
const isFavorited = favoriteStatus?.isFavorited ?? false;
|
||||
|
||||
// Fetch like status
|
||||
const { data: likeStatus, mutate: mutateLike } = useSWR(
|
||||
identifier && isAuthenticated ? ['like-status', 'agent', identifier] : null,
|
||||
() => socialService.checkLikeStatus('agent', identifier!),
|
||||
{ revalidateOnFocus: false },
|
||||
);
|
||||
const isLiked = likeStatus?.isLiked ?? false;
|
||||
|
||||
const handleFavoriteClick = async () => {
|
||||
if (!isAuthenticated) {
|
||||
await signIn();
|
||||
@@ -115,30 +105,6 @@ const Header = memo<{ mobile?: boolean }>(({ mobile: isMobile }) => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleLikeClick = async () => {
|
||||
if (!isAuthenticated) {
|
||||
await signIn();
|
||||
return;
|
||||
}
|
||||
if (!identifier) return;
|
||||
setLikeLoading(true);
|
||||
try {
|
||||
if (isLiked) {
|
||||
await socialService.unlike('agent', identifier);
|
||||
message.success(t('assistant.unlikeSuccess'));
|
||||
} else {
|
||||
await socialService.like('agent', identifier);
|
||||
message.success(t('assistant.likeSuccess'));
|
||||
}
|
||||
await mutateLike();
|
||||
} catch (error) {
|
||||
console.error('Like action failed:', error);
|
||||
message.error(t('assistant.likeFailed'));
|
||||
} finally {
|
||||
setLikeLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const categories = useCategory();
|
||||
const cate = categories.find((c) => c.key === category);
|
||||
|
||||
@@ -195,14 +161,6 @@ const Header = memo<{ mobile?: boolean }>(({ mobile: isMobile }) => {
|
||||
{title}
|
||||
</Text>
|
||||
</Flexbox>
|
||||
<Tooltip title={isLiked ? t('assistant.unlike') : t('assistant.like')}>
|
||||
<ActionIcon
|
||||
icon={HeartIcon}
|
||||
loading={likeLoading}
|
||||
onClick={handleLikeClick}
|
||||
style={isLiked ? { color: '#ff4d4f' } : undefined}
|
||||
/>
|
||||
</Tooltip>
|
||||
<Tooltip title={isFavorited ? t('assistant.unfavorite') : t('assistant.favorite')}>
|
||||
<ActionIcon
|
||||
icon={isFavorited ? BookmarkCheckIcon : BookmarkIcon}
|
||||
|
||||
@@ -71,14 +71,6 @@ const Nav = memo<NavProps>(({ mobile, setActiveTab, activeTab = GroupAgentNavKey
|
||||
<a className={styles.link} href={SOCIAL_URL.discord} rel="noreferrer" target="_blank">
|
||||
{t('groupAgents.details.nav.needHelp', { defaultValue: 'Need help?' })}
|
||||
</a>
|
||||
<a
|
||||
className={styles.link}
|
||||
href="https://github.com/lobehub/lobe-chat/issues/new/choose"
|
||||
rel="noreferrer"
|
||||
target="_blank"
|
||||
>
|
||||
{t('groupAgents.details.nav.reportIssue', { defaultValue: 'Report issue' })}
|
||||
</a>
|
||||
</Flexbox>
|
||||
</Flexbox>
|
||||
);
|
||||
|
||||
@@ -18,7 +18,6 @@ import {
|
||||
BookmarkIcon,
|
||||
DotIcon,
|
||||
GitBranchIcon,
|
||||
HeartIcon,
|
||||
UsersIcon,
|
||||
} from 'lucide-react';
|
||||
import qs from 'query-string';
|
||||
@@ -49,7 +48,6 @@ const Header = memo<{ mobile?: boolean }>(({ mobile: isMobile }) => {
|
||||
const { mobile = isMobile } = useResponsive();
|
||||
const { isAuthenticated, signIn, session } = useMarketAuth();
|
||||
const [favoriteLoading, setFavoriteLoading] = useState(false);
|
||||
const [likeLoading, setLikeLoading] = useState(false);
|
||||
|
||||
const {
|
||||
memberAgents = [],
|
||||
@@ -81,14 +79,6 @@ const Header = memo<{ mobile?: boolean }>(({ mobile: isMobile }) => {
|
||||
|
||||
const isFavorited = favoriteStatus?.isFavorited ?? false;
|
||||
|
||||
// Fetch like status
|
||||
const { data: likeStatus, mutate: mutateLike } = useSWR(
|
||||
identifier && isAuthenticated ? ['like-status', 'agent', identifier] : null,
|
||||
() => socialService.checkLikeStatus('agent', identifier!),
|
||||
{ revalidateOnFocus: false },
|
||||
);
|
||||
const isLiked = likeStatus?.isLiked ?? false;
|
||||
|
||||
const handleFavoriteClick = async () => {
|
||||
if (!isAuthenticated) {
|
||||
await signIn();
|
||||
@@ -114,31 +104,6 @@ const Header = memo<{ mobile?: boolean }>(({ mobile: isMobile }) => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleLikeClick = async () => {
|
||||
if (!isAuthenticated) {
|
||||
await signIn();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!identifier) return;
|
||||
|
||||
setLikeLoading(true);
|
||||
try {
|
||||
if (isLiked) {
|
||||
await socialService.unlike('agent', identifier);
|
||||
message.success(t('assistant.unlikeSuccess'));
|
||||
} else {
|
||||
await socialService.like('agent', identifier);
|
||||
message.success(t('assistant.likeSuccess'));
|
||||
}
|
||||
await mutateLike();
|
||||
} catch {
|
||||
message.error(t('assistant.likeFailed'));
|
||||
} finally {
|
||||
setLikeLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const cateButton = category ? (
|
||||
<Link
|
||||
to={qs.stringifyUrl({
|
||||
@@ -192,14 +157,6 @@ const Header = memo<{ mobile?: boolean }>(({ mobile: isMobile }) => {
|
||||
{title}
|
||||
</Text>
|
||||
</Flexbox>
|
||||
<Tooltip title={isLiked ? t('assistant.unlike') : t('assistant.like')}>
|
||||
<ActionIcon
|
||||
icon={HeartIcon}
|
||||
loading={likeLoading}
|
||||
onClick={handleLikeClick}
|
||||
style={isLiked ? { color: '#ff4d4f' } : undefined}
|
||||
/>
|
||||
</Tooltip>
|
||||
<Tooltip title={isFavorited ? t('assistant.unfavorite') : t('assistant.favorite')}>
|
||||
<ActionIcon
|
||||
icon={isFavorited ? BookmarkCheckIcon : BookmarkIcon}
|
||||
|
||||
@@ -18,10 +18,10 @@ import {
|
||||
AlertTriangle,
|
||||
ClockIcon,
|
||||
CoinsIcon,
|
||||
DownloadIcon,
|
||||
ExternalLink,
|
||||
Eye,
|
||||
EyeOff,
|
||||
GitForkIcon,
|
||||
MoreVerticalIcon,
|
||||
Pencil,
|
||||
} from 'lucide-react';
|
||||
@@ -127,7 +127,7 @@ const UserAgentCard = memo<UserAgentCardProps>(
|
||||
createdAt,
|
||||
category,
|
||||
tokenUsage,
|
||||
installCount,
|
||||
forkCount,
|
||||
status,
|
||||
identifier,
|
||||
isValidated,
|
||||
@@ -345,14 +345,14 @@ const UserAgentCard = memo<UserAgentCardProps>(
|
||||
{formatIntergerNumber(tokenUsage)}
|
||||
</Tag>
|
||||
</Tooltip>
|
||||
{installCount !== undefined && (
|
||||
{Boolean(forkCount && forkCount > 0) && (
|
||||
<Tooltip
|
||||
placement={'top'}
|
||||
styles={{ root: { pointerEvents: 'none' } }}
|
||||
title={t('assistants.downloads')}
|
||||
title={t('fork.forksCount', { count: forkCount })}
|
||||
>
|
||||
<Tag className={styles.statTag} icon={<Icon icon={DownloadIcon} />}>
|
||||
{formatIntergerNumber(installCount)}
|
||||
<Tag className={styles.statTag} icon={<Icon icon={GitForkIcon} />}>
|
||||
{formatIntergerNumber(forkCount)}
|
||||
</Tag>
|
||||
</Tooltip>
|
||||
)}
|
||||
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
DownloadIcon,
|
||||
Eye,
|
||||
EyeOff,
|
||||
GitForkIcon,
|
||||
MoreVerticalIcon,
|
||||
Pencil,
|
||||
UsersIcon,
|
||||
@@ -116,6 +117,7 @@ const UserGroupCard = memo<UserGroupCardProps>(
|
||||
description,
|
||||
createdAt,
|
||||
category,
|
||||
forkCount,
|
||||
installCount,
|
||||
identifier,
|
||||
memberCount,
|
||||
@@ -275,6 +277,17 @@ const UserGroupCard = memo<UserGroupCardProps>(
|
||||
</Tag>
|
||||
</Tooltip>
|
||||
)}
|
||||
{Boolean(forkCount && forkCount > 0) && (
|
||||
<Tooltip
|
||||
placement={'top'}
|
||||
styles={{ root: { pointerEvents: 'none' } }}
|
||||
title={t('fork.forksCount', { count: forkCount })}
|
||||
>
|
||||
<Tag className={styles.statTag} icon={<Icon icon={GitForkIcon} />}>
|
||||
{formatIntergerNumber(forkCount)}
|
||||
</Tag>
|
||||
</Tooltip>
|
||||
)}
|
||||
{installCount !== undefined && installCount > 0 && (
|
||||
<Tooltip
|
||||
placement={'top'}
|
||||
|
||||
@@ -1732,6 +1732,7 @@ export class DiscoverService {
|
||||
config: {} as any,
|
||||
createdAt: agent.createdAt,
|
||||
description: agent.description || '',
|
||||
forkCount: agent.forkCount,
|
||||
homepage: `https://lobehub.com/discover/assistant/${agent.identifier}`,
|
||||
identifier: agent.identifier,
|
||||
installCount: agent.installCount,
|
||||
@@ -1752,6 +1753,7 @@ export class DiscoverService {
|
||||
category: group.category as any,
|
||||
createdAt: group.createdAt,
|
||||
description: group.description || '',
|
||||
forkCount: group.forkCount,
|
||||
homepage: `https://lobehub.com/discover/group_agent/${group.identifier}`,
|
||||
identifier: group.identifier,
|
||||
installCount: group.installCount || 0,
|
||||
|
||||
Reference in New Issue
Block a user