Skip to content

Commit d5ae4fb

Browse files
author
Ives van Hoorne
committed
Latest live
1 parent c9c2c5d commit d5ae4fb

File tree

6 files changed

+27
-12
lines changed

6 files changed

+27
-12
lines changed

packages/app/src/app/components/CodeEditor/Monaco/index.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ function indexToLineAndColumn(lines, index) {
4545
offset += line.length + 1;
4646
}
4747

48-
// +2 for column, because +1 for Monaco and +1 for linebreak
49-
return { lineNumber: lines.length, column: lines[lines.length - 1] + 2 };
48+
// +2 for column (length is already a +1), because +1 for Monaco and +1 for linebreak
49+
return {
50+
lineNumber: lines.length,
51+
column: (lines[lines.length - 1] || '').length + 1,
52+
};
5053
}
5154

5255
const fadeIn = css.keyframes('fadeIn', {
@@ -291,7 +294,7 @@ class MonacoEditor extends React.Component<Props, State> implements Editor {
291294
const { onSelectionChanged, isLive } = this.props;
292295
// Reason 3 is update by mouse or arrow keys
293296
if (isLive) {
294-
const lines = editor.getModel().getLinesContent();
297+
const lines = editor.getModel().getLinesContent() || [];
295298
const data = {
296299
primary: getSelection(lines, selectionChange.selection),
297300
secondary: selectionChange.secondarySelections.map(s =>
@@ -515,7 +518,7 @@ class MonacoEditor extends React.Component<Props, State> implements Editor {
515518
}
516519
>
517520
) => {
518-
const lines = this.editor.getModel().getLinesContent();
521+
const lines = this.editor.getModel().getLinesContent() || [];
519522

520523
userSelections.forEach(data => {
521524
const { userId } = data;
@@ -730,7 +733,7 @@ class MonacoEditor extends React.Component<Props, State> implements Editor {
730733
index += op;
731734
} else if (TextOperation.isInsert(op)) {
732735
const { lineNumber, column } = indexToLineAndColumn(
733-
this.editor.getModel().getLinesContent(),
736+
this.editor.getModel().getLinesContent() || [],
734737
index
735738
);
736739
this.editor.getModel().applyEdits([
@@ -747,7 +750,7 @@ class MonacoEditor extends React.Component<Props, State> implements Editor {
747750
]);
748751
index += op.length;
749752
} else if (TextOperation.isDelete(op)) {
750-
const lines = this.editor.getModel().getLinesContent();
753+
const lines = this.editor.getModel().getLinesContent() || [];
751754
const from = indexToLineAndColumn(lines, index);
752755
const to = indexToLineAndColumn(lines, index - op);
753756
this.editor.getModel().applyEdits([
@@ -1098,9 +1101,9 @@ class MonacoEditor extends React.Component<Props, State> implements Editor {
10981101

10991102
updateCode(code: string = '') {
11001103
const pos = this.editor.getPosition();
1101-
const lines = this.editor.getModel().getLinesContent();
1104+
const lines = this.editor.getModel().getLinesContent() || [];
11021105
const lastLine = lines.length;
1103-
const lastLineColumn = lines[lines.length - 1].length;
1106+
const lastLineColumn = (lines[lines.length - 1] || '').length;
11041107
const editOperation = {
11051108
identifier: {
11061109
major: 1,

packages/app/src/app/pages/Sandbox/Editor/Content/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ class EditorPreview extends React.Component<Props, State> {
396396
height={editorHeight}
397397
settings={settings(store)}
398398
sendTransforms={this.sendTransforms}
399-
readOnly={!store.live.isCurrentEditor}
399+
readOnly={!store.live.isCurrentEditor || store.live.reconnecting}
400400
isLive={store.live.isLive}
401401
onCodeReceived={signals.live.onCodeReceived}
402402
onSelectionChanged={signals.live.onSelectionChanged}

packages/app/src/app/pages/Sandbox/Editor/Workspace/items/Live/LiveInfo.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ class LiveInfo extends React.Component {
124124
addEditor,
125125
removeEditor,
126126
currentUserId,
127+
reconnecting,
127128
} = this.props;
128129

129130
const owner = roomInfo.users.find(u => u.id === ownerId);
@@ -145,7 +146,13 @@ class LiveInfo extends React.Component {
145146
<Container>
146147
<Title>
147148
<div style={{ flex: 1, display: 'flex', alignItems: 'center' }}>
148-
<RecordIcon /> {isOwner ? "You've gone live!" : 'You are live!'}
149+
{reconnecting ? (
150+
'Reconnecting...'
151+
) : (
152+
<React.Fragment>
153+
<RecordIcon /> {isOwner ? "You've gone live!" : 'You are live!'}
154+
</React.Fragment>
155+
)}
149156
</div>
150157
<div>
151158
{roomInfo.startTime != null && (

packages/app/src/app/pages/Sandbox/Editor/Workspace/items/Live/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const Live = ({ signals, store }) => (
2121
roomInfo={store.live.roomInfo}
2222
ownerId={store.editor.currentSandbox.author.id}
2323
currentUserId={store.user.id}
24+
reconnecting={store.live.reconnecting}
2425
/>
2526
) : (
2627
<React.Fragment>

packages/app/src/app/store/modules/live/actions.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,20 @@ export function consumeState({ props, ot }) {
107107
roomInfo,
108108
} = props.data;
109109

110-
ot.consumeData(otData);
111-
112110
return {
113111
sandbox,
114112
changedModuleShortids,
115113
tabs,
116114
currentModuleShortid,
117115
roomInfo,
116+
otData,
118117
};
119118
}
120119

120+
export function consumeOTData({ props, ot }) {
121+
ot.consumeData(props.otData);
122+
}
123+
121124
export function sendSelection({ props, state, live }) {
122125
const userId = state.get('user.id');
123126
const moduleShortid = props.moduleShortid;

packages/app/src/app/store/modules/live/sequences.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ export const handleMessage = [
101101
equals(state`live.isLoading`),
102102
{
103103
true: [
104+
actions.consumeOTData,
104105
set(state`editor.sandboxes.${props`sandbox.id`}`, props`sandbox`),
105106
setSandbox,
106107
set(state`editor.tabs`, props`tabs`),

0 commit comments

Comments
 (0)