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
36209eae
Commit
36209eae
authored
Sep 13, 2023
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add content cache for memo editor
parent
d63715d4
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
10 deletions
+13
-10
index.tsx
web/src/components/MemoEditor/index.tsx
+10
-1
UpgradeVersionBanner.tsx
web/src/components/UpgradeVersionBanner.tsx
+3
-3
storage.ts
web/src/helpers/storage.ts
+0
-6
No files found.
web/src/components/MemoEditor/index.tsx
View file @
36209eae
...
@@ -2,6 +2,7 @@ import { isNumber, last, uniq } from "lodash-es";
...
@@ -2,6 +2,7 @@ import { isNumber, last, uniq } from "lodash-es";
import
React
,
{
useCallback
,
useEffect
,
useMemo
,
useRef
,
useState
}
from
"react"
;
import
React
,
{
useCallback
,
useEffect
,
useMemo
,
useRef
,
useState
}
from
"react"
;
import
{
toast
}
from
"react-hot-toast"
;
import
{
toast
}
from
"react-hot-toast"
;
import
{
useTranslation
}
from
"react-i18next"
;
import
{
useTranslation
}
from
"react-i18next"
;
import
{
useLocalStorage
}
from
"react-use"
;
import
{
upsertMemoResource
}
from
"@/helpers/api"
;
import
{
upsertMemoResource
}
from
"@/helpers/api"
;
import
{
TAB_SPACE_WIDTH
,
UNKNOWN_ID
}
from
"@/helpers/consts"
;
import
{
TAB_SPACE_WIDTH
,
UNKNOWN_ID
}
from
"@/helpers/consts"
;
import
{
clearContentQueryParam
}
from
"@/helpers/utils"
;
import
{
clearContentQueryParam
}
from
"@/helpers/utils"
;
...
@@ -39,6 +40,7 @@ const MemoEditor = (props: Props) => {
...
@@ -39,6 +40,7 @@ const MemoEditor = (props: Props) => {
const
{
className
,
memoId
,
onConfirm
}
=
props
;
const
{
className
,
memoId
,
onConfirm
}
=
props
;
const
{
i18n
}
=
useTranslation
();
const
{
i18n
}
=
useTranslation
();
const
t
=
useTranslate
();
const
t
=
useTranslate
();
const
[
contentCache
,
setContentCache
]
=
useLocalStorage
<
string
>
(
`memo-editor-
${
props
.
memoId
||
"0"
}
`
,
""
);
const
{
const
{
state
:
{
systemStatus
},
state
:
{
systemStatus
},
}
=
useGlobalStore
();
}
=
useGlobalStore
();
...
@@ -61,6 +63,10 @@ const MemoEditor = (props: Props) => {
...
@@ -61,6 +63,10 @@ const MemoEditor = (props: Props) => {
const
user
=
userStore
.
state
.
user
as
User
;
const
user
=
userStore
.
state
.
user
as
User
;
const
setting
=
user
.
setting
;
const
setting
=
user
.
setting
;
useEffect
(()
=>
{
editorRef
.
current
?.
setContent
(
contentCache
||
""
);
},
[]);
useEffect
(()
=>
{
useEffect
(()
=>
{
let
visibility
=
setting
.
memoVisibility
;
let
visibility
=
setting
.
memoVisibility
;
if
(
systemStatus
.
disablePublicMemos
&&
visibility
===
"PUBLIC"
)
{
if
(
systemStatus
.
disablePublicMemos
&&
visibility
===
"PUBLIC"
)
{
...
@@ -83,8 +89,10 @@ const MemoEditor = (props: Props) => {
...
@@ -83,8 +89,10 @@ const MemoEditor = (props: Props) => {
resourceList
:
memo
.
resourceList
,
resourceList
:
memo
.
resourceList
,
relationList
:
memo
.
relationList
,
relationList
:
memo
.
relationList
,
}));
}));
if
(
!
contentCache
)
{
editorRef
.
current
?.
setContent
(
memo
.
content
??
""
);
editorRef
.
current
?.
setContent
(
memo
.
content
??
""
);
}
}
}
});
});
}
}
},
[
memoId
]);
},
[
memoId
]);
...
@@ -242,6 +250,7 @@ const MemoEditor = (props: Props) => {
...
@@ -242,6 +250,7 @@ const MemoEditor = (props: Props) => {
const
handleContentChange
=
(
content
:
string
)
=>
{
const
handleContentChange
=
(
content
:
string
)
=>
{
setHasContent
(
content
!==
""
);
setHasContent
(
content
!==
""
);
setContentCache
(
content
);
};
};
const
handleSaveBtnClick
=
async
()
=>
{
const
handleSaveBtnClick
=
async
()
=>
{
...
...
web/src/components/UpgradeVersionBanner.tsx
View file @
36209eae
import
{
useEffect
,
useState
}
from
"react"
;
import
{
useEffect
,
useState
}
from
"react"
;
import
{
useLocalStorage
}
from
"react-use"
;
import
{
compare
}
from
"semver"
;
import
{
compare
}
from
"semver"
;
import
*
as
api
from
"@/helpers/api"
;
import
*
as
api
from
"@/helpers/api"
;
import
storage
from
"@/helpers/storage"
;
import
{
useGlobalStore
}
from
"@/store/module"
;
import
{
useGlobalStore
}
from
"@/store/module"
;
import
Icon
from
"./Icon"
;
import
Icon
from
"./Icon"
;
...
@@ -12,6 +12,7 @@ interface State {
...
@@ -12,6 +12,7 @@ interface State {
const
UpgradeVersionView
:
React
.
FC
=
()
=>
{
const
UpgradeVersionView
:
React
.
FC
=
()
=>
{
const
globalStore
=
useGlobalStore
();
const
globalStore
=
useGlobalStore
();
const
[
skippedVersion
,
setSkippedVersion
]
=
useLocalStorage
<
string
>
(
"skipped_version"
,
"0.0.0"
);
const
profile
=
globalStore
.
state
.
systemStatus
.
profile
;
const
profile
=
globalStore
.
state
.
systemStatus
.
profile
;
const
[
state
,
setState
]
=
useState
<
State
>
({
const
[
state
,
setState
]
=
useState
<
State
>
({
latestVersion
:
""
,
latestVersion
:
""
,
...
@@ -20,7 +21,6 @@ const UpgradeVersionView: React.FC = () => {
...
@@ -20,7 +21,6 @@ const UpgradeVersionView: React.FC = () => {
useEffect
(()
=>
{
useEffect
(()
=>
{
api
.
getRepoLatestTag
().
then
((
latestTag
)
=>
{
api
.
getRepoLatestTag
().
then
((
latestTag
)
=>
{
const
{
skippedVersion
}
=
storage
.
get
([
"skippedVersion"
]);
const
latestVersion
=
latestTag
.
slice
(
1
)
||
"0.0.0"
;
const
latestVersion
=
latestTag
.
slice
(
1
)
||
"0.0.0"
;
const
currentVersion
=
profile
.
version
;
const
currentVersion
=
profile
.
version
;
const
skipped
=
skippedVersion
?
skippedVersion
===
latestVersion
:
false
;
const
skipped
=
skippedVersion
?
skippedVersion
===
latestVersion
:
false
;
...
@@ -32,7 +32,7 @@ const UpgradeVersionView: React.FC = () => {
...
@@ -32,7 +32,7 @@ const UpgradeVersionView: React.FC = () => {
},
[]);
},
[]);
const
onSkip
=
()
=>
{
const
onSkip
=
()
=>
{
s
torage
.
set
({
skippedVersion
:
state
.
latestVersion
}
);
s
etSkippedVersion
(
state
.
latestVersion
);
setState
((
s
)
=>
({
setState
((
s
)
=>
({
...
s
,
...
s
,
show
:
false
,
show
:
false
,
...
...
web/src/helpers/storage.ts
View file @
36209eae
...
@@ -2,18 +2,12 @@
...
@@ -2,18 +2,12 @@
* Define storage data type
* Define storage data type
*/
*/
interface
StorageData
{
interface
StorageData
{
// Editor content cache
editorContentCache
:
string
;
// Editing memo id cache
editingMemoIdCache
:
MemoId
;
// locale
// locale
locale
:
Locale
;
locale
:
Locale
;
// appearance
// appearance
appearance
:
Appearance
;
appearance
:
Appearance
;
// local setting
// local setting
localSetting
:
LocalSetting
;
localSetting
:
LocalSetting
;
// skipped version
skippedVersion
:
string
;
}
}
type
StorageKey
=
keyof
StorageData
;
type
StorageKey
=
keyof
StorageData
;
...
...
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