Skip to content

Commit

Permalink
✨ feat(options): 优化选项项设计
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Jan 26, 2021
1 parent c4bad83 commit 6c551c3
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 23 deletions.
9 changes: 0 additions & 9 deletions src/pages/options/App.less

This file was deleted.

33 changes: 33 additions & 0 deletions src/pages/options/Token/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React, { useContext } from 'react';
import { Button, Input, Space } from 'antd';

import { YuqueTokenService } from '@/services';

import styles from './style.less';

const Token = () => {
const { setYuqueToken, token, syncToCloudStorage } = useContext(
YuqueTokenService,
);

return (
<div className={styles.container}>
<Space direction={'vertical'} style={{ display: 'flex' }}>
语雀 Token:
<Input
placeholder={'token'}
value={token}
onChange={(e) => {
setYuqueToken(e.target.value);
}}
onPressEnter={syncToCloudStorage}
/>
<Button type={'primary'} onClick={syncToCloudStorage}>
保存
</Button>
</Space>
</div>
);
};

export default Token;
5 changes: 5 additions & 0 deletions src/pages/options/Token/style.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@import '~theme/index';

.container {
//display: flex;
}
53 changes: 41 additions & 12 deletions src/pages/options/index.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,52 @@
import React from 'react';
import { Button, Input } from 'antd';
import { Menu } from 'antd';
import {
BulbOutlined,
FontColorsOutlined,
KeyOutlined,
SearchOutlined,
} from '@ant-design/icons';

import { useYuqueTokenService, YuqueTokenService } from '@/services';
import Token from './Token';

import './App.less';
import styles from './style.less';

const App = () => {
const yuqueTokenService = useYuqueTokenService();
const { setYuqueToken, token, syncToCloudStorage } = yuqueTokenService;

return (
<YuqueTokenService.Provider value={yuqueTokenService}>
语雀 Token:
<Input
placeholder={'token'}
value={token}
onChange={(e) => {
setYuqueToken(e.target.value);
}}
/>
<Button onClick={syncToCloudStorage}>保存</Button>
<div className={styles.container}>
<h4>Power Yuque 配置面板</h4>
<div className={styles.card}>
<Menu
mode="inline"
className={styles.menu}
defaultSelectedKeys={['token']}
>
<Menu.Item key="token">
<KeyOutlined /> 语雀 Token
</Menu.Item>
<Menu.Item key="typographic">
<FontColorsOutlined />
排版配置
</Menu.Item>

<Menu.Item key="dark">
<BulbOutlined />
深色模式
</Menu.Item>
<Menu.Item key="12">
<SearchOutlined /> 搜索框
</Menu.Item>
</Menu>

<div className={styles.content}>
<Token />
</div>
</div>
</div>
</YuqueTokenService.Provider>
);
};
Expand Down
24 changes: 24 additions & 0 deletions src/pages/options/style.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@import '~theme/index';

.container {
height: 100vh;
padding: 24px;
background: @background-color-base;
}

.menu {
width: 200px;
min-height: 400px;
padding-top: 12px;
}

.card {
display: flex;
background: @white;
border-radius: 4px;
}

.content {
width: 100%;
padding: 24px;
}
6 changes: 4 additions & 2 deletions src/services/useYuqueTokenService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useLocalStorageState } from 'ahooks';
import { getServiceToken } from '@/utils';
import { useCallback, useEffect } from 'react';
import { message } from 'antd';

/**
* Yuque Token
Expand All @@ -10,13 +11,14 @@ export const useYuqueTokenService = () => {
const [token, setYuqueToken] = useLocalStorageState('yuque_token', '');

const syncToCloudStorage = useCallback(() => {
chrome.storage.sync.set({ yuque_token: token }, () => {
chrome.storage?.sync.set({ yuque_token: token }, () => {
chrome.storage.sync.get(console.log);
});
message.success('保存成功');
}, [token]);

useEffect(() => {
chrome.storage.sync.get((data) => {
chrome.storage?.sync.get((data) => {
console.log(data);
if (data.yuque_token !== token) {
setYuqueToken(data.yuque_token);
Expand Down

0 comments on commit 6c551c3

Please sign in to comment.