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
9d8c9609
Unverified
Commit
9d8c9609
authored
Oct 31, 2022
by
boojack
Committed by
GitHub
Oct 31, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: cache editing memo id (#388)
* feat: cache editing memo id * chore: update
parent
ef549207
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
46 additions
and
27 deletions
+46
-27
ChangeMemoCreatedTsDialog.tsx
web/src/components/ChangeMemoCreatedTsDialog.tsx
+9
-8
Memo.tsx
web/src/components/Memo.tsx
+1
-1
MemoCardDialog.tsx
web/src/components/MemoCardDialog.tsx
+5
-3
MemoEditor.tsx
web/src/components/MemoEditor.tsx
+27
-12
storage.ts
web/src/helpers/storage.ts
+2
-0
memoService.ts
web/src/services/memoService.ts
+2
-3
No files found.
web/src/components/ChangeMemoCreatedTsDialog.tsx
View file @
9d8c9609
...
@@ -18,14 +18,15 @@ const ChangeMemoCreatedTsDialog: React.FC<Props> = (props: Props) => {
...
@@ -18,14 +18,15 @@ const ChangeMemoCreatedTsDialog: React.FC<Props> = (props: Props) => {
const
maxDatetimeValue
=
dayjs
().
format
(
"YYYY-MM-DDTHH:mm"
);
const
maxDatetimeValue
=
dayjs
().
format
(
"YYYY-MM-DDTHH:mm"
);
useEffect
(()
=>
{
useEffect
(()
=>
{
const
memo
=
memoService
.
getMemoById
(
memoId
);
memoService
.
getMemoById
(
memoId
).
then
((
memo
)
=>
{
if
(
memo
)
{
if
(
memo
)
{
const
datetime
=
dayjs
(
memo
.
createdTs
).
format
(
"YYYY-MM-DDTHH:mm"
);
const
datetime
=
dayjs
(
memo
.
createdTs
).
format
(
"YYYY-MM-DDTHH:mm"
);
setCreatedAt
(
datetime
);
setCreatedAt
(
datetime
);
}
else
{
}
else
{
toastHelper
.
error
(
t
(
"message.memo-not-found"
));
toastHelper
.
error
(
t
(
"message.memo-not-found"
));
destroy
();
destroy
();
}
}
});
},
[]);
},
[]);
const
handleCloseBtnClick
=
()
=>
{
const
handleCloseBtnClick
=
()
=>
{
...
...
web/src/components/Memo.tsx
View file @
9d8c9609
...
@@ -113,7 +113,7 @@ const Memo: React.FC<Props> = (props: Props) => {
...
@@ -113,7 +113,7 @@ const Memo: React.FC<Props> = (props: Props) => {
if
(
targetEl
.
className
===
"memo-link-text"
)
{
if
(
targetEl
.
className
===
"memo-link-text"
)
{
const
memoId
=
targetEl
.
dataset
?.
value
;
const
memoId
=
targetEl
.
dataset
?.
value
;
const
memoTemp
=
memoService
.
getMemoById
(
Number
(
memoId
)
??
UNKNOWN_ID
);
const
memoTemp
=
await
memoService
.
getMemoById
(
Number
(
memoId
)
??
UNKNOWN_ID
);
if
(
memoTemp
)
{
if
(
memoTemp
)
{
showMemoCardDialog
(
memoTemp
);
showMemoCardDialog
(
memoTemp
);
...
...
web/src/components/MemoCardDialog.tsx
View file @
9d8c9609
...
@@ -54,7 +54,7 @@ const MemoCardDialog: React.FC<Props> = (props: Props) => {
...
@@ -54,7 +54,7 @@ const MemoCardDialog: React.FC<Props> = (props: Props) => {
continue
;
continue
;
}
}
const
memoTemp
=
memoService
.
getMemoById
(
id
);
const
memoTemp
=
await
memoService
.
getMemoById
(
id
);
if
(
memoTemp
)
{
if
(
memoTemp
)
{
linkMemos
.
push
({
linkMemos
.
push
({
...
memoTemp
,
...
memoTemp
,
...
@@ -83,7 +83,9 @@ const MemoCardDialog: React.FC<Props> = (props: Props) => {
...
@@ -83,7 +83,9 @@ const MemoCardDialog: React.FC<Props> = (props: Props) => {
};
};
fetchLinkedMemos
();
fetchLinkedMemos
();
setMemo
(
memoService
.
getMemoById
(
memo
.
id
)
as
Memo
);
memoService
.
getMemoById
(
memo
.
id
).
then
((
memo
)
=>
{
setMemo
(
memo
);
});
},
[
memos
,
memo
.
id
]);
},
[
memos
,
memo
.
id
]);
const
handleMemoCreatedAtClick
=
()
=>
{
const
handleMemoCreatedAtClick
=
()
=>
{
...
@@ -99,7 +101,7 @@ const MemoCardDialog: React.FC<Props> = (props: Props) => {
...
@@ -99,7 +101,7 @@ const MemoCardDialog: React.FC<Props> = (props: Props) => {
if
(
targetEl
.
className
===
"memo-link-text"
)
{
if
(
targetEl
.
className
===
"memo-link-text"
)
{
const
nextMemoId
=
targetEl
.
dataset
?.
value
;
const
nextMemoId
=
targetEl
.
dataset
?.
value
;
const
memoTemp
=
memoService
.
getMemoById
(
Number
(
nextMemoId
)
??
UNKNOWN_ID
);
const
memoTemp
=
await
memoService
.
getMemoById
(
Number
(
nextMemoId
)
??
UNKNOWN_ID
);
if
(
memoTemp
)
{
if
(
memoTemp
)
{
const
nextMemo
=
{
const
nextMemo
=
{
...
...
web/src/components/MemoEditor.tsx
View file @
9d8c9609
...
@@ -47,6 +47,13 @@ const MemoEditor: React.FC = () => {
...
@@ -47,6 +47,13 @@ const MemoEditor: React.FC = () => {
const
editorFontStyle
=
user
?.
setting
.
editorFontStyle
||
"normal"
;
const
editorFontStyle
=
user
?.
setting
.
editorFontStyle
||
"normal"
;
const
mobileEditorStyle
=
user
?.
setting
.
mobileEditorStyle
||
"normal"
;
const
mobileEditorStyle
=
user
?.
setting
.
mobileEditorStyle
||
"normal"
;
useEffect
(()
=>
{
const
{
editingMemoIdCache
}
=
storage
.
get
([
"editingMemoIdCache"
]);
if
(
editingMemoIdCache
)
{
editorStateService
.
setEditMemoWithId
(
editingMemoIdCache
);
}
},
[]);
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
editorState
.
markMemoId
&&
editorState
.
markMemoId
!==
UNKNOWN_ID
)
{
if
(
editorState
.
markMemoId
&&
editorState
.
markMemoId
!==
UNKNOWN_ID
)
{
const
editorCurrentValue
=
editorRef
.
current
?.
getContent
();
const
editorCurrentValue
=
editorRef
.
current
?.
getContent
();
...
@@ -62,18 +69,26 @@ const MemoEditor: React.FC = () => {
...
@@ -62,18 +69,26 @@ const MemoEditor: React.FC = () => {
editorState
.
editMemoId
!==
UNKNOWN_ID
&&
editorState
.
editMemoId
!==
UNKNOWN_ID
&&
editorState
.
editMemoId
!==
prevGlobalStateRef
.
current
.
editMemoId
editorState
.
editMemoId
!==
prevGlobalStateRef
.
current
.
editMemoId
)
{
)
{
const
memo
=
memoService
.
getMemoById
(
editorState
.
editMemoId
??
UNKNOWN_ID
);
memoService
.
getMemoById
(
editorState
.
editMemoId
??
UNKNOWN_ID
).
then
((
memo
)
=>
{
if
(
memo
)
{
if
(
memo
)
{
setState
({
setState
({
...
state
,
...
state
,
resourceList
:
memo
.
resourceList
,
resourceList
:
memo
.
resourceList
,
});
});
editorRef
.
current
?.
setContent
(
memo
.
content
??
""
);
editorRef
.
current
?.
setContent
(
memo
.
content
??
""
);
editorRef
.
current
?.
focus
();
editorRef
.
current
?.
focus
();
}
}
});
}
}
prevGlobalStateRef
.
current
=
editorState
;
prevGlobalStateRef
.
current
=
editorState
;
if
(
editorState
.
editMemoId
)
{
storage
.
set
({
editingMemoIdCache
:
editorState
.
editMemoId
,
});
}
else
{
storage
.
remove
([
"editingMemoIdCache"
]);
}
},
[
state
,
editorState
.
editMemoId
]);
},
[
state
,
editorState
.
editMemoId
]);
const
handleKeyDown
=
(
event
:
React
.
KeyboardEvent
)
=>
{
const
handleKeyDown
=
(
event
:
React
.
KeyboardEvent
)
=>
{
...
@@ -175,7 +190,7 @@ const MemoEditor: React.FC = () => {
...
@@ -175,7 +190,7 @@ const MemoEditor: React.FC = () => {
try
{
try
{
const
{
editMemoId
}
=
editorStateService
.
getState
();
const
{
editMemoId
}
=
editorStateService
.
getState
();
if
(
editMemoId
&&
editMemoId
!==
UNKNOWN_ID
)
{
if
(
editMemoId
&&
editMemoId
!==
UNKNOWN_ID
)
{
const
prevMemo
=
memoService
.
getMemoById
(
editMemoId
??
UNKNOWN_ID
);
const
prevMemo
=
await
memoService
.
getMemoById
(
editMemoId
??
UNKNOWN_ID
);
if
(
prevMemo
)
{
if
(
prevMemo
)
{
await
memoService
.
patchMemo
({
await
memoService
.
patchMemo
({
...
@@ -206,7 +221,7 @@ const MemoEditor: React.FC = () => {
...
@@ -206,7 +221,7 @@ const MemoEditor: React.FC = () => {
editorRef
.
current
?.
setContent
(
""
);
editorRef
.
current
?.
setContent
(
""
);
};
};
const
handleCancelEdit
ing
=
()
=>
{
const
handleCancelEdit
=
()
=>
{
setState
({
setState
({
...
state
,
...
state
,
resourceList
:
[],
resourceList
:
[],
...
@@ -348,7 +363,7 @@ const MemoEditor: React.FC = () => {
...
@@ -348,7 +363,7 @@ const MemoEditor: React.FC = () => {
>
>
<
div
className=
{
`tip-container ${isEditing ? "" : "!hidden"}`
}
>
<
div
className=
{
`tip-container ${isEditing ? "" : "!hidden"}`
}
>
<
span
className=
"tip-text"
>
{
t
(
"editor.editing"
)
}
</
span
>
<
span
className=
"tip-text"
>
{
t
(
"editor.editing"
)
}
</
span
>
<
button
className=
"cancel-btn"
onClick=
{
handleCancelEdit
ing
}
>
<
button
className=
"cancel-btn"
onClick=
{
handleCancelEdit
}
>
{
t
(
"common.cancel"
)
}
{
t
(
"common.cancel"
)
}
</
button
>
</
button
>
</
div
>
</
div
>
...
...
web/src/helpers/storage.ts
View file @
9d8c9609
...
@@ -4,6 +4,8 @@
...
@@ -4,6 +4,8 @@
interface
StorageData
{
interface
StorageData
{
// Editor content cache
// Editor content cache
editorContentCache
:
string
;
editorContentCache
:
string
;
// Editing memo id cache
editingMemoIdCache
:
MemoId
;
// locale
// locale
locale
:
Locale
;
locale
:
Locale
;
}
}
...
...
web/src/services/memoService.ts
View file @
9d8c9609
...
@@ -71,19 +71,18 @@ const memoService = {
...
@@ -71,19 +71,18 @@ const memoService = {
fetchMemoById
:
async
(
memoId
:
MemoId
)
=>
{
fetchMemoById
:
async
(
memoId
:
MemoId
)
=>
{
const
{
data
}
=
(
await
api
.
getMemoById
(
memoId
)).
data
;
const
{
data
}
=
(
await
api
.
getMemoById
(
memoId
)).
data
;
const
memo
=
convertResponseModelMemo
(
data
);
const
memo
=
convertResponseModelMemo
(
data
);
store
.
dispatch
(
patchMemo
(
memo
));
return
memo
;
return
memo
;
},
},
getMemoById
:
(
memoId
:
MemoId
)
=>
{
getMemoById
:
async
(
memoId
:
MemoId
)
=>
{
for
(
const
m
of
memoService
.
getState
().
memos
)
{
for
(
const
m
of
memoService
.
getState
().
memos
)
{
if
(
m
.
id
===
memoId
)
{
if
(
m
.
id
===
memoId
)
{
return
m
;
return
m
;
}
}
}
}
return
null
;
return
await
memoService
.
fetchMemoById
(
memoId
)
;
},
},
updateTagsState
:
async
()
=>
{
updateTagsState
:
async
()
=>
{
...
...
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