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

feat: setting data-control #9

Merged
merged 2 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/app/setting/SettingClient/BtnList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const SettingBtnList = React.memo<any>(() => {
{
icon: Cog,
title: 'ๆ•ฐๆฎๆŽงๅˆถ',
href: '/setting/user-info',
href: '/setting/data-control',
},
{
icon: Settings,
Expand Down
9 changes: 6 additions & 3 deletions src/app/setting/SettingClient/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import { createStyles } from 'antd-style';

export const useStyles = createStyles(({ token }) => ({
setting: {
width: '100%',
background: token.colorBgLayout,
position: 'relative',
'width': '100%',
'background': token.colorBgLayout,
'position': 'relative',
'& > div': {
height: '100%',
},
},
content: {
maxWidth: '600px',
Expand Down
104 changes: 104 additions & 0 deletions src/app/setting/data-control/DataControlClient/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
'use client';

import { Button, Card, Flex, Switch, Table } from 'antd';
import classNames from 'classnames';
import React from 'react';

import BtnsBlock, { Btn } from '@/components/BtnsBlock';
import ReturnBtn from '@/components/ReturnBtn';

import { useStyles } from './styles';

interface Props {
user: {
name: string;
};
}

const DataControlClient: React.FC<Props> = () => {
const { styles } = useStyles();
const [checked, setChecked] = React.useState(false);

const btns1: Btn[] = React.useMemo(
() => [
{
title: '่Šๅคฉ่ฎฐๅฝ•ๅบ”็”จ',
action: (
<Switch
checked={checked}
onChange={_checked => {
setChecked(_checked);
}}
/>
),
},
],
[checked]
);
const btns_del_all: Btn[] = React.useMemo(
() => [
{
title: 'ๅˆ ้™คๆ‰€ๆœ‰่Šๅคฉ่ฎฐๅฝ•',
danger: true,
onClick: () => {
console.warn('handel del all');
},
},
],
[checked]
);
return (
<div className={classNames(styles.dataControl)}>
<div>
<ReturnBtn title="ๆ•ฐๆฎๆŽงๅˆถ" to="/setting" />
<Flex className={'scrollBar'} justify={'center'}>
<div className={classNames(styles.content)}>
<BtnsBlock
btns={btns1}
extra="ๅฐ†ๆญคๆต่งˆๅ™จไธŠ็š„ๆ–ฐ่Šๅคฉ่ฎฐๅฝ•ไฟๅญ˜ๅˆฐๆ‚จ็š„ๅŽ†ๅฒ่ฎฐๅฝ•ไธญ๏ผŒๅนถๅ…่ฎธๆˆ‘ไปฌๅบ”็”จๆ‚จ็š„่Šๅคฉ่ฎฐๅฝ•๏ผŒๆ”น่ฟ›ๆˆ‘ไปฌ็š„ๆจกๅž‹ใ€‚ๅ…ณ้—ญๅผ€ๅ…ณ๏ผŒๅฐ†ไธไผšไฟ็•™ๆ‚จ็š„่Šๅคฉ่ฎฐๅฝ•ใ€‚ๆญค่ฎพ็ฝฎไธๅœจๆต่งˆๅ™จๆˆ–่ฎพๅค‡ไน‹้—ดๅŒๆญฅใ€‚"
/>
<BtnsBlock btns={btns_del_all} />
<Card bordered={false} title="ๅˆ†ไบซ้“พๆŽฅ">
<Table
className={styles.table}
columns={[
{
dataIndex: 'name',
title: 'ๅฏน่ฏๅ็งฐ',
width: '50%',
},
{
dataIndex: 'time',
title: 'ๅˆ†ไบซๆ—ถ้—ด',
width: '50%',
},
{
dataIndex: 'opera',
title: 'ๆ“ไฝœ',
width: 120,
render: () => {
return (
<Button danger type="primary">
ๅˆ ้™ค
</Button>
);
},
},
]}
dataSource={[
{
name: 'ๅฏน่ฏ1',
time: '2024-01-01 08:08:08',
},
]}
pagination={false}
/>
</Card>
</div>
</Flex>
</div>
</div>
);
};

export default DataControlClient;
30 changes: 30 additions & 0 deletions src/app/setting/data-control/DataControlClient/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { createStyles } from 'antd-style';

export const useStyles = createStyles(({ token }) => ({
dataControl: {
'height': '100%',
'width': '100%',
'background': token.colorBgLayout,
'position': 'relative',
'& > div': {
position: 'relative',
overflow: 'hidden',
height: '100%',
paddingBottom: '40px',
paddingTop: '64px',
},
},
sub: {
width: '100%',
},
content: {
paddingTop: 16,
paddingBottom: 42,
width: 600,
},
table: {
'.ant-table-tbody > tr:last-child > td': {
borderBottom: 'unset',
},
},
}));
7 changes: 7 additions & 0 deletions src/app/setting/data-control/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { PropsWithChildren, memo } from 'react';

const Layout = memo<PropsWithChildren>(({ children }) => {
return <>{children}</>;
});

export default Layout;
17 changes: 17 additions & 0 deletions src/app/setting/data-control/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';

import { getUserData } from '../../actions/user';
import DataControlClient from './DataControlClient';

export default async function DesktopPage() {
const user = await getUserData();
const props = {
user,
};
// todo fetch server data
return (
<>
<DataControlClient {...props} />
</>
);
}
100 changes: 64 additions & 36 deletions src/components/BtnsBlock/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use client';

import { ActionIcon } from '@lobehub/ui';
import { Flex } from 'antd';
import { Button, Flex } from 'antd';
import { createStyles } from 'antd-style';
import { ChevronRight, User } from 'lucide-react';
import { ChevronRight } from 'lucide-react';
import Link from 'next/link';
import React from 'react';

export const useStyles = createStyles(() => ({
export const useStyles = createStyles(({ token }) => ({
btns: {
marginBottom: 16,
borderRadius: 16,
Expand Down Expand Up @@ -37,10 +37,18 @@ export const useStyles = createStyles(() => ({
minHeight: '56px',
},
content_left: {
flex: '1 1',
fontSize: 16,
fontWeight: '500',
lineHeight: '22px',
'flex': '1 1',
'fontSize': 16,
'fontWeight': '500',
'lineHeight': '22px',
'textAlign': 'left',
'paddingLeft': 'unset',
'&:hover': {
backgroundColor: 'inherit !important',
},
'&:hover.ant-btn-dangerous': {
color: `${token.colorError} !important`,
},
},
content_right: {
marginLeft: '8px',
Expand All @@ -53,54 +61,74 @@ export const useStyles = createStyles(() => ({
height: '20px',
},
},
extra: {
color: token.colorTextTertiary,
fontSize: token.fontSize,
transform: 'translateY(-16px)',
},
}));

export interface Btn {
icon: any;
icon?: any;
title: string;
onClick?: () => void;
href?: string;
danger?: boolean;
action?: React.ReactNode | string; // action ๅ’Œ href ไบŒ้€‰ไธ€
icon_bg?: string;
}

export interface BtnsBlockProps {
btns: Btn[];
extra?: string;
}

const BtnsBlock = React.memo<BtnsBlockProps>(props => {
const { styles, theme } = useStyles();
const { btns } = props;
const { btns, extra } = props;
return (
<div className={styles.btns}>
{btns.map((item, idx) => {
const icon = item.icon || User;
const icon_bg = item.icon_bg || theme.colorPrimary;
const key = item.title + idx;
const children = (
<Flex align={'center'} className={styles.btn} key={key}>
<div className={styles.icon} style={{ backgroundColor: icon_bg }}>
<ActionIcon color={'white'} icon={icon} />
</div>
<Flex align={'center'} className={styles.content}>
<div className={styles.content_left}>{item.title || '้ป˜่ฎคๆ ‡้ข˜'}</div>
{item.href ? (
<Flex align={'center'} className={styles.content_right}>
<ChevronRight color={'rgb(204, 204, 204)'} />
</Flex>
<>
<div className={styles.btns}>
{btns.map((item, idx) => {
const icon = item.icon;
const icon_bg = item.icon_bg || theme.colorPrimary;
const key = item.title + idx;
const children = (
<Flex align={'center'} className={styles.btn} key={key} onClick={item.onClick}>
{icon ? (
<div className={styles.icon} style={{ backgroundColor: icon_bg }}>
<ActionIcon color={'white'} icon={icon} />
</div>
) : null}
<Flex align={'center'} className={styles.content}>
<Button className={styles.content_left} danger={item.danger} type="text">
{item.title || '้ป˜่ฎคๆ ‡้ข˜'}
</Button>
{item.href ? (
<Flex align={'center'} className={styles.content_right}>
<ChevronRight color={'rgb(204, 204, 204)'} />
</Flex>
) : null}
{item.action ? (
<Flex align={'center'} className={styles.content_right}>
{item.action}
</Flex>
) : null}
</Flex>
</Flex>
</Flex>
);
if (item.href) {
return (
<Link className={styles.linkWrapper} href={item.href} key={'link-wrapper-' + key}>
{children}
</Link>
);
}
return children;
})}
</div>
if (item.href) {
return (
<Link className={styles.linkWrapper} href={item.href} key={'link-wrapper-' + key}>
{children}
</Link>
);
}
return children;
})}
</div>
{extra ? <div className={styles.extra}>{extra}</div> : null}
</>
);
});

Expand Down
2 changes: 1 addition & 1 deletion src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useMemo } from 'react';
let store: any;

const initialState = {
theme: localStorage.getItem('theme') || 'light', // todo remove: use server
theme: typeof window === 'undefined' ? 'light' : localStorage.getItem('theme') || 'light', // todo remove: use server
activeChat: 'name',
};

Expand Down
Loading