Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
9db1f573
Commit
9db1f573
authored
Dec 12, 2021
by
steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
web: recover single global memo editor
parent
5e84a577
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
34 deletions
+21
-34
MemoEditor.tsx
web/src/components/MemoEditor.tsx
+18
-21
MemoList.tsx
web/src/components/MemoList.tsx
+3
-8
memolist.less
web/src/less/memolist.less
+0
-5
No files found.
web/src/components/MemoEditor.tsx
View file @
9db1f573
...
@@ -7,36 +7,31 @@ import toastHelper from "./Toast";
...
@@ -7,36 +7,31 @@ import toastHelper from "./Toast";
import
Editor
,
{
EditorRefActions
}
from
"./Editor/Editor"
;
import
Editor
,
{
EditorRefActions
}
from
"./Editor/Editor"
;
import
"../less/memo-editor.less"
;
import
"../less/memo-editor.less"
;
interface
Props
{
interface
Props
{}
className
?:
string
;
editMemoId
?:
string
;
}
const
MemoEditor
:
React
.
FC
<
Props
>
=
(
props
:
Props
)
=>
{
const
MemoEditor
:
React
.
FC
<
Props
>
=
()
=>
{
const
{
className
,
editMemoId
}
=
props
;
const
{
globalState
}
=
useContext
(
appContext
);
const
{
globalState
}
=
useContext
(
appContext
);
const
editorRef
=
useRef
<
EditorRefActions
>
(
null
);
const
editorRef
=
useRef
<
EditorRefActions
>
(
null
);
const
prevGlobalStateRef
=
useRef
(
globalState
);
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
globalState
.
markMemoId
)
{
if
(
globalState
.
markMemoId
)
{
if
(
editMemoId
===
globalState
.
editMemoId
||
(
!
editMemoId
&&
!
globalState
.
editMemoId
))
{
const
editorCurrentValue
=
editorRef
.
current
?.
getContent
();
const
editorCurrentValue
=
editorRef
.
current
?.
getContent
();
const
memoLinkText
=
`
${
editorCurrentValue
?
"
\n
"
:
""
}
Mark: [@MEMO](
${
globalState
.
markMemoId
}
)`
;
const
memoLinkText
=
`
${
editorCurrentValue
?
"
\n
"
:
""
}
Mark: [@MEMO](
${
globalState
.
markMemoId
}
)`
;
editorRef
.
current
?.
insertText
(
memoLinkText
);
editorRef
.
current
?.
insertText
(
memoLinkText
);
globalStateService
.
setMarkMemoId
(
""
);
globalStateService
.
setMarkMemoId
(
""
);
}
}
}
},
[
globalState
.
markMemoId
]);
useEffect
(()
=>
{
if
(
globalState
.
editMemoId
&&
globalState
.
editMemoId
!==
prevGlobalStateRef
.
current
.
editMemoId
)
{
if
(
editMemoId
)
{
const
editMemo
=
memoService
.
getMemoById
(
globalState
.
editMemoId
);
const
editMemo
=
memoService
.
getMemoById
(
editMemoId
);
if
(
editMemo
)
{
if
(
editMemo
)
{
editorRef
.
current
?.
setContent
(
editMemo
.
content
??
""
);
editorRef
.
current
?.
setContent
(
editMemo
.
content
??
""
);
editorRef
.
current
?.
focus
();
editorRef
.
current
?.
focus
();
}
}
}
}
},
[
editMemoId
]);
prevGlobalStateRef
.
current
=
globalState
;
},
[
globalState
.
markMemoId
,
globalState
.
editMemoId
]);
const
handleSaveBtnClick
=
useCallback
(
async
(
content
:
string
)
=>
{
const
handleSaveBtnClick
=
useCallback
(
async
(
content
:
string
)
=>
{
if
(
content
===
""
)
{
if
(
content
===
""
)
{
...
@@ -44,6 +39,8 @@ const MemoEditor: React.FC<Props> = (props: Props) => {
...
@@ -44,6 +39,8 @@ const MemoEditor: React.FC<Props> = (props: Props) => {
return
;
return
;
}
}
const
{
editMemoId
}
=
globalStateService
.
getState
();
content
=
content
.
replaceAll
(
" "
,
" "
);
content
=
content
.
replaceAll
(
" "
,
" "
);
try
{
try
{
...
@@ -83,7 +80,7 @@ const MemoEditor: React.FC<Props> = (props: Props) => {
...
@@ -83,7 +80,7 @@ const MemoEditor: React.FC<Props> = (props: Props) => {
setEditorContentCache
(
content
);
setEditorContentCache
(
content
);
},
[]);
},
[]);
const
showEditStatus
=
Boolean
(
editMemoId
);
const
showEditStatus
=
Boolean
(
globalState
.
editMemoId
);
const
editorConfig
=
useMemo
(
const
editorConfig
=
useMemo
(
()
=>
({
()
=>
({
...
@@ -97,12 +94,12 @@ const MemoEditor: React.FC<Props> = (props: Props) => {
...
@@ -97,12 +94,12 @@ const MemoEditor: React.FC<Props> = (props: Props) => {
onCancelBtnClick
:
handleCancelBtnClick
,
onCancelBtnClick
:
handleCancelBtnClick
,
onContentChange
:
handleContentChange
,
onContentChange
:
handleContentChange
,
}),
}),
[
editMemoId
]
[
showEditStatus
]
);
);
return
(
return
(
<
div
className=
{
`memo-editor-wrapper ${className} ${editMemoId ? "edit-ing" : ""}`
}
>
<
div
className=
{
"memo-editor-wrapper "
+
(
showEditStatus
?
"edit-ing"
:
""
)
}
>
<
p
className=
{
"tip-text "
+
(
editMemoId
?
""
:
"hidden"
)
}
>
正在修改中...
</
p
>
<
p
className=
{
"tip-text "
+
(
showEditStatus
?
""
:
"hidden"
)
}
>
正在修改中...
</
p
>
<
Editor
ref=
{
editorRef
}
{
...
editorConfig
}
/>
<
Editor
ref=
{
editorRef
}
{
...
editorConfig
}
/>
</
div
>
</
div
>
);
);
...
...
web/src/components/MemoList.tsx
View file @
9db1f573
...
@@ -6,7 +6,6 @@ import utils from "../helpers/utils";
...
@@ -6,7 +6,6 @@ import utils from "../helpers/utils";
import
{
checkShouldShowMemoWithFilters
}
from
"../helpers/filter"
;
import
{
checkShouldShowMemoWithFilters
}
from
"../helpers/filter"
;
import
Memo
from
"./Memo"
;
import
Memo
from
"./Memo"
;
import
toastHelper
from
"./Toast"
;
import
toastHelper
from
"./Toast"
;
import
MemoEditor
from
"./MemoEditor"
;
import
"../less/memolist.less"
;
import
"../less/memolist.less"
;
interface
Props
{}
interface
Props
{}
...
@@ -95,13 +94,9 @@ const MemoList: React.FC<Props> = () => {
...
@@ -95,13 +94,9 @@ const MemoList: React.FC<Props> = () => {
return (
return (
<
div
className=
{
`memolist-wrapper ${isFetching ? "" : "completed"}`
}
onClick=
{
handleMemoListClick
}
ref=
{
wrapperElement
}
>
<
div
className=
{
`memolist-wrapper ${isFetching ? "" : "completed"}`
}
onClick=
{
handleMemoListClick
}
ref=
{
wrapperElement
}
>
{
shownMemos
.
map
((
memo
)
=>
{
shownMemos
.
map
((
memo
)
=>
(
globalState
.
editMemoId
===
memo
.
id
?
(
<
Memo
key=
{
`${memo.id}-${memo.updatedAt}`
}
memo=
{
memo
}
/>
<
MemoEditor
key=
{
memo
.
id
}
className=
"memo-edit"
editMemoId=
{
memo
.
id
}
/>
))
}
)
:
(
<
Memo
key=
{
`${memo.id}-${memo.updatedAt}`
}
memo=
{
memo
}
/>
)
)
}
<
div
className=
"status-text-container"
>
<
div
className=
"status-text-container"
>
<
p
className=
"status-text"
>
<
p
className=
"status-text"
>
{
isFetching
?
"努力请求数据中..."
:
shownMemos
.
length
===
0
?
"空空如也"
:
showMemoFilter
?
""
:
"所有数据加载完啦 🎉"
}
{
isFetching
?
"努力请求数据中..."
:
shownMemos
.
length
===
0
?
"空空如也"
:
showMemoFilter
?
""
:
"所有数据加载完啦 🎉"
}
...
...
web/src/less/memolist.less
View file @
9db1f573
...
@@ -7,11 +7,6 @@
...
@@ -7,11 +7,6 @@
overflow-y: scroll;
overflow-y: scroll;
.hide-scroll-bar();
.hide-scroll-bar();
> .memo-edit {
margin-top: 8px;
width: 100%;
}
> .status-text-container {
> .status-text-container {
.flex(column, flex-start, center);
.flex(column, flex-start, center);
width: 100%;
width: 100%;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment