Skip to content
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

Feature/webworker #58

Merged
merged 3 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 48 additions & 5 deletions OneShelf.Frontend/OneShelf.Frontend.Web/Pages/User.razor
Original file line number Diff line number Diff line change
@@ -1,25 +1,53 @@
@page "/user"
@using SpawnDev.BlazorJS
@inject IdentityProvider IdentityProvider
@inject NavigationManager NavigationManager
@inject BlazorJSRuntime BlazorJsRuntime

<PageTitle>Профиль</PageTitle>

<h1>Добрый день, @_title</h1>

@if (!Unauthorized)
{
<div>Не знаю, зачем нужна эта страница, обычно она везде есть. Вы можете присоединяться к клубам, напишите админам. Можно выйти (ваш шортлист будет с вами при следующем входе):</div>
<div class="mb-3">Вы можете присоединяться к клубам, напишите админам.</div>
}

<button class="btn btn-primary" @onclick="Logout">Выйти</button>
@if (IdentityProvider.Identity != null)
{
<button class="btn btn-primary mb-3" @onclick="Logout">Выйти</button>
}
else
{
<h1>Вам бы войти бы:</h1>
<button class="btn btn-primary mb-3" @onclick="() => IdentityProvider.EnsureAuthorized()">Войти</button>
}

@if (Unauthorized)
{
<div>Может быть, вы видите это сообщение по ошибке. Если вам кажется, что доступ должен быть, тем более, напишите, пожалуйста. Спасибо.</div>
<div class="mb-3">Может быть, вы видите это сообщение по ошибке. Если вам кажется, что доступ должен быть, тем более, напишите, пожалуйста. Спасибо.</div>
}

<h3>Совместимость</h3>
<div class="mb-3">Это для случаев если приложение не загружается с первого раза. Не включайте режим совместимости, если всё работает.</div>
<div>
<label>
<input type="checkbox" disabled="disabled" checked="@(_isCompatMode)"/>
Совместимость сейчас
</label>
</div>
<div>
<label>
<input type="checkbox" disabled="disabled" checked="@(_forceCompatMode)" />
Совместимость всегда
<button @onclick="SwitchForceCompatMode">@(_forceCompatMode ? "Выключить" : "Включить")</button>
</label>
</div>

@code {
private string? _title;
private bool _isCompatMode;
private bool _forceCompatMode;

[Parameter]
[SupplyParameterFromQuery]
Expand All @@ -29,9 +57,10 @@
{
await base.OnInitializedAsync();

if (!IdentityProvider.EnsureAuthorized()) return;
_title = IdentityProvider.Identity?.Title;

_title = IdentityProvider.RequiredIdentity.Title;
_isCompatMode = BlazorJsRuntime.WindowThis!.JSRef!.Get<bool>("useCompatMode");
_forceCompatMode = BlazorJsRuntime.WindowThis.LocalStorage.GetItem("forceCompatMode") == "1";
}

protected override async Task OnParametersSetAsync()
Expand All @@ -45,4 +74,18 @@
NavigationManager.NavigateTo("/");
}

private void SwitchForceCompatMode()
{
if (_forceCompatMode)
{
BlazorJsRuntime.WindowThis!.LocalStorage.RemoveItem("forceCompatMode");
}
else
{
BlazorJsRuntime.WindowThis!.LocalStorage.SetItem("forceCompatMode", "1");
}

BlazorJsRuntime.WindowThis!.Location.Reload();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,10 @@ public async Task ScrollToTop()
var module = await _jsRuntime.InvokeAsync<IJSObjectReference>("import", $"./services-js/{GetType().Name}.js");
await module.InvokeVoidAsync("ScrollToTop");
}

public async Task FirstInitSuccessful()
{
var module = await _jsRuntime.InvokeAsync<IJSObjectReference>("import", $"./services-js/{GetType().Name}.js");
await module.InvokeVoidAsync("FirstInitSuccessful");
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@using OneShelf.Frontend.Web.Components
@inherits LayoutComponentBase
@inject IJSRuntime Js
@inject JsFunctions JsFunctions

<!-- Main navbar -->
<div class="navbar navbar-dark navbar-expand-lg navbar-static border-bottom border-bottom-white border-opacity-10 my-navbar-black @(_just ? "my-navbar-black-body-just" : string.Empty)">
Expand Down Expand Up @@ -87,6 +88,7 @@
if (firstRender)
{
await module.InvokeVoidAsync("MainLayoutRendered");
await JsFunctions.FirstInitSuccessful();
}

await module.InvokeVoidAsync("InitSecondToTop");
Expand Down
5 changes: 5 additions & 0 deletions OneShelf.Frontend/OneShelf.Frontend.Web/wwwroot/css/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@
}


#error-info {
color: darkgreen;
}


#my-preview div.chords-block {
span.chords-double-line {
line-height: 42px;
Expand Down
21 changes: 20 additions & 1 deletion OneShelf.Frontend/OneShelf.Frontend.Web/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,12 @@

<div id="blazor-error-ui">
Случилась ошибка.
<span id="error-info"></span>
<a href="" class="reload">Обновить</a>
<span id="error-compat-mode">
<span>|</span>
<button href="#" onclick="location.href = '?forceCompatMode=1'">попробовать совместимость</button>
</span>
<a class="dismiss">🗙</a>
</div>
<script src="sw-registrator.js"></script>
Expand All @@ -170,7 +175,7 @@
(async () => {
var url = new URL(location.href);
let verboseStart = url.searchParams.get('verboseStart') === '1';
var forceCompatMode = url.searchParams.get('forceCompatMode') === '1';
var forceCompatMode = url.searchParams.get('forceCompatMode') === '1' || localStorage.getItem('forceCompatMode') === '1';
var supportsSimd = await wasmFeatureDetect.simd();
if (verboseStart) console.log('supportsSimd', supportsSimd);
// compat mode build could be built without wasm exception support if needed and detected here
Expand All @@ -181,6 +186,9 @@
if (verboseStart) console.log('forceCompatMode', forceCompatMode);
useCompatMode = true;
}

window.useCompatMode = useCompatMode;

if (verboseStart) console.log('useCompatMode', useCompatMode);
// Blazor United (.Net 8 Blazor Web App) Blazor.start settings are slightly different than Blazor WebAssembly (Blazor WebAssembly Standalone App)
var getRuntimeType = function () {
Expand Down Expand Up @@ -211,6 +219,17 @@
}
})();
</script>

<script>
(function () {
if (window.useCompatMode) {
document.getElementById('error-compat-mode').setAttribute('style', 'display: none');
document.getElementById('error-info').innerText = 'using compat ' + getWasmReleaseVersion();
} else {
document.getElementById('error-info').innerText = getWasmReleaseVersion();
}
})();
</script>
</body>

</html>
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ export function Confirm(query) {

export function ScrollToTop() {
document.querySelector('.content-inner').scrollTo(0, 0);
}

export function FirstInitSuccessful() {
document.getElementById('error-compat-mode').setAttribute('style', 'display: none');
}
Loading