From 29bf7f9a9192158d0258cee2c2e12d9e9d8b0adf Mon Sep 17 00:00:00 2001 From: Henning Dieterichs Date: Wed, 5 Apr 2023 12:22:20 +0200 Subject: [PATCH] Implements option to disable auto-reload --- .../pages/playground/PlaygroundModel.ts | 19 ++++++++++++++- .../playground/PlaygroundPageContent.tsx | 24 ++++++++++++++++--- .../website/pages/playground/SettingsModel.ts | 10 ++++++++ 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/website/src/website/pages/playground/PlaygroundModel.ts b/website/src/website/pages/playground/PlaygroundModel.ts index 15ae15f8..5f8bdc15 100644 --- a/website/src/website/pages/playground/PlaygroundModel.ts +++ b/website/src/website/pages/playground/PlaygroundModel.ts @@ -56,7 +56,7 @@ export class PlaygroundModel { public readonly serializer = new StateUrlSerializer(this); - reload(): void { + public reload(): void { this.reloadKey++; } @@ -127,12 +127,29 @@ export class PlaygroundModel { private readonly debouncer = new Debouncer(250); + @observable + public isDirty = false; + constructor() { + let lastState = this.state; + this.dispose.track({ dispose: reaction( () => ({ state: this.state }), ({ state }) => { + if (!this.settings.autoReload) { + if ( + JSON.stringify(state.monacoSetup) === + JSON.stringify(lastState.monacoSetup) && + state.key === lastState.key + ) { + this.isDirty = true; + return; + } + } this.debouncer.run(() => { + this.isDirty = false; + lastState = state; for (const handler of this._previewHandlers) { handler.handlePreview(state); } diff --git a/website/src/website/pages/playground/PlaygroundPageContent.tsx b/website/src/website/pages/playground/PlaygroundPageContent.tsx index 7968b323..20eca186 100644 --- a/website/src/website/pages/playground/PlaygroundPageContent.tsx +++ b/website/src/website/pages/playground/PlaygroundPageContent.tsx @@ -18,7 +18,7 @@ import { PlaygroundModel } from "./PlaygroundModel"; import { Preview } from "./Preview"; import { SettingsDialog } from "./SettingsDialog"; import { Button, Col, Row, Stack } from "../../components/bootstrap"; -import { ButtonGroup } from "react-bootstrap"; +import { ButtonGroup, FormCheck } from "react-bootstrap"; @hotComponent(module) @observer @@ -114,11 +114,29 @@ export class PlaygroundPageContent extends React.Component< titleBarItems={
+ {model.settings.previewFullScreen || ( + + (model.settings.autoReload = + e.target.checked) + } + /> + )}