Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements option to disable auto-reload #3889

Merged
merged 1 commit into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion website/src/website/pages/playground/PlaygroundModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class PlaygroundModel {

public readonly serializer = new StateUrlSerializer(this);

reload(): void {
public reload(): void {
this.reloadKey++;
}

Expand Down Expand Up @@ -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);
}
Expand Down
24 changes: 21 additions & 3 deletions website/src/website/pages/playground/PlaygroundPageContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -114,11 +114,29 @@ export class PlaygroundPageContent extends React.Component<
titleBarItems={
<div
style={{ marginLeft: "auto" }}
className="d-flex gap-2"
className="d-flex gap-2 align-items-center"
>
{model.settings.previewFullScreen || (
<FormCheck
label="Auto-Reload"
className="text-nowrap"
checked={
model.settings.autoReload
}
onChange={(e) =>
(model.settings.autoReload =
e.target.checked)
}
/>
)}
<Button
type="button"
className="btn btn-light settings bi-arrow-clockwise"
className={
"btn settings bi-arrow-clockwise " +
(model.isDirty
? "btn-primary"
: "btn-light")
}
style={{
fontSize: 20,
padding: "0px 4px",
Expand Down
10 changes: 10 additions & 0 deletions website/src/website/pages/playground/SettingsModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ export class SettingsModel {
this.setSettings({ ...this._settings, previewFullScreen: value });
}

get autoReload() {
return this._settings.autoReload ?? true;
}

set autoReload(value: boolean) {
this.setSettings({ ...this._settings, autoReload: value });
}

constructor() {
const settingsStr = localStorage.getItem(this.settingsKey);
if (settingsStr) {
Expand Down Expand Up @@ -70,6 +78,7 @@ export interface Settings {
customConfig: JsonString<IMonacoSetup>;

previewFullScreen: boolean;
autoReload: boolean | undefined;
}

export type JsonString<T> = string;
Expand Down Expand Up @@ -167,6 +176,7 @@ export function getDefaultSettings(): Settings {
loaderPathsConfig: "",
}),
previewFullScreen: false,
autoReload: true,
};
return defaultSettings;
}
Expand Down