Skip to content

Commit 39eff5a

Browse files
committed
Fix showing message of readonly shell on every shell
1 parent 674cda5 commit 39eff5a

File tree

2 files changed

+30
-35
lines changed

2 files changed

+30
-35
lines changed

packages/app/src/app/components/Preview/DevTools/Terminal/Shell/Term.tsx

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ import * as fit from 'xterm/lib/addons/fit/fit';
55

66
import ResizeObserver from 'resize-observer-polyfill';
77

8-
import { notificationState } from '@codesandbox/common/lib/utils/notifications';
9-
import { dispatch } from 'codesandbox-api';
10-
import { NotificationStatus } from '@codesandbox/notifications';
118
import getTerminalTheme, { VSTheme } from '../terminal-theme';
129
import { TerminalWithFit } from '../types';
1310

@@ -39,37 +36,6 @@ export class TerminalComponentNoTheme extends React.PureComponent<Props> {
3936
this.resizeTerminal();
4037
window.addEventListener('resize', this.listenForResize);
4138

42-
let shownNotification = false;
43-
44-
this.term.on('data', () => {
45-
// This is readonly, so let the user know they need to open a new
46-
// terminal
47-
48-
if (!shownNotification) {
49-
if (this.props.owned) {
50-
notificationState.addNotification({
51-
title: 'Terminal Read-Only',
52-
message:
53-
"The main terminal is read-only and runs what's defined in package.json#start, you can create a new terminal to input commands",
54-
status: NotificationStatus.NOTICE,
55-
actions: {
56-
primary: [
57-
{
58-
label: 'Create Terminal',
59-
run: () => {
60-
dispatch({
61-
type: 'codesandbox:create-shell',
62-
});
63-
},
64-
},
65-
],
66-
},
67-
});
68-
}
69-
shownNotification = true;
70-
}
71-
});
72-
7339
this.props.onTerminalInitialized(this.term);
7440
};
7541

packages/app/src/app/components/Preview/DevTools/Terminal/index.tsx

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import './styles.css';
22

3-
import { listen } from 'codesandbox-api';
3+
import { listen, dispatch } from 'codesandbox-api';
44
import React from 'react';
55
import PlusIcon from 'react-icons/lib/md/add';
66
import { withTheme } from 'styled-components';
77
import uuid from 'uuid';
88

9+
import { notificationState } from '@codesandbox/common/lib/utils/notifications';
10+
import { NotificationStatus } from '@codesandbox/notifications';
911
import { Shell } from './Shell';
1012
import { TerminalComponent } from './Shell/Term';
1113
import { ShellTabs } from './ShellTabs';
@@ -36,6 +38,7 @@ class DevToolTerminal extends React.Component<
3638
listener: () => void;
3739
node?: HTMLElement;
3840
timeout?: number;
41+
shownReadonlyNotification: boolean = false;
3942

4043
componentDidMount() {
4144
createShell = this.createShell;
@@ -48,6 +51,32 @@ class DevToolTerminal extends React.Component<
4851

4952
this.messageQueue.forEach(this.handleMessage);
5053
this.messageQueue.length = 0;
54+
55+
terminal.on('data', () => {
56+
if (this.props.owned) {
57+
if (!this.shownReadonlyNotification) {
58+
notificationState.addNotification({
59+
title: 'Terminal Read-Only',
60+
message:
61+
"The main terminal is read-only and runs what's defined in package.json#start, you can create a new terminal to input commands",
62+
status: NotificationStatus.NOTICE,
63+
actions: {
64+
primary: [
65+
{
66+
label: 'Create Terminal',
67+
run: () => {
68+
dispatch({
69+
type: 'codesandbox:create-shell',
70+
});
71+
},
72+
},
73+
],
74+
},
75+
});
76+
}
77+
this.shownReadonlyNotification = true;
78+
}
79+
});
5180
};
5281

5382
handleMessage = (data: any) => {

0 commit comments

Comments
 (0)