Skip to content

Commit

Permalink
Adds "use latest dev" button
Browse files Browse the repository at this point in the history
  • Loading branch information
hediet committed Aug 28, 2023
1 parent 31b04af commit 57ac88c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
32 changes: 23 additions & 9 deletions website/src/website/pages/playground/PlaygroundModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,16 @@ class StateUrlSerializer implements IHistoryModel {
this.historyId++;
}

@action
useLatestDev(): void {
this._sourceOverride = undefined;
this.model.settings.setSettings({
...this.model.settings.settings,
...Source.useLatestDev().toPartialSettings(),
});
this.historyId++;
}

@action
saveSourceOverride(): void {
if (this._sourceOverride) {
Expand Down Expand Up @@ -662,22 +672,26 @@ function findLastIndex<T>(
}

class Source {
public static useLatestDev(sourceLanguagesStr?: string): Source {
// Assume the versions are already loaded
const versions = getNpmVersionsSync(undefined);
const version = versions.find((v) => v.indexOf("-dev-") !== -1);
return new Source(version, undefined, sourceLanguagesStr);
}

public static useLatest(sourceLanguagesStr?: string): Source {
return new Source(monacoEditorVersion, undefined, sourceLanguagesStr);
}

public static parse(
sourceStr: string | undefined,
sourceLanguagesStr: string | undefined
): Source {
if (sourceStr === "latest-dev") {
// The versions are already loaded
const versions = getNpmVersionsSync(undefined);
const version = versions.find((v) => v.indexOf("-dev-") !== -1);
return new Source(version, undefined, sourceLanguagesStr);
return Source.useLatestDev(sourceLanguagesStr);
}
if (sourceStr === "latest") {
return new Source(
monacoEditorVersion,
undefined,
sourceLanguagesStr
);
return Source.useLatest(sourceLanguagesStr);
}

if (sourceStr && sourceStr.startsWith("v")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,15 @@ export class PlaygroundPageContent extends React.Component<
.version ?? "url"}{" "}
override
</button>
<button
type="button"
className="btn btn-secondary"
onClick={() =>
model.serializer.useLatestDev()
}
>
Use latest dev
</button>
<button
type="button"
className="btn btn-secondary"
Expand Down
2 changes: 2 additions & 0 deletions website/src/website/pages/playground/getNpmVersionsSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export async function getNpmVersions(): Promise<string[]> {
return npmVersionsPromise!;
}

getNpmVersions();

async function loadNpmVersions(): Promise<string[]> {
if (npmVersionsPromise === undefined) {
npmVersionsPromise = _getNpmVersions();
Expand Down

0 comments on commit 57ac88c

Please sign in to comment.