Skip to content

Commit

Permalink
Remove loading indication for Monaco (#1260)
Browse files Browse the repository at this point in the history
* Remove loading indication for Monaco

* removed unused variable
  • Loading branch information
veler authored Jun 25, 2024
1 parent 08a556a commit 93c9de0
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
<div class="monaco-editor-standalone-container @(IsActuallyEnabled ? string.Empty : "disabled")"
@ref=Element>

<ProgressRing id="@($"{Id}-loading")"
IsIndeterminate="@ShowLoading"
IsVisible="@ShowLoading" />

<div id="@Id" class="monaco-editor-standalone-instance @(IsActuallyEnabled ? string.Empty : "disabled")"></div>

<div class="monaco-editor-standalone-underline" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ public MonacoEditor(IJSRuntime? jsRuntime = null, string? id = null, string? @cl
[Parameter]
public UITextLineNumber? LineNumberMode { get; set; }

private bool ShowLoading { get; set; }

protected override void OnInitialized()
{
base.OnInitialized();
Expand All @@ -67,8 +65,6 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
InvokeAsync(DisplayLoadingIfSlowLoadingAsync).Forget();

// Get desired options
StandaloneEditorConstructionOptions options = ConstructionOptions?.Invoke(this) ?? new();

Expand Down Expand Up @@ -145,7 +141,6 @@ protected override void OnEditorLoaded()
lock (_lock)
{
_isLoaded = true;
ShowLoading = false;

if (SettingsProvider is not null)
{
Expand Down Expand Up @@ -190,27 +185,6 @@ private string GetTheme()
return _themeListener.ActualAppTheme == ApplicationTheme.Dark ? BuiltinTheme.VsDark : BuiltinTheme.Vs;
}

private async Task DisplayLoadingIfSlowLoadingAsync()
{
// Let's not show the progress ring during the first 100ms. We know customers tends to perceive anything
// faster than 100ms as "instant", so no need to bother the user with a very shortly displayed progress ring
// if we succeed to load within 100ms.
// https://psychology.stackexchange.com/questions/1664/what-is-the-threshold-where-actions-are-perceived-as-instant

const int Delay = 100;

await Task.Delay(Delay);

lock (_lock)
{
if (!_isLoaded)
{
ShowLoading = true;
StateHasChanged();
}
}
}

private void ApplyWordWrapOption(EditorOptions editorOptions)
{
switch (WrapMode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
<div class="monaco-editor-standalone-container @(IsActuallyEnabled ? string.Empty : "disabled")"
@ref=Element>

<ProgressRing id="@($"{Id}-loading")"
IsIndeterminate="@ShowLoading"
IsVisible="@ShowLoading" />

<div id="@Id" class="monaco-editor-standalone-instance"></div>

<div class="monaco-editor-standalone-underline" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace DevToys.Blazor.Components;
public partial class MonacoEditorDiff : RicherMonacoEditorDiffBase
{
private readonly object _lock = new();
private bool _isLoaded;
private bool _oldIsActuallyEnabled;
private bool _oldReadOnlyState;

Expand All @@ -21,8 +20,6 @@ public partial class MonacoEditorDiff : RicherMonacoEditorDiffBase
[Parameter]
public Func<MonacoEditorDiff, StandaloneDiffEditorConstructionOptions>? ConstructionOptions { get; set; }

private bool ShowLoading { get; set; }

protected override void OnInitialized()
{
base.OnInitialized();
Expand All @@ -39,8 +36,6 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
Guard.IsNull(OriginalEditor);
Guard.IsNull(ModifiedEditor);

InvokeAsync(DisplayLoadingIfSlowLoadingAsync).Forget();

// Get desired options
StandaloneDiffEditorConstructionOptions options = ConstructionOptions?.Invoke(this) ?? new();

Expand Down Expand Up @@ -133,8 +128,6 @@ protected override void OnEditorLoaded()
base.OnEditorLoaded();
lock (_lock)
{
_isLoaded = true;
ShowLoading = false;
StateHasChanged();
}
}
Expand Down Expand Up @@ -163,25 +156,4 @@ private string GetTheme()
Guard.IsNotNull(_themeListener);
return _themeListener.ActualAppTheme == ApplicationTheme.Dark ? BuiltinTheme.VsDark : BuiltinTheme.Vs;
}

private async Task DisplayLoadingIfSlowLoadingAsync()
{
// Let's not show the progress ring during the first 100ms. We know customers tends to perceive anything
// faster than 100ms as "instant", so no need to bother the user with a very shortly displayed progress ring
// if we succeed to load within 100ms.
// https://psychology.stackexchange.com/questions/1664/what-is-the-threshold-where-actions-are-perceived-as-instant

const int Delay = 100;

await Task.Delay(Delay);

lock (_lock)
{
if (!_isLoaded)
{
ShowLoading = true;
StateHasChanged();
}
}
}
}

0 comments on commit 93c9de0

Please sign in to comment.