feat(Permission) Added start of the Storage feature. Detailed/Plain default toggle

This commit is contained in:
2022-04-24 19:33:18 -04:00
parent 8a4d00054a
commit afaafbe713
20 changed files with 538 additions and 65 deletions
@@ -1,15 +1,17 @@
@inject IJSRuntime jsRuntime;
@inject IKeyService keyService
@inject IImmortalSelectionService filterService
@inject IBuildOrderService buildOrderService
@inject IJSRuntime JsRuntime
@inject IKeyService KeyService
@inject IImmortalSelectionService FilterService
@inject IBuildOrderService BuildOrderService
@inject IStorageService StorageService
@using Services.Website
@implements IDisposable
@if (entity != null)
@if (_entity != null)
{
<div class="entityClickView">
<CascadingValue Value="entity">
<CascadingValue Value="@viewType">
<CascadingValue Value="_entity">
<CascadingValue Value="@_viewType">
<EntityViewComponent></EntityViewComponent>
</CascadingValue>
</CascadingValue>
@@ -17,28 +19,39 @@
}
<style>
.entityClickView {
overflow-y: scroll; width: 100%; overflow-x: hidden; height: 550px;
overflow-y: scroll; width: 100%; overflow-x: hidden; height: 550px;
}
</style>
@code {
private EntityModel? entity = default!;
private string viewType = "Detailed";
private EntityModel? _entity = default!;
private string _viewType = EntityViewType.Detailed;
protected override void OnInitialized()
{
keyService.Subscribe(HandleClick);
KeyService.Subscribe(HandleClick);
StorageService.Subscribe(RefreshDefaults);
RefreshDefaults();
}
void IDisposable.Dispose()
{
keyService.Unsubscribe(HandleClick);
KeyService.Unsubscribe(HandleClick);
StorageService.Unsubscribe(RefreshDefaults);
}
void RefreshDefaults()
{
_viewType = StorageService.GetValue<bool>(StorageKeys.IsPlainView) ? EntityViewType.Plain : EntityViewType.Detailed;
}
protected override bool ShouldRender()
{
#if DEBUG
jsRuntime.InvokeVoidAsync("console.time", "EntityClickViewComponent");
JsRuntime.InvokeVoidAsync("console.time", "EntityClickViewComponent");
#endif
return true;
}
@@ -46,23 +59,23 @@
protected override void OnAfterRender(bool firstRender)
{
#if DEBUG
jsRuntime.InvokeVoidAsync("console.timeEnd", "EntityClickViewComponent");
JsRuntime.InvokeVoidAsync("console.timeEnd", "EntityClickViewComponent");
#endif
}
private void HandleClick()
{
var hotkey = keyService.GetHotkey();
var hotkeyGroup = keyService.GetHotkeyGroup();
var isHoldSpace = keyService.IsHoldingSpace();
var faction = filterService.GetFactionType();
var immortal = filterService.GetImmortalType();
var hotkey = KeyService.GetHotkey();
var hotkeyGroup = KeyService.GetHotkeyGroup();
var isHoldSpace = KeyService.IsHoldingSpace();
var faction = FilterService.GetFactionType();
var immortal = FilterService.GetImmortalType();
var foundEntity = EntityModel.GetFrom(hotkey!, hotkeyGroup, isHoldSpace, faction, immortal);
if (foundEntity != null && entity != foundEntity)
if (foundEntity != null && _entity != foundEntity)
{
entity = foundEntity;
_entity = foundEntity;
StateHasChanged();
}
}
@@ -1,4 +1,4 @@
@page "/analytics"
@page "/data-collection"
@layout PageLayout
+58 -7
View File
@@ -1,16 +1,27 @@
@page "/permissions"
@inject IPermissionService PermissionService
@layout PageLayout
@using Services.Website
@inject Blazored.LocalStorage.ILocalStorageService LocalStorage
@implements IDisposable
<LayoutMediumContentComponent>
<AlertComponent>
<Title>Not Implemented</Title>
<Message></Message>
</AlertComponent>
<PaperComponent>
TODO
<FormLayoutComponent>
<FormToggleComponent
Label="Storage Enabled"
Info="Is storage enabled?"
Value="@_storageEnabled"
OnChange="StoragePermissionChanged"/>
<FormToggleComponent
Label="Data Collection Enabled"
Info="Is data collection enabled?"
Value="@_dataCollectionEnabled"
OnChange="DataCollectionPermissionChanged"/>
</FormLayoutComponent>
</PaperComponent>
<ContentDividerComponent/>
@@ -41,4 +52,44 @@
<InfoAnswerComponent>Enable data tracking if you want the website maintainer to know how your using the website.</InfoAnswerComponent>
</InfoBodyComponent>
</PaperComponent>
</LayoutMediumContentComponent>
</LayoutMediumContentComponent>
@code {
private bool _storageEnabled = false;
private bool _dataCollectionEnabled = false;
protected override void OnInitialized()
{
PermissionService.Subscribe(Update);
Update();
}
void Update()
{
_storageEnabled = PermissionService.GetIsStorageEnabled();
_dataCollectionEnabled = PermissionService.GetIsDataCollectionEnabled();
StateHasChanged();
}
public void Dispose()
{
PermissionService.Unsubscribe(Update);
}
private void StoragePermissionChanged(ChangeEventArgs obj)
{
PermissionService.SetIsStorageEnabled((bool)obj.Value!);
}
private void DataCollectionPermissionChanged(ChangeEventArgs obj)
{
PermissionService.SetIsDataCollectionEnabled((bool)obj.Value!);
}
}
+56 -8
View File
@@ -1,20 +1,68 @@
@page "/storage"
@inject IStorageService StorageService
@using Services.Website
@implements IDisposable
@layout PageLayout
<LayoutMediumContentComponent>
<AlertComponent>
<Title>Not Implemented</Title>
<Message></Message>
</AlertComponent>
<PaperComponent>
TODO
</PaperComponent>
@if (!_enabledPermissions)
{
<AlertComponent Type="@SeverityType.Error">
<Title>Storage Disabled</Title>
<Message>Enable Storage on the Permissions Page.</Message>
</AlertComponent>
}
else
{
<PaperComponent>
<FormLayoutComponent>
<FormToggleComponent
Label="Is Plain View"
Value="@_isEntityPlainView"
OnChange="EntityViewChanged"/>
</FormLayoutComponent>
</PaperComponent>
}
<ContentDividerComponent/>
<PaperComponent>
</PaperComponent>
</LayoutMediumContentComponent>
</LayoutMediumContentComponent>
@code {
bool _enabledPermissions;
protected override void OnInitialized()
{
_enabledPermissions = StorageService.GetValue<bool>(StorageKeys.EnabledStorage);
Update();
StorageService.Subscribe(Update);
}
public void Dispose()
{
StorageService.Unsubscribe(Update);
}
void Update()
{
_isEntityPlainView = StorageService.GetValue<bool>(StorageKeys.IsPlainView);
StateHasChanged();
}
private bool _isEntityPlainView;
private void EntityViewChanged(ChangeEventArgs obj)
{
StorageService.SetValue(StorageKeys.IsPlainView, obj.Value);
}
}