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
52c8ac2a
Unverified
Commit
52c8ac2a
authored
Sep 26, 2022
by
boojack
Committed by
GitHub
Sep 26, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: update emoji picker toggle logic (#244)
parent
0c80654c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
45 deletions
+44
-45
EmojiPicker.tsx
web/src/components/Editor/EmojiPicker.tsx
+16
-19
MemoEditor.tsx
web/src/components/MemoEditor.tsx
+28
-26
No files found.
web/src/components/Editor/EmojiPicker.tsx
View file @
52c8ac2a
import
{
forwardRef
,
useEffect
}
from
"react"
;
import
Picker
,
{
IEmojiPickerProps
}
from
"emoji-picker-react"
;
import
Picker
,
{
IEmojiPickerProps
}
from
"emoji-picker-react"
;
import
{
useEffect
}
from
"react"
;
type
EmojiPickerElement
=
HTMLDivElement
;
interface
Props
{
interface
Props
{
isShowEmojiPicker
:
boolean
;
shouldShow
:
boolean
;
onEmojiClick
:
IEmojiPickerProps
[
"onEmojiClick"
];
onEmojiClick
:
IEmojiPickerProps
[
"onEmojiClick"
];
handleChangeIsShowEmojiPicker
:
(
status
:
boolean
)
=>
void
;
onShouldShowEmojiPickerChange
:
(
status
:
boolean
)
=>
void
;
}
}
export
const
EmojiPicker
=
forwardRef
<
EmojiPickerElement
,
Props
>
((
props
:
Props
,
ref
)
=>
{
export
const
EmojiPicker
:
React
.
FC
<
Props
>
=
(
props
:
Props
)
=>
{
const
{
isShowEmojiPicker
,
onEmojiClick
,
handleChangeIsShowEmojiPicker
}
=
props
;
const
{
shouldShow
,
onEmojiClick
,
onShouldShowEmojiPickerChange
}
=
props
;
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
isShowEmojiPicker
)
{
if
(
shouldShow
)
{
const
handleClickOutside
=
(
event
:
MouseEvent
)
=>
{
const
handleClickOutside
=
(
event
:
MouseEvent
)
=>
{
event
.
stopPropagation
();
const
emojiWrapper
=
document
.
querySelector
(
".emoji-picker-react"
);
const
emojiWrapper
=
document
.
querySelector
(
".emoji-picker-react"
);
const
isContains
=
emojiWrapper
?.
contains
(
event
.
target
as
Node
);
const
isContains
=
emojiWrapper
?.
contains
(
event
.
target
as
Node
);
if
(
!
isContains
)
{
if
(
!
isContains
)
{
handleChangeIsShowEmojiPicker
(
false
);
onShouldShowEmojiPickerChange
(
false
);
}
}
};
};
document
.
addEventListener
(
"mousedown"
,
handleClickOutside
);
return
()
=>
{
window
.
addEventListener
(
"click"
,
handleClickOutside
,
{
// Unbind the event listener on clean up
capture
:
true
,
document
.
removeEventListener
(
"mousedown"
,
handleClickOutside
);
once
:
true
,
};
}
)
;
}
}
},
[
isShowEmojiPicker
]);
},
[
shouldShow
]);
return
(
return
(
<
div
className=
"emoji-picker"
ref=
{
ref
}
>
<
div
className=
{
`emoji-picker ${shouldShow ? "" : "hidden"}`
}
>
<
Picker
onEmojiClick=
{
onEmojiClick
}
disableSearchBar
/>
<
Picker
onEmojiClick=
{
onEmojiClick
}
disableSearchBar
/>
</
div
>
</
div
>
);
);
});
};
EmojiPicker
.
displayName
=
"EmojiPicker"
;
export
default
EmojiPicker
;
export
default
EmojiPicker
;
web/src/components/MemoEditor.tsx
View file @
52c8ac2a
...
@@ -11,13 +11,23 @@ import Editor, { EditorRefActions } from "./Editor/Editor";
...
@@ -11,13 +11,23 @@ import Editor, { EditorRefActions } from "./Editor/Editor";
import
EmojiPicker
from
"./Editor/EmojiPicker"
;
import
EmojiPicker
from
"./Editor/EmojiPicker"
;
import
"../less/memo-editor.less"
;
import
"../less/memo-editor.less"
;
const
getEditorContentCache
=
():
string
=>
{
return
storage
.
get
([
"editorContentCache"
]).
editorContentCache
??
""
;
};
const
setEditorContentCache
=
(
content
:
string
)
=>
{
storage
.
set
({
editorContentCache
:
content
,
});
};
interface
State
{
interface
State
{
isShowEmojiPicker
:
boolean
;
fullscreen
:
boolean
;
fullscreen
:
boolean
;
isUploadingResource
:
boolean
;
isUploadingResource
:
boolean
;
shouldShowEmojiPicker
:
boolean
;
}
}
const
MemoEditor
=
()
=>
{
const
MemoEditor
:
React
.
FC
=
()
=>
{
const
{
t
,
i18n
}
=
useTranslation
();
const
{
t
,
i18n
}
=
useTranslation
();
const
user
=
useAppSelector
((
state
)
=>
state
.
user
.
user
);
const
user
=
useAppSelector
((
state
)
=>
state
.
user
.
user
);
const
editorState
=
useAppSelector
((
state
)
=>
state
.
editor
);
const
editorState
=
useAppSelector
((
state
)
=>
state
.
editor
);
...
@@ -25,7 +35,7 @@ const MemoEditor = () => {
...
@@ -25,7 +35,7 @@ const MemoEditor = () => {
const
[
state
,
setState
]
=
useState
<
State
>
({
const
[
state
,
setState
]
=
useState
<
State
>
({
isUploadingResource
:
false
,
isUploadingResource
:
false
,
fullscreen
:
false
,
fullscreen
:
false
,
is
ShowEmojiPicker
:
false
,
should
ShowEmojiPicker
:
false
,
});
});
const
editorRef
=
useRef
<
EditorRefActions
>
(
null
);
const
editorRef
=
useRef
<
EditorRefActions
>
(
null
);
const
prevGlobalStateRef
=
useRef
(
editorState
);
const
prevGlobalStateRef
=
useRef
(
editorState
);
...
@@ -182,6 +192,10 @@ const MemoEditor = () => {
...
@@ -182,6 +192,10 @@ const MemoEditor = () => {
setEditorContentCache
(
content
);
setEditorContentCache
(
content
);
},
[]);
},
[]);
const
handleEmojiPickerBtnClick
=
()
=>
{
handleChangeShouldShowEmojiPicker
(
!
state
.
shouldShowEmojiPicker
);
};
const
handleCheckBoxBtnClick
=
()
=>
{
const
handleCheckBoxBtnClick
=
()
=>
{
if
(
!
editorRef
.
current
)
{
if
(
!
editorRef
.
current
)
{
return
;
return
;
...
@@ -249,10 +263,10 @@ const MemoEditor = () => {
...
@@ -249,10 +263,10 @@ const MemoEditor = () => {
}
}
},
[]);
},
[]);
const
handleChange
Is
ShowEmojiPicker
=
(
status
:
boolean
)
=>
{
const
handleChange
Should
ShowEmojiPicker
=
(
status
:
boolean
)
=>
{
setState
({
setState
({
...
state
,
...
state
,
is
ShowEmojiPicker
:
status
,
should
ShowEmojiPicker
:
status
,
});
});
};
};
...
@@ -262,7 +276,7 @@ const MemoEditor = () => {
...
@@ -262,7 +276,7 @@ const MemoEditor = () => {
}
}
editorRef
.
current
.
insertText
(
`
${
emojiObject
.
emoji
}
`
);
editorRef
.
current
.
insertText
(
`
${
emojiObject
.
emoji
}
`
);
handleChange
Is
ShowEmojiPicker
(
false
);
handleChange
Should
ShowEmojiPicker
(
false
);
};
};
const
isEditing
=
Boolean
(
editorState
.
editMemoId
&&
editorState
.
editMemoId
!==
UNKNOWN_ID
);
const
isEditing
=
Boolean
(
editorState
.
editMemoId
&&
editorState
.
editMemoId
!==
UNKNOWN_ID
);
...
@@ -312,13 +326,13 @@ const MemoEditor = () => {
...
@@ -312,13 +326,13 @@ const MemoEditor = () => {
</
div
>
</
div
>
</
div
>
</
div
>
<
button
className=
"action-btn"
>
<
button
className=
"action-btn"
>
<
Icon
.
CheckSquare
className=
"icon-img"
onClick=
{
handleCheckBox
BtnClick
}
/>
<
Icon
.
Smile
className=
"icon-img"
onClick=
{
handleEmojiPicker
BtnClick
}
/>
</
button
>
</
button
>
<
button
className=
"action-btn"
>
<
button
className=
"action-btn"
>
<
Icon
.
C
ode
className=
"icon-img"
onClick=
{
handleCodeBlock
BtnClick
}
/>
<
Icon
.
C
heckSquare
className=
"icon-img"
onClick=
{
handleCheckBox
BtnClick
}
/>
</
button
>
</
button
>
<
button
className=
"action-btn"
>
<
button
className=
"action-btn"
>
<
Icon
.
Smile
className=
"icon-img"
onClick=
{
()
=>
handleChangeIsShowEmojiPicker
(
!
state
.
isShowEmojiPicker
)
}
/>
<
Icon
.
Code
className=
"icon-img"
onClick=
{
handleCodeBlockBtnClick
}
/>
</
button
>
</
button
>
<
button
className=
"action-btn"
>
<
button
className=
"action-btn"
>
<
Icon
.
Image
className=
"icon-img"
onClick=
{
handleUploadFileBtnClick
}
/>
<
Icon
.
Image
className=
"icon-img"
onClick=
{
handleUploadFileBtnClick
}
/>
...
@@ -330,25 +344,13 @@ const MemoEditor = () => {
...
@@ -330,25 +344,13 @@ const MemoEditor = () => {
</>
</>
}
}
/>
/>
{
state
.
isShowEmojiPicker
&&
(
<
EmojiPicker
<
EmojiPicker
shouldShow=
{
state
.
shouldShowEmojiPicker
}
onEmojiClick=
{
handleEmojiClick
}
onEmojiClick=
{
handleEmojiClick
}
isShowEmojiPicker=
{
state
.
isShowEmojiPicker
}
onShouldShowEmojiPickerChange=
{
handleChangeShouldShowEmojiPicker
}
handleChangeIsShowEmojiPicker=
{
handleChangeIsShowEmojiPicker
}
/>
/>
)
}
</
div
>
</
div
>
);
);
};
};
function
getEditorContentCache
():
string
{
return
storage
.
get
([
"editorContentCache"
]).
editorContentCache
??
""
;
}
function
setEditorContentCache
(
content
:
string
)
{
storage
.
set
({
editorContentCache
:
content
,
});
}
export
default
MemoEditor
;
export
default
MemoEditor
;
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