Skip to content

Commit c7960b4

Browse files
author
Ives van Hoorne
committed
Clear console preference
1 parent d5446a3 commit c7960b4

File tree

6 files changed

+31
-1
lines changed

6 files changed

+31
-1
lines changed

src/app/components/sandbox/Preview/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,11 @@ export default class Preview extends React.PureComponent {
196196
module,
197197
sandboxId,
198198
externalResources,
199+
preferences,
199200
} = this.props;
200-
201+
if (preferences.clearConsoleEnabled) {
202+
console.clear();
203+
}
201204
if (bundle.externals == null) {
202205
if (!bundle.processing && !bundle.error) {
203206
this.fetchBundle();

src/app/pages/Sandbox/Editor/Workspace/Preferences/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ const Preferences = ({ preferences, preferencesActions }: Props) => (
7070
setValue={preferencesActions.setLivePreview}
7171
tooltip="Only update on save"
7272
/>
73+
<Preference
74+
title="Clear console"
75+
value={preferences.clearConsoleEnabled}
76+
setValue={preferencesActions.setClearConsolePreference}
77+
tooltip="Clear console when executing"
78+
/>
7379
<Preference
7480
title="Instant preview"
7581
value={preferences.instantPreviewEnabled}

src/app/store/preferences/actions.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
LINT_ENABLED,
99
INSTANT_PREVIEW,
1010
FONT_SIZE,
11+
CLEAR_CONSOLE,
1112
} from './keys';
1213

1314
export const SET_PREFERENCE_AUTOCOMPLETE = 'SET_PREFERENCE_AUTOCOMPLETE';
@@ -18,6 +19,7 @@ export const SET_PREFERENCE_PRETTIFY_ON_SAVE =
1819
'SET_PREFERENCE_PRETTIFY_ON_SAVE';
1920
export const SET_PREFERENCE_LINT = 'SET_PREFERENCE_LINT';
2021
export const SET_INSTANT_PREVIEW = 'SET_INSTANT_PREVIEW';
22+
export const SET_CLEAR_CONSOLE = 'SET_CLEAR_CONSOLE';
2123

2224
const setOption = (key, val) => {
2325
try {
@@ -68,6 +70,17 @@ export default {
6870
});
6971
},
7072

73+
setClearConsolePreference: (clearConsole: boolean) => (
74+
dispatch: Function,
75+
) => {
76+
setOption(CLEAR_CONSOLE, clearConsole);
77+
78+
dispatch({
79+
type: SET_CLEAR_CONSOLE,
80+
option: clearConsole,
81+
});
82+
},
83+
7184
setLintPreference: (lint: boolean) => (dispatch: Function) => {
7285
setOption(LINT_ENABLED, lint);
7386

src/app/store/preferences/keys.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ export const INSTANT_PREVIEW = 'settings.instantpreview';
55
export const PRETTIFY_ON_SAVE = 'settings.prettifyonsave';
66
export const LINT_ENABLED = 'settings.lintenabled';
77
export const FONT_SIZE = 'settings.fontsize';
8+
export const CLEAR_CONSOLE = 'settings.clearconsole';

src/app/store/preferences/reducer.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
SET_PREFERENCE_LINT,
1212
SET_INSTANT_PREVIEW,
1313
SET_PREFERENCE_FONT_SIZE,
14+
SET_CLEAR_CONSOLE,
1415
} from './actions';
1516
import {
1617
AUTO_COMPLETE,
@@ -20,6 +21,7 @@ import {
2021
LINT_ENABLED,
2122
INSTANT_PREVIEW,
2223
FONT_SIZE,
24+
CLEAR_CONSOLE,
2325
} from './keys';
2426

2527
const getKey = (key, defaultVal) => {
@@ -40,6 +42,7 @@ const initialState: Preferences = {
4042
lintEnabled: getKey(LINT_ENABLED, false),
4143
instantPreviewEnabled: getKey(INSTANT_PREVIEW, false),
4244
fontSize: getKey(FONT_SIZE, 14),
45+
clearConsoleEnabled: getKey(CLEAR_CONSOLE, false),
4346
};
4447

4548
export default (state: Preferences = initialState, action): Preferences => {
@@ -58,6 +61,8 @@ export default (state: Preferences = initialState, action): Preferences => {
5861
return { ...state, instantPreviewEnabled: action.option };
5962
case SET_PREFERENCE_FONT_SIZE:
6063
return { ...state, fontSize: action.option };
64+
case SET_CLEAR_CONSOLE:
65+
return { ...state, clearConsoleEnabled: action.option };
6166
default: {
6267
return state;
6368
}

src/common/types.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ export type Preferences = {
9292
prettifyOnSaveEnabled: boolean,
9393
lintEnabled: boolean,
9494
instantPreviewEnabled: boolean,
95+
fontSize: number,
96+
clearConsoleEnabled: boolean,
9597
};
9698

9799
export type NotificationButton = {

0 commit comments

Comments
 (0)