-
-
Notifications
You must be signed in to change notification settings - Fork 362
doc(Layout): improve load theme logic #6598
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9622e92
feat: 增加 GetPreferredThemeAsync 扩展方法
ArgoZhang e6eec99
doc: 更新主题加载逻辑防止抖动
ArgoZhang fbfca6a
perf: 优化性能
ArgoZhang 2d0f70e
Merge branch 'main' into refactor-theme
ArgoZhang dbbd390
refactor: 移除 GetPreferredThemeAsync 扩展方法
ArgoZhang 751b9a5
refactor: 删除 getPreferredTheme 方法
ArgoZhang d4d982a
Merge branch 'main' into refactor-theme
ArgoZhang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 7 additions & 4 deletions
11
src/BootstrapBlazor.Server/Components/Layout/BaseLayout.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,13 +3,21 @@ | |
| // See the LICENSE file in the project root for more information. | ||
| // Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone | ||
|
|
||
| using BootstrapBlazor.Server.Data; | ||
| using Microsoft.Extensions.Options; | ||
| using Microsoft.JSInterop; | ||
|
|
||
| namespace BootstrapBlazor.Server.Components.Layout; | ||
|
|
||
| /// <summary> | ||
| /// 母版页基类 | ||
| /// </summary> | ||
| public partial class BaseLayout : IDisposable | ||
| { | ||
| [Inject] | ||
| [NotNull] | ||
| private IJSRuntime? JSRuntime { get; set; } | ||
|
|
||
| [Inject] | ||
| [NotNull] | ||
| private IStringLocalizer<BaseLayout>? Localizer { get; set; } | ||
|
|
@@ -26,6 +34,10 @@ public partial class BaseLayout : IDisposable | |
| [NotNull] | ||
| private IDispatchService<bool>? RebootDispatchService { get; set; } | ||
|
|
||
| [Inject] | ||
| [NotNull] | ||
| private IOptions<WebsiteOptions>? WebsiteOption { get; set; } | ||
|
|
||
| [NotNull] | ||
| private string? FlowText { get; set; } | ||
|
|
||
|
|
@@ -38,6 +50,8 @@ public partial class BaseLayout : IDisposable | |
| [NotNull] | ||
| private string? CancelText { get; set; } | ||
|
|
||
| private bool _init = false; | ||
|
|
||
| /// <summary> | ||
| /// <inheritdoc/> | ||
| /// </summary> | ||
|
|
@@ -54,6 +68,19 @@ protected override void OnInitialized() | |
| RebootDispatchService.Subscribe(NotifyReboot); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// <inheritdoc/> | ||
| /// </summary> | ||
| /// <returns></returns> | ||
| protected override async Task OnInitializedAsync() | ||
| { | ||
| await base.OnInitializedAsync(); | ||
|
|
||
| var module = await JSRuntime.LoadModule($"{WebsiteOption.Value.JSModuleRootPath}Layout/BaseLayout.razor.js"); | ||
| await module.InvokeVoidAsync("initTheme"); | ||
| _init = true; | ||
| } | ||
|
|
||
| private async Task NotifyCommit(DispatchEntry<GiteePostBody> payload) | ||
| { | ||
| if (payload.CanDispatch()) | ||
|
|
||
6 changes: 6 additions & 0 deletions
6
src/BootstrapBlazor.Server/Components/Layout/BaseLayout.razor.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { getTheme, setTheme } from "../../_content/BootstrapBlazor/modules/utility.js" | ||
|
|
||
| export function initTheme() { | ||
| const currentTheme = getTheme(); | ||
| setTheme(currentTheme, false); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (performance): Delaying layout rendering until _init is true may impact perceived performance.
If initialization is asynchronous, users may experience a blank screen. Display a loading indicator or fallback UI during this period.