Skip to content

Commit

Permalink
Merge branch 'blazor-server-support'
Browse files Browse the repository at this point in the history
  • Loading branch information
jsakamoto committed Apr 3, 2024
2 parents e5b2856 + 65b4858 commit aed5982
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
10 changes: 8 additions & 2 deletions BlazingStory/Internals/Addons/Background/BackgroundAddon.razor
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,18 @@

private BackgroundMode _BackgroundMode = BackgroundMode.None;

protected override async Task OnInitializedAsync()
protected override void OnInitialized()
{
this.HelperScript = this.Services.GetRequiredService<HelperScript>();
this.AddonsStore.RegisterAddon(this);
}

protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (!firstRender) return;

var backgroudnModeStr = await this.HelperScript.GetLocalStorageItemAsync(StorageKeys.BackgroundMode);
this._BackgroundMode = Enum.TryParse<BackgroundMode>(backgroudnModeStr, out var backgroundMode) ? backgroundMode : BackgroundMode.None;
this.AddonsStore.RegisterAddon(this);
this.SetFrameArguments();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,18 @@
);
}

protected override async Task OnInitializedAsync()
protected override void OnInitialized()
{
this.HelperScript = this.Services.GetRequiredService<HelperScript>();
this._CurrentState = await this.HelperScript.LoadObjectFromLocalStorageAsync(StorageKey, this._CurrentState);
this.AddonsStore.RegisterAddon(this);
}

protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (!firstRender) return;
this._CurrentState = await this.HelperScript.LoadObjectFromLocalStorageAsync(StorageKey, this._CurrentState);
}

private async Task OnClickSize(SizeType size)
{
if (size == SizeType.None) await Task.Delay(10);
Expand Down
9 changes: 7 additions & 2 deletions BlazingStory/Internals/Addons/CommonAddonComponent.razor
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,17 @@

public IReadOnlyDictionary<string, object?> FrameArguments => _FrameArguments;

protected override async Task OnInitializedAsync()
protected override void OnInitialized()
{
this.HelperScript = this.Services.GetRequiredService<HelperScript>();
this.AddonsStore.RegisterAddon(this);
}

protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (!firstRender) return;
var enableStr = await this.HelperScript.GetLocalStorageItemAsync(StorageKey);
this._Enable = bool.TryParse(enableStr, out var enable) ? enable : this._Enable;
this.AddonsStore.RegisterAddon(this);
this.SetFrameArguments();
}

Expand Down
13 changes: 13 additions & 0 deletions BlazingStory/Internals/Pages/Canvas/CanvasFrame.razor
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ else

private bool _EnableMeasure = false;

private bool _Rendered = false;

/// <summary>
/// Constructor
/// </summary>
Expand All @@ -74,6 +76,14 @@ else
this.StateHasChanged();
}

protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (!firstRender) return;
this._Rendered = true;
await UpdateComponentStatesAsync();
this.StateHasChanged();
}

/// <summary>
/// When the state of the story has been changed, this canvas frame should be re-rendered.
/// </summary>
Expand Down Expand Up @@ -124,6 +134,9 @@ else

private async ValueTask UpdateGlobalEffectsFromUrlAsync(NameValueCollection queryStrings)
{
// If it is during the server-side pre-rendering, nothing to do.
if (!this._Rendered) return;

var globalEffectsString = queryStrings["globals"] ?? "";
if (this._GlobalEffectsString == globalEffectsString) return;
this._GlobalEffectsString = globalEffectsString;
Expand Down

0 comments on commit aed5982

Please sign in to comment.