Skip to content

Commit

Permalink
✨ feat: 添加我的 Tab
Browse files Browse the repository at this point in the history
  • Loading branch information
rdmclin2 committed Apr 17, 2024
1 parent 5a5c034 commit ceddadb
Show file tree
Hide file tree
Showing 15 changed files with 234 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/app/market/SideBar/MarketList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export interface MarketListProps {

const MarketList = memo<MarketListProps>(({ activeTab, mobile }) => {
const items = [
{ icon: Bot, label: '角色', value: MarketTabs.Agent },
{ icon: Mic2, label: '跳舞', value: MarketTabs.Dance },
{ icon: Bot, label: '角色订阅', value: MarketTabs.Agent },
{ icon: Mic2, label: '舞蹈订阅', value: MarketTabs.Dance },
];

return items.map(({ value, icon, label }) => (
Expand Down
21 changes: 21 additions & 0 deletions src/app/my/Redirect.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use client';

import { useRouter } from 'next/navigation';
import { useEffect } from 'react';

const Redirect = () => {
const router = useRouter();

useEffect(() => {
// const hasData = localStorage.getItem('V_IDOL_WELCOME');
// if (hasData) {
router.push('/my/agent');
// } else {
// router.push('/welcome');
// }
}, []);

return null;
};

export default Redirect;
50 changes: 50 additions & 0 deletions src/app/my/SideBar/MyList/Item.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Icon, List } from '@lobehub/ui';
import { createStyles, useResponsive } from 'antd-style';
import { ChevronRight, type LucideIcon } from 'lucide-react';
import { CSSProperties, ReactNode, memo } from 'react';

const { Item } = List;

const useStyles = createStyles(({ css, token, responsive }) => ({
container: css`
position: relative;
padding-top: 16px;
padding-bottom: 16px;
border-radius: ${token.borderRadius}px;
${responsive.mobile} {
border-radius: 0;
}
`,
noHover: css`
pointer-events: none;
`,
}));

export interface ItemProps {
active?: boolean;
className?: string;
hoverable?: boolean;
icon: LucideIcon;
label: ReactNode;
style?: CSSProperties;
}

const SettingItem = memo<ItemProps>(
({ label, icon, hoverable = true, active = false, style, className }) => {
const { cx, styles } = useStyles();
const { mobile } = useResponsive();
return (
<Item
active={active}
avatar={<Icon icon={icon} size={{ fontSize: 20 }} />}
className={cx(styles.container, !hoverable && styles.noHover, className)}
style={style}
title={label as string}
>
{mobile && <Icon icon={ChevronRight} size={{ fontSize: 16 }} />}
</Item>
);
},
);

export default SettingItem;
31 changes: 31 additions & 0 deletions src/app/my/SideBar/MyList/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Bot, Mic2 } from 'lucide-react';
import Link from 'next/link';
import { memo } from 'react';

import { MyTabs } from '../type';
import Item from './Item';

export interface MyListProps {
activeTab?: MyTabs;
mobile?: boolean;
}

const MyList = memo<MyListProps>(({ activeTab, mobile }) => {
const items = [
{ icon: Bot, label: '我的角色', value: MyTabs.Agent },
{ icon: Mic2, label: '我的舞蹈', value: MyTabs.Dance },
];

return items.map(({ value, icon, label }) => (
<Link aria-label={label} href={`/my/${value}`} key={value}>
<Item
active={mobile ? false : activeTab === value}
hoverable={!mobile}
icon={icon}
label={label}
/>
</Link>
));
});

export default MyList;
37 changes: 37 additions & 0 deletions src/app/my/SideBar/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { createStyles, useResponsive } from 'antd-style';
import { memo } from 'react';
import { Flexbox } from 'react-layout-kit';

import MyList, { MyListProps } from './MyList';

const useStyles = createStyles(({ token, css }) => ({
container: css`
border-inline-end: 1px solid ${token.colorBorder};
`,
logo: css`
fill: ${token.colorText};
`,
top: css`
font-size: 20px;
font-weight: bold;
`,
}));

const SideBar = memo<MyListProps>(({ activeTab }) => {
const { styles } = useStyles();

const { mobile } = useResponsive();

return (
<Flexbox className={styles.container} width={280}>
<Flexbox className={styles.top} padding={16}>
我的
</Flexbox>
<Flexbox gap={8} style={{ paddingInline: 8 }}>
<MyList activeTab={activeTab} mobile={mobile} />
</Flexbox>
</Flexbox>
);
});

export default SideBar;
4 changes: 4 additions & 0 deletions src/app/my/SideBar/type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum MyTabs {
Agent = 'agent',
Dance = 'dance',
}
9 changes: 9 additions & 0 deletions src/app/my/agent/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { PropsWithChildren } from 'react';

import { MyTabs } from '@/app/my/SideBar/type';

import MyLayout from '../layout.desktop';

export default ({ children }: PropsWithChildren) => {
return <MyLayout activeTab={MyTabs.Agent}>{children}</MyLayout>;
};
11 changes: 11 additions & 0 deletions src/app/my/agent/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use client';

import React from 'react';

import MyAgent from '@/panels/AgentPanel/Agent';

const Market = () => {
return <MyAgent />;
};

export default Market;
9 changes: 9 additions & 0 deletions src/app/my/dance/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { PropsWithChildren } from 'react';

import { MyTabs } from '@/app/my/SideBar/type';

import MyLayout from '../layout.desktop';

export default ({ children }: PropsWithChildren) => {
return <MyLayout activeTab={MyTabs.Dance}>{children}</MyLayout>;
};
11 changes: 11 additions & 0 deletions src/app/my/dance/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use client';

import React from 'react';

import MyDance from '@/panels/DancePanel/Dance';

const Market = () => {
return <MyDance />;
};

export default Market;
26 changes: 26 additions & 0 deletions src/app/my/layout.desktop.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use client';

import { ReactNode } from 'react';
import { Flexbox } from 'react-layout-kit';

import SideBar from '@/app/my/SideBar';
import { MyTabs } from '@/app/my/SideBar/type';

export interface LayoutProps {
activeTab: MyTabs;
children?: ReactNode;
}

const LayoutDesktop = (props: LayoutProps) => {
const { children, activeTab } = props;
return (
<Flexbox flex={1} height={'100%'} width={'100%'} style={{ position: 'relative' }} horizontal>
<SideBar activeTab={activeTab} />
<Flexbox align={'center'} flex={1} style={{ overflow: 'scroll' }}>
{children}
</Flexbox>
</Flexbox>
);
};

export default LayoutDesktop;
5 changes: 5 additions & 0 deletions src/app/my/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Redirect from '@/app/my/Redirect';

const Index = () => <Redirect />;

export default Index;
12 changes: 12 additions & 0 deletions src/app/my/style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { createStyles } from 'antd-style';

export const useStyles = createStyles(({ css }) => ({
content: css`
display: flex;
flex-direction: row;
flex-grow: 1;
width: 100%;
height: 100%;
`,
}));
6 changes: 5 additions & 1 deletion src/layout/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const Header = () => {
items={[
{
key: 'home',
label: '首页',
label: '互动',
},
{
key: 'chat',
Expand All @@ -36,6 +36,10 @@ const Header = () => {
key: 'market',
label: '发现',
},
{
key: 'my',
label: '我的',
},
]}
onChange={(key) => {
setActiveKey(key);
Expand Down
2 changes: 1 addition & 1 deletion src/panels/DancePanel/Dance/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const Dance = (props: DanceProps) => {
return (
<div className={classNames(className, styles.container)} style={style}>
<div className={styles.content}>
<TopBanner title={"Let's Dance"} />
<TopBanner title={"Hi, Let's Dance!"} />
<DanceList setTab={setTab} />
</div>
<DanceCard />
Expand Down

0 comments on commit ceddadb

Please sign in to comment.