Skip to content

Commit 1875a83

Browse files
KomediruzeckiDavy-c
authored andcommitted
Refactor connect and reconnect
Add popup
1 parent 28a320b commit 1875a83

File tree

3 files changed

+126
-86
lines changed

3 files changed

+126
-86
lines changed

src/cloud/components/Editor/index.tsx

Lines changed: 39 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ import {
4040
mdiEyeOutline,
4141
mdiViewSplitVertical,
4242
mdiDotsHorizontal,
43-
mdiCloudOffOutline,
44-
mdiCloudSyncOutline,
4543
} from '@mdi/js'
4644
import EditorToolButton from './EditorToolButton'
4745
import { not } from 'ramda'
@@ -101,6 +99,7 @@ import CustomizedMarkdownPreviewer from '../MarkdownView/CustomizedMarkdownPrevi
10199
import BottomBarButton from '../BottomBarButton'
102100
import { YText } from 'yjs/dist/src/internals'
103101
import { useLocalSnapshot } from '../../lib/stores/localSnapshots'
102+
import SyncStatus from '../Topbar/SyncStatus'
104103

105104
type LayoutMode = 'split' | 'preview' | 'editor'
106105

@@ -159,6 +158,8 @@ const Editor = ({
159158
: 'preview'
160159
)
161160
const [editorContent, setEditorContent] = useState('')
161+
const [showingConnectIssueMessage, setShowingShowingConnectIssueMessage] =
162+
useState<boolean>(false)
162163
const docRef = useRef<string>('')
163164
const router = useRouter()
164165
const { state } = router
@@ -485,6 +486,16 @@ const Editor = ({
485486
})
486487
}, [openModal, onTemplatePickCallback])
487488

489+
useEffect(() => {
490+
if (connState == 'reconnecting') {
491+
setShowingShowingConnectIssueMessage(true)
492+
} else if (connState == 'disconnected') {
493+
setShowingShowingConnectIssueMessage(true)
494+
} else {
495+
setShowingShowingConnectIssueMessage(false)
496+
}
497+
}, [connState])
498+
488499
const toggleScrollSync = useCallback(() => {
489500
setScrollSync(not)
490501
}, [])
@@ -846,57 +857,6 @@ const Editor = ({
846857
{
847858
type: 'separator',
848859
},
849-
...(connState === 'reconnecting'
850-
? [
851-
{
852-
type: 'button',
853-
iconPath: mdiCloudSyncOutline,
854-
variant: 'danger',
855-
disabled: true,
856-
label: translate(lngKeys.EditorReconnectAttempt),
857-
tooltip: (
858-
<>
859-
{translate(lngKeys.EditorReconnectAttempt1)}
860-
<br />
861-
{translate(lngKeys.EditorReconnectAttempt2)}
862-
</>
863-
),
864-
},
865-
]
866-
: connState === 'disconnected'
867-
? [
868-
{
869-
type: 'button',
870-
iconPath: mdiCloudOffOutline,
871-
variant: 'danger',
872-
onClick: () => realtime.connect(),
873-
label: translate(lngKeys.EditorReconnectDisconnected),
874-
tooltip: (
875-
<>
876-
{translate(lngKeys.EditorReconnectDisconnected1)}
877-
<br />
878-
{translate(lngKeys.EditorReconnectDisconnected2)}
879-
</>
880-
),
881-
},
882-
]
883-
: connState === 'loaded'
884-
? [
885-
{
886-
type: 'button',
887-
variant: 'secondary' as const,
888-
disabled: true,
889-
label: translate(lngKeys.EditorReconnectSyncing),
890-
tooltip: (
891-
<>
892-
{translate(lngKeys.EditorReconnectSyncing1)}
893-
<br />
894-
{translate(lngKeys.EditorReconnectSyncing2)}
895-
</>
896-
),
897-
},
898-
]
899-
: []),
900860
...(docIsEditable && currentUserIsCoreMember
901861
? [
902862
{
@@ -1069,6 +1029,9 @@ const Editor = ({
10691029
)}
10701030
</Container>
10711031
</EditorLayout>
1032+
{showingConnectIssueMessage && (
1033+
<SyncStatus provider={realtime} connState={connState} />
1034+
)}
10721035
</ApplicationContent>
10731036
</ApplicationPage>
10741037
)
@@ -1102,6 +1065,7 @@ const StyledBottomBar = styled.div`
11021065
height: 24px;
11031066
background-color: ${({ theme }) => theme.colors.background.primary};
11041067
box-sizing: content-box;
1068+
11051069
& > :first-child {
11061070
flex: 1;
11071071
}
@@ -1142,6 +1106,7 @@ const StyledShortcodeConvertMenu = styled.div`
11421106

11431107
const StyledLayoutDimensions = styled.div`
11441108
width: 100%;
1109+
11451110
&.preview,
11461111
.preview {
11471112
width: 100%;
@@ -1163,17 +1128,21 @@ const ToolbarRow = styled.div`
11631128
border: solid 1px ${({ theme }) => theme.colors.border.second};
11641129
border-radius: 5px;
11651130
`
1131+
11661132
interface FontOptionsProps {
11671133
fontSize: string
11681134
fontFamily: string
11691135
}
1136+
11701137
const StyledEditorWrapper = styled.div<BaseTheme & FontOptionsProps>`
11711138
position: relative;
11721139
height: auto;
11731140
width: 50%;
1141+
11741142
&.layout-editor {
11751143
width: 100%;
11761144
}
1145+
11771146
&.layout-preview {
11781147
display: none;
11791148
}
@@ -1189,19 +1158,23 @@ const StyledEditorWrapper = styled.div<BaseTheme & FontOptionsProps>`
11891158
const StyledPreview = styled.div`
11901159
height: 100%;
11911160
width: 50%;
1161+
11921162
&.layout-split {
11931163
width: 50%;
1164+
11941165
.scroller {
11951166
height: 100%;
11961167
overflow: auto;
11971168
border-left: 1px solid ${({ theme }) => theme.colors.border.main};
11981169
}
11991170
}
1171+
12001172
&.layout-preview {
12011173
padding-top: ${({ theme }) => theme.sizes.spaces.sm}px;
12021174
margin: 0 auto;
12031175
width: 100%;
12041176
}
1177+
12051178
&.layout-editor {
12061179
display: none;
12071180
}
@@ -1223,21 +1196,25 @@ const StyledEditor = styled.div`
12231196
height: auto;
12241197
min-height: 0;
12251198
font-size: 15px;
1199+
12261200
&.preview,
12271201
.preview {
12281202
${rightSidePageLayout};
12291203
margin: auto;
12301204
}
1205+
12311206
& .CodeMirrorWrapper {
12321207
height: 100%;
12331208
word-break: break-word;
12341209
}
1210+
12351211
& .CodeMirror {
12361212
width: 100%;
12371213
height: 100%;
12381214
position: relative;
12391215
z-index: 0 !important;
12401216
line-height: 1.4em;
1217+
12411218
.CodeMirror-hints {
12421219
position: absolute;
12431220
z-index: 10;
@@ -1254,6 +1231,7 @@ const StyledEditor = styled.div`
12541231
font-family: monospace;
12551232
list-style: none;
12561233
}
1234+
12571235
.CodeMirror-hint {
12581236
position: relative;
12591237
margin: 0;
@@ -1264,8 +1242,10 @@ const StyledEditor = styled.div`
12641242
cursor: pointer;
12651243
font-size: ${({ theme }) => theme.sizes.fonts.xsm}px;
12661244
}
1245+
12671246
li.CodeMirror-hint-active {
12681247
color: ${({ theme }) => theme.colors.variants.primary.base};
1248+
12691249
&:before {
12701250
content: '';
12711251
display: block;
@@ -1277,15 +1257,18 @@ const StyledEditor = styled.div`
12771257
background-color: ${({ theme }) => theme.colors.variants.primary.base};
12781258
}
12791259
}
1260+
12801261
& .remote-caret {
12811262
position: relative;
12821263
border-left: 1px solid black;
12831264
margin-left: -1px;
12841265
box-sizing: border-box;
1266+
12851267
&:hover > div {
12861268
opacity: 1;
12871269
transition-delay: 0s;
12881270
}
1271+
12891272
& > div {
12901273
position: absolute;
12911274
left: -1px;
@@ -1307,15 +1290,18 @@ const StyledEditor = styled.div`
13071290
}
13081291
}
13091292
}
1293+
13101294
.CodeMirror-scroll {
13111295
position: relative;
13121296
z-index: 0;
13131297
width: 100%;
13141298
}
1299+
13151300
.CodeMirror-code,
13161301
.CodeMirror-gutters {
13171302
padding-bottom: 32px;
13181303
}
1304+
13191305
& .file-loading-widget {
13201306
transform: translate3d(0, -100%, 0);
13211307
}

0 commit comments

Comments
 (0)