1
- import React from 'react' ;
1
+ import React , { useCallback } from 'react' ;
2
2
import { TMemo } from '@shared/components/TMemo' ;
3
3
import { CommonPanelProps } from '@shared/components/panel/type' ;
4
4
import { useAsync } from 'react-use' ;
5
5
import _isString from 'lodash/isString' ;
6
6
import _isNil from 'lodash/isNil' ;
7
7
import { fetchNoteInfo } from '@shared/model/note' ;
8
- import { Result } from 'antd' ;
8
+ import { Result , Tooltip } from 'antd' ;
9
9
import LoadingSpinner from '../LoadingSpinner' ;
10
10
import { useTranslation } from '@shared/i18n' ;
11
11
import { Previewer } from '../editor/Previewer' ;
12
12
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 > </ Iconfont >
29
+ </ Link >
30
+ </ Tooltip >
31
+ ) ;
32
+ }
13
33
14
34
/**
15
35
* 团笔记面板
@@ -18,6 +38,7 @@ export const NotePanel: React.FC<CommonPanelProps> = TMemo((props) => {
18
38
const { panel } = props ;
19
39
const noteUUID = panel . target_uuid ;
20
40
const { t } = useTranslation ( ) ;
41
+ const noteEditBtn = useNoteEditBtn ( noteUUID ) ;
21
42
22
43
const { loading, value, error } = useAsync ( async ( ) => {
23
44
if ( ! _isString ( noteUUID ) ) {
@@ -34,7 +55,11 @@ export const NotePanel: React.FC<CommonPanelProps> = TMemo((props) => {
34
55
35
56
if ( ! _isNil ( value ) ) {
36
57
return (
37
- < CommonPanel headerPrefix = "#" header = { panel . name } >
58
+ < CommonPanel
59
+ headerPrefix = "#"
60
+ header = { panel . name }
61
+ headerSuffix = { noteEditBtn }
62
+ >
38
63
< div style = { { padding : 10 } } >
39
64
< Previewer value = { value . data as any } />
40
65
</ div >
0 commit comments