-
-
Notifications
You must be signed in to change notification settings - Fork 376
chore(Vote): remove gitee vote #7489
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| @inherits WebSiteModuleComponentBase | ||
|
|
||
| @code { | ||
| RenderFragment RenderVote => | ||
| @<div> | ||
| <div style="font-size: 48px; text-align: center;">🏆</div> | ||
| <p class="text-center mt-2">正在参加 <b>Gitee 2025 最受欢迎的开源软件</b> 投票活动,快来给我投票吧!</p> | ||
| <div class="my-3 text-center">您的每一票都是对开源社区的支持,感谢您的参与!</div> | ||
| <div style="display: flex; justify-content: space-around;" id="bb-g-toast"> | ||
| <a href="https://gitee.com/activity/2025opensource?ident=I6MYBB" target="_blank" style="font-weight: bold; padding: 6px 12px; border-radius: var(--bs-border-radius); background: linear-gradient(135deg, #667eea, #764ba2); color: #fff;">🚀 必须投一票</a> | ||
| <a href="https://gitee.com/activity/2025opensource?ident=I6MYBB" target="_blank" class="text-muted" style="padding: 6px 12px;" title="老六你居然不投票">我知道了</a> | ||
| </div> | ||
| </div>; | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,50 @@ | ||||||
| // Licensed to the .NET Foundation under one or more agreements. | ||||||
| // The .NET Foundation licenses this file to you under the Apache 2.0 License | ||||||
| // See the LICENSE file in the project root for more information. | ||||||
| // Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone | ||||||
|
|
||||||
| using Microsoft.JSInterop; | ||||||
| using System.Globalization; | ||||||
|
|
||||||
| namespace BootstrapBlazor.Server.Components.Components; | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// 正站通知组件 | ||||||
|
||||||
| /// 正站通知组件 | |
| /// 全站通知组件 |
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 (bug_risk): The JS init function defines a debug parameter that is never set, so the debug behavior cannot be controlled.
GlobalToast.razor.js exports init(invoke, method, debug) and uses if (debug !== true) to decide whether to schedule the toast. InvokeInitAsync only passes Interop and the method name, so debug is always undefined and the toast is always scheduled. Either pass an IsDevelopment/similar flag as the third argument, or remove the debug parameter and related branching in JS to avoid dead configuration.
Suggested implementation:
public partial class GlobalToast
{
[Inject]
[NotNull]
private ToastService? Toast { get; set; }
[Inject]
private IWebHostEnvironment? HostEnvironment { get; set; }
/// <summary> /// <inheritdoc/>
protected override Task InvokeInitAsync() =>
InvokeVoidAsync("init", Interop, nameof(ShowToast), HostEnvironment?.IsDevelopment() == true);- Ensure the file has
using Microsoft.AspNetCore.Hosting;orusing Microsoft.Extensions.Hosting;at the top, depending on which hosting environment type your project already uses. If the project usesIHostEnvironmentinstead ofIWebHostEnvironment, change the injected type accordingly and keep using.IsDevelopment(). - No changes are required in
GlobalToast.razor.jsif its exportedinitsignature remainsinit(invoke, method, debug)and it already branches ondebugusingif (debug !== true) { ... }. With these changes,debugwill betruein development andundefined/falseotherwise.
Copilot
AI
Jan 10, 2026
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.
The GlobalToast component needs access to WebsiteOption to pass the IsDevelopment flag to the JavaScript init function (as done in the original BaseLayout implementation). Since WebSiteModuleComponentBase has WebsiteOption as a private field, GlobalToast should inject IOptions<WebsiteOptions> and pass WebsiteOption.Value.IsDevelopment as the third parameter to InvokeInitAsync.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import EventHandler from "../../_content/BootstrapBlazor/modules/event-handler.js" | ||
|
|
||
| export function init(invoke, method, debug) { | ||
| const localstorageKey = 'bb-g-toast' | ||
| const v = localStorage.getItem(localstorageKey); | ||
| if (v) { | ||
| try { | ||
| const differ = new Date().getTime() - v; | ||
| if (differ < 86400000) { | ||
| return; | ||
| } | ||
| } | ||
| catch { | ||
| localStorage.removeItem(localstorageKey); | ||
| } | ||
| } | ||
|
|
||
| if (debug !== true) { | ||
| const handler = setTimeout(async () => { | ||
| clearTimeout(handler); | ||
| await invoke.invokeMethodAsync(method); | ||
| }, 10000); | ||
| } | ||
|
|
||
| EventHandler.on(document, 'click', '#bb-g-toast', e => { | ||
| const toast = e.delegateTarget.closest('.toast'); | ||
| if (toast) { | ||
| toast.classList.remove('show'); | ||
|
|
||
| localStorage.setItem(localstorageKey, new Date().getTime()); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| export function dispose() { | ||
| EventHandler.off(document, 'click', '#bb-g-toast'); | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,14 +5,13 @@ | |||||||
|
|
||||||||
| using Microsoft.Extensions.Options; | ||||||||
| using Microsoft.JSInterop; | ||||||||
| using System.Globalization; | ||||||||
|
|
||||||||
| namespace BootstrapBlazor.Server.Components.Layout; | ||||||||
|
|
||||||||
| /// <summary> | ||||||||
| /// 母版页基类 | ||||||||
| /// </summary> | ||||||||
| public partial class BaseLayout : IAsyncDisposable | ||||||||
| public partial class BaseLayout : IDisposable | ||||||||
| { | ||||||||
| [Inject] | ||||||||
| [NotNull] | ||||||||
|
|
@@ -51,8 +50,6 @@ public partial class BaseLayout : IAsyncDisposable | |||||||
| private string? CancelText { get; set; } | ||||||||
|
|
||||||||
| private bool _init = false; | ||||||||
| private JSModule? _module; | ||||||||
| private DotNetObjectReference<BaseLayout>? _interop; | ||||||||
|
|
||||||||
| /// <summary> | ||||||||
| /// <inheritdoc/> | ||||||||
|
|
@@ -74,18 +71,13 @@ protected override void OnInitialized() | |||||||
| /// <inheritdoc/> | ||||||||
| /// </summary> | ||||||||
| /// <returns></returns> | ||||||||
| protected override async Task OnAfterRenderAsync(bool firstRender) | ||||||||
| protected override async Task OnInitializedAsync() | ||||||||
| { | ||||||||
| await base.OnAfterRenderAsync(firstRender); | ||||||||
| await base.OnInitializedAsync(); | ||||||||
|
|
||||||||
| if (firstRender) | ||||||||
| { | ||||||||
| _module = await JSRuntime.LoadModule($"{WebsiteOption.Value.JSModuleRootPath}Layout/BaseLayout.razor.js"); | ||||||||
| _interop = DotNetObjectReference.Create(this); | ||||||||
| await _module.InvokeVoidAsync("doTask", _interop, WebsiteOption.Value.IsDevelopment); | ||||||||
| _init = true; | ||||||||
| StateHasChanged(); | ||||||||
| } | ||||||||
| var module = await JSRuntime.LoadModule($"{WebsiteOption.Value.JSModuleRootPath}Layout/BaseLayout.razor.js"); | ||||||||
| await module.InvokeVoidAsync("initTheme"); | ||||||||
|
Comment on lines
+78
to
+79
|
||||||||
| _init = true; | ||||||||
|
Comment on lines
+74
to
+80
|
||||||||
| _init = true; | |
| _init = true; | |
| await InvokeAsync(StateHasChanged); |
Copilot
AI
Jan 10, 2026
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.
The change from IAsyncDisposable to IDisposable is problematic because the previous implementation needed to dispose of JSModule asynchronously. While the current code doesn't store the module reference, if async disposal is needed in the future (which is likely given that JSModule disposal is async), this change will require reverting back to IAsyncDisposable. Consider keeping IAsyncDisposable for consistency with JavaScript interop best practices.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,44 +1,6 @@ | ||
| import { getTheme, setTheme } from "../../_content/BootstrapBlazor/modules/utility.js" | ||
| import EventHandler from "../../_content/BootstrapBlazor/modules/event-handler.js" | ||
|
|
||
| function initTheme() { | ||
| export function initTheme() { | ||
| const currentTheme = getTheme(); | ||
| setTheme(currentTheme, false); | ||
| } | ||
|
|
||
| export function doTask(invoke, debug) { | ||
| initTheme(); | ||
|
|
||
| const v = localStorage.getItem('bb-gitee-vote'); | ||
| if (v) { | ||
| try { | ||
| const differ = new Date().getTime() - v; | ||
| if (differ < 86400000) { | ||
| return; | ||
| } | ||
| } | ||
| catch { | ||
| localStorage.removeItem('bb-gitee-vote'); | ||
| } | ||
| } | ||
|
|
||
| if (debug !== true) { | ||
| const handler = setTimeout(async () => { | ||
| clearTimeout(handler); | ||
| await invoke.invokeMethodAsync("ShowVoteToast"); | ||
| }, 10000); | ||
| } | ||
|
|
||
| EventHandler.on(document, 'click', '#bb-gitee-vote', e => { | ||
| const toast = e.delegateTarget.closest('.toast'); | ||
| if (toast) { | ||
| toast.classList.remove('show'); | ||
|
|
||
| localStorage.setItem('bb-gitee-vote', new Date().getTime()); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| export function dispose() { | ||
| EventHandler.off(document, 'click', '#bb-gitee-vote'); | ||
| } |
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.
The GlobalToast component has been created but is not instantiated anywhere in the application. The vote toast functionality was removed from BaseLayout, but the new GlobalToast component needs to be added to a layout or component for the functionality to work. Consider adding <GlobalToast /> to BaseLayout.razor or another appropriate location.