Skip to content

Commit 11587b5

Browse files
committed
refactor(web): 笔记面板增加编辑按钮,方便直接进行编辑对应笔记
1 parent ed46714 commit 11587b5

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
lines changed

src/web/components/panels/CommonHeader.tsx

+12-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ const Container = styled.div`
1111
justify-content: space-between;
1212
1313
${(props) => props.theme.mixins.mobile('padding: 8px 0;')}
14+
15+
> div {
16+
display: flex;
17+
align-items: center;
18+
}
1419
`;
1520

1621
const HeaderPrefix = styled.span`
@@ -23,6 +28,10 @@ const HeaderText = styled.span`
2328
line-height: 28px;
2429
`;
2530

31+
const HeaderSuffix = styled.span`
32+
margin-left: 8px;
33+
`;
34+
2635
const HeaderActionContainer = styled(Space)`
2736
${(props) =>
2837
props.theme.mixins.mobile('width: 100%;justify-content: flex-end;')}
@@ -31,18 +40,18 @@ const HeaderActionContainer = styled(Space)`
3140
interface CommonHeaderProps {
3241
headerPrefix?: React.ReactNode;
3342
headerActions?: React.ReactNode[];
43+
headerSuffix?: React.ReactNode;
3444
}
3545
export const CommonHeader: React.FC<CommonHeaderProps> = TMemo((props) => {
36-
const { headerActions } = props;
37-
3846
return (
3947
<SectionHeader>
4048
<Container>
4149
<div>
4250
<HeaderPrefix>{props.headerPrefix}</HeaderPrefix>
4351
<HeaderText>{props.children}</HeaderText>
52+
<HeaderSuffix>{props.headerSuffix}</HeaderSuffix>
4453
</div>
45-
<HeaderActionContainer>{headerActions}</HeaderActionContainer>
54+
<HeaderActionContainer>{props.headerActions}</HeaderActionContainer>
4655
</Container>
4756
</SectionHeader>
4857
);

src/web/components/panels/CommonPanel.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ interface CommonPanelProps {
3737
style?: React.CSSProperties;
3838
headerPrefix?: React.ReactNode;
3939
headerActions?: React.ReactNode[];
40+
headerSuffix?: React.ReactNode;
4041
rightPanel?: React.ReactNode;
4142
}
4243
export const CommonPanel: React.FC<CommonPanelProps> = TMemo((props) => {
@@ -45,6 +46,7 @@ export const CommonPanel: React.FC<CommonPanelProps> = TMemo((props) => {
4546
<CommonHeader
4647
headerPrefix={props.headerPrefix}
4748
headerActions={props.headerActions}
49+
headerSuffix={props.headerSuffix}
4850
>
4951
{props.header}
5052
</CommonHeader>

src/web/components/panels/NotePanel.tsx

+28-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,35 @@
1-
import React from 'react';
1+
import React, { useCallback } from 'react';
22
import { TMemo } from '@shared/components/TMemo';
33
import { CommonPanelProps } from '@shared/components/panel/type';
44
import { useAsync } from 'react-use';
55
import _isString from 'lodash/isString';
66
import _isNil from 'lodash/isNil';
77
import { fetchNoteInfo } from '@shared/model/note';
8-
import { Result } from 'antd';
8+
import { Result, Tooltip } from 'antd';
99
import LoadingSpinner from '../LoadingSpinner';
1010
import { useTranslation } from '@shared/i18n';
1111
import { Previewer } from '../editor/Previewer';
1212
import { CommonPanel } from './CommonPanel';
13+
import { Iconfont } from '../Iconfont';
14+
import { Link } from 'react-router-dom';
15+
import { useNoteInfo } from '@redux/hooks/note';
16+
17+
function useNoteEditBtn(noteUUID: string): React.ReactElement | null {
18+
const { t } = useTranslation();
19+
const noteInfo = useNoteInfo(noteUUID);
20+
21+
if (_isNil(noteInfo)) {
22+
return null;
23+
}
24+
25+
return (
26+
<Tooltip title={t('编辑')}>
27+
<Link style={{ color: 'inherit' }} to={`/main/personal/note/${noteUUID}`}>
28+
<Iconfont>&#xe602;</Iconfont>
29+
</Link>
30+
</Tooltip>
31+
);
32+
}
1333

1434
/**
1535
* 团笔记面板
@@ -18,6 +38,7 @@ export const NotePanel: React.FC<CommonPanelProps> = TMemo((props) => {
1838
const { panel } = props;
1939
const noteUUID = panel.target_uuid;
2040
const { t } = useTranslation();
41+
const noteEditBtn = useNoteEditBtn(noteUUID);
2142

2243
const { loading, value, error } = useAsync(async () => {
2344
if (!_isString(noteUUID)) {
@@ -34,7 +55,11 @@ export const NotePanel: React.FC<CommonPanelProps> = TMemo((props) => {
3455

3556
if (!_isNil(value)) {
3657
return (
37-
<CommonPanel headerPrefix="#" header={panel.name}>
58+
<CommonPanel
59+
headerPrefix="#"
60+
header={panel.name}
61+
headerSuffix={noteEditBtn}
62+
>
3863
<div style={{ padding: 10 }}>
3964
<Previewer value={value.data as any} />
4065
</div>

0 commit comments

Comments
 (0)