Skip to content

Commit 0f5c3dd

Browse files
committed
refactor: enhance mobile toolbar and editable document control logic
- Updated ToolbarMobile to conditionally render based on keyboard state. - Improved useEditableDocControl to manage editor's editable state based on keyboard visibility. - Cleaned up MobileLayout by removing unnecessary line breaks.
1 parent 298ec3d commit 0f5c3dd

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

packages/webapp/src/components/pages/document/components/toolbarMobile/ToolbarMobile.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,15 @@ const ToolbarMobile = () => {
1414
} = useStore((state) => state.settings)
1515

1616
const { createComment } = useTurnSelectedTextIntoComment()
17+
const { isKeyboardOpen } = useStore((state) => state)
1718

1819
useEffect(() => {
1920
if (isEditable) {
2021
setIsFormatSelectionVisible(false)
2122
}
2223
}, [isEditable])
2324

24-
if (!editor) {
25-
return null
26-
}
25+
if (!editor || !isKeyboardOpen) return null
2726

2827
const buttons = [
2928
{

packages/webapp/src/components/pages/document/hooks/useEditableDocControl.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,33 @@ const useEditableDocControl = () => {
77
editor: { instance: editor, loading }
88
} = useStore((state) => state.settings)
99
const setWorkspaceEditorSetting = useStore((state) => state.setWorkspaceEditorSetting)
10+
const { isKeyboardOpen } = useStore((state) => state)
1011

1112
useEffect(() => {
1213
if (!editor) return
13-
const isKeyboardOpen = useStore.getState().isKeyboardOpen
1414

1515
// TODO: update text selection, when editable change to false, scrolling is getting hard when we have a text range selected
1616
const timeout = setTimeout(() => {
17+
const { isKeyboardOpen } = useStore.getState()
1718

18-
if (isKeyboardOpen) {
19+
if (!isKeyboardOpen) {
1920
const divProseMirror = document.querySelector('.tiptap.ProseMirror') as HTMLElement
2021
divProseMirror?.setAttribute('contenteditable', 'false')
21-
useStore.getState().setWorkspaceEditorSetting('isEditable', false)
2222
editor?.setEditable(false)
2323
} else {
2424
const divProseMirror = document.querySelector('.tiptap.ProseMirror') as HTMLElement
2525
divProseMirror?.setAttribute('contenteditable', 'true')
26-
setWorkspaceEditorSetting('isEditable', true)
2726
editor?.setEditable(true)
2827
}
29-
3028
}, 500)
3129
return () => {
3230
clearTimeout(timeout)
3331
}
3432
}, [deviceDetect, editor, loading])
33+
34+
useEffect(() => {
35+
setWorkspaceEditorSetting('isEditable', !isKeyboardOpen ? false : true)
36+
}, [isKeyboardOpen, setWorkspaceEditorSetting])
3537
}
3638

3739
export default useEditableDocControl

packages/webapp/src/components/pages/document/layouts/MobileLayout.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ const MobileLayout = () => {
3535
if (isHistoryView) return <MobileHistory />
3636

3737
return (
38-
39-
4038
<div
4139
className={`tiptap relative flex w-full flex-col ${deviceClass}`}
4240
style={{
@@ -49,7 +47,7 @@ const MobileLayout = () => {
4947
<MobileEditor />
5048
<BigPencilBtn />
5149
<BottomSheet />
52-
<div className="sticky mobileToolbarBottom bottom-0 left-0 z-20 w-full bg-white">
50+
<div className="mobileToolbarBottom sticky bottom-0 left-0 z-20 w-full bg-white">
5351
<ToolbarMobile />
5452
</div>
5553
</div>

0 commit comments

Comments
 (0)