Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ refactor: Refactor Market Layout #2320

Merged
merged 8 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions src/app/(main)/market/(desktop)/index.tsx

This file was deleted.

31 changes: 0 additions & 31 deletions src/app/(main)/market/(mobile)/features/AgentCard.tsx

This file was deleted.

25 changes: 0 additions & 25 deletions src/app/(main)/market/(mobile)/index.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
'use client';

import { DraggablePanel, DraggablePanelBody, DraggablePanelContainer } from '@lobehub/ui';
import { createStyles } from 'antd-style';
import { memo, useCallback, useState } from 'react';
import { createStyles, useResponsive } from 'antd-style';
import { PropsWithChildren, memo, useCallback, useState } from 'react';
import { Flexbox } from 'react-layout-kit';

import SafeSpacing from '@/components/SafeSpacing';
import { MARKET_SIDEBAR_WIDTH } from '@/const/layoutTokens';
import { agentMarketSelectors, useMarketStore } from '@/store/market';

import AgentDetailContent from '../../features/AgentDetailContent';

const useStyles = createStyles(({ css, token, stylish }) => ({
content: css`
display: flex;
Expand All @@ -23,8 +24,9 @@ const useStyles = createStyles(({ css, token, stylish }) => ({
noScrollbar: stylish.noScrollbar,
}));

const SideBar = memo(() => {
const SideBar = memo<PropsWithChildren>(({ children }) => {
const { styles } = useStyles();
const { md = true } = useResponsive();
canisminor1990 marked this conversation as resolved.
Show resolved Hide resolved
const [tempId, setTempId] = useState<string>('');
const [showAgentSidebar, deactivateAgent, activateAgent] = useMarketStore((s) => [
agentMarketSelectors.showSideBar(s),
Expand All @@ -44,15 +46,18 @@ const SideBar = memo(() => {
[deactivateAgent, activateAgent, tempId],
);

const minWidth = md ? MARKET_SIDEBAR_WIDTH : 350;

return (
<DraggablePanel
className={styles.drawer}
classNames={{
content: styles.content,
}}
expand={showAgentSidebar}
minWidth={MARKET_SIDEBAR_WIDTH}
mode={'fixed'}
maxWidth={'80vw' as any}
minWidth={minWidth}
mode={md ? 'fixed' : 'float'}
onExpandChange={handleExpandChange}
placement={'right'}
showHandlerWideArea={false}
Expand All @@ -61,15 +66,15 @@ const SideBar = memo(() => {
style={{
flex: 'none',
height: '100%',
minWidth: MARKET_SIDEBAR_WIDTH,
minWidth: minWidth,
}}
>
<SafeSpacing />
{md && <SafeSpacing />}
<DraggablePanelBody
className={styles.noScrollbar}
style={{ padding: 0, position: 'relative' }}
>
<AgentDetailContent />
<Flexbox>{children}</Flexbox>
</DraggablePanelBody>
</DraggablePanelContainer>
</DraggablePanel>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use client';

import { Modal } from '@lobehub/ui';
import { memo } from 'react';
import { PropsWithChildren, memo } from 'react';
import { useTranslation } from 'react-i18next';

import { agentMarketSelectors, useMarketStore } from '@/store/market';

import AgentDetailContent from '../../features/AgentDetailContent';

const AgentDetail = memo(() => {
const AgentDetail = memo<PropsWithChildren>(({ children }) => {
const [showAgentSidebar, deactivateAgent] = useMarketStore((s) => [
agentMarketSelectors.showSideBar(s),
s.deactivateAgent,
Expand All @@ -17,12 +17,14 @@ const AgentDetail = memo(() => {
return (
<Modal
allowFullscreen
onCancel={deactivateAgent}
onCancel={() => {
deactivateAgent();
}}
open={showAgentSidebar}
styles={{ body: { padding: 0 } }}
title={t('sidebar.title')}
>
<AgentDetailContent />
{children}
</Modal>
);
});
Expand Down
19 changes: 19 additions & 0 deletions src/app/(main)/market/@detail/default.tsx
canisminor1990 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import ServerLayout from '@/components/server/ServerLayout';

import Desktop from './_layout/Desktop';
import Mobile from './_layout/Mobile';
import AgentDetailContent from './features/AgentDetailContent';

const Layout = ServerLayout({ Desktop, Mobile });

const Detail = () => {
return (
<Layout>
<AgentDetailContent />
</Layout>
);
};

Detail.displayName = 'AgentDetail';

export default Detail;
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Avatar, Tag } from '@lobehub/ui';
import { App, Button, Typography } from 'antd';
import { startCase } from 'lodash-es';
import { isEqual, startCase } from 'lodash-es';
canisminor1990 marked this conversation as resolved.
Show resolved Hide resolved
import { useRouter } from 'next/navigation';
import { memo } from 'react';
import { useTranslation } from 'react-i18next';
import { Center } from 'react-layout-kit';

import { useSearch } from '@/app/(main)/market/hooks/useSearch';
import { SESSION_CHAT_URL } from '@/const/url';
import { useIsMobile } from '@/hooks/useIsMobile';
import { agentMarketSelectors, useMarketStore } from '@/store/market';
Expand All @@ -16,11 +17,13 @@ import { useStyles } from './style';
const { Link } = Typography;

const Header = memo(() => {
const search = useSearch();
const router = useRouter();
const { t } = useTranslation('market');
const { styles, theme } = useStyles();
const createSession = useSessionStore((s) => s.createSession);
const agentItem = useMarketStore(agentMarketSelectors.currentAgentItem);
const agentItem = useMarketStore(agentMarketSelectors.currentAgentItem, isEqual);

const { message } = App.useApp();

const { meta, createAt, author, homepage, config } = agentItem;
Expand All @@ -38,7 +41,6 @@ const Header = memo(() => {

const handleAddAgent = () => {
if (!agentItem) return;

createSession({ config, meta }, false);
message.success(t('addAgentSuccess'));
};
Expand All @@ -55,11 +57,7 @@ const Header = memo(() => {
<div className={styles.title}>{title}</div>
<Center gap={6} horizontal style={{ flexWrap: 'wrap' }}>
{(tags as string[]).map((tag: string, index) => (
<Tag
key={index}
onClick={() => useMarketStore.setState({ searchKeywords: tag })}
style={{ margin: 0 }}
>
<Tag key={index} onClick={() => search(tag)} style={{ margin: 0 }}>
{startCase(tag).trim()}
</Tag>
))}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
'use client';

import { Markdown, TabsNav } from '@lobehub/ui';
import { memo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { Flexbox } from 'react-layout-kit';

import AgentCardBanner from '@/app/(main)/market/features/AgentCard/AgentCardBanner';
import { useMarketStore } from '@/store/market';

import AgentCardBanner from '../../../features/AgentCard/AgentCardBanner';
import Comment from './Comment';
import Header from './Header';
import Loading from './Loading';
Expand Down
9 changes: 3 additions & 6 deletions src/app/(main)/market/_layout/Desktop/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client';

import { ChatHeader, Logo } from '@lobehub/ui';
import { createStyles } from 'antd-style';
import Link from 'next/link';
import { memo } from 'react';

import ShareAgentButton from '../../features/ShareAgentButton';
Expand All @@ -17,11 +18,7 @@ const Header = memo(() => {

return (
<ChatHeader
left={
<Link aria-label={'home'} href={'/'}>
<Logo className={styles.logo} extra={'Discover'} size={36} type={'text'} />
</Link>
}
left={<Logo className={styles.logo} extra={'Discover'} size={36} type={'text'} />}
right={<ShareAgentButton />}
/>
);
Expand Down
39 changes: 39 additions & 0 deletions src/app/(main)/market/_layout/Desktop/Hero.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use client';

import { GridBackground } from '@lobehub/ui';
import { createStyles } from 'antd-style';
import { memo } from 'react';
import { Center } from 'react-layout-kit';

const useStyles = createStyles(({ css, responsive }) => ({
background: css`
width: 80%;
margin: -60px 0 -20px;

${responsive.md} {
display: none;
}
`,
title: css`
z-index: 2;

margin-top: 24px;

font-size: min(56px, 6vw);
font-weight: 800;
line-height: 1.2;
text-align: center;
`,
}));

const Hero = memo(() => {
const { theme, styles } = useStyles();
return (
<Center>
<h1 className={styles.title}>Find & Use The Best Agents</h1>
<GridBackground animation className={styles.background} colorFront={theme.colorText} random />
</Center>
);
});

export default Hero;
Loading
Loading