fix(Search) Fixed search auto focus, plus some WIP code
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
@implements IDisposable;
|
||||
@using System.Timers
|
||||
@implements IDisposable;
|
||||
@inject ISearchService searchService
|
||||
@inject IJSRuntime jsRuntime
|
||||
|
||||
@@ -13,7 +14,7 @@
|
||||
@onclick:stopPropagation="true">
|
||||
|
||||
<FormLayoutComponent>
|
||||
<FormTextComponent Id="search-input-box" Placeholder="Search..." OnInput="SearchChanged"></FormTextComponent>
|
||||
<FormTextComponent OnFocus="OnFocus" Id="search-input-box" Placeholder="Search..." OnInput="SearchChanged"></FormTextComponent>
|
||||
</FormLayoutComponent>
|
||||
|
||||
<div class="searchBox">
|
||||
@@ -120,25 +121,33 @@
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
searchService.Subscribe(OnSearchChanged);
|
||||
|
||||
timer = new Timer(200);
|
||||
timer.Elapsed += FocusTimer;
|
||||
timer.Enabled = false;
|
||||
}
|
||||
|
||||
private System.Threading.Timer timer = null!;
|
||||
|
||||
private void FocusTimer(object? sender, ElapsedEventArgs e)
|
||||
{
|
||||
jsRuntime.InvokeVoidAsync("SetFocusToElement", "search-input-box");
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private Timer timer = null!;
|
||||
private void OnSearchChanged()
|
||||
{
|
||||
if (searchService.IsVisible)
|
||||
if (timer.Enabled != searchService.IsVisible)
|
||||
{
|
||||
timer = new System.Threading.Timer(_ =>
|
||||
{
|
||||
jsRuntime.InvokeVoidAsync("SetFocusToElement", "search-input-box");
|
||||
InvokeAsync(StateHasChanged);
|
||||
}, null, 1, 1);
|
||||
|
||||
timer.Enabled = searchService.IsVisible;
|
||||
}
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
searchService.Unsubscribe(OnSearchChanged);
|
||||
timer.Elapsed -= FocusTimer;
|
||||
}
|
||||
|
||||
|
||||
@@ -171,4 +180,9 @@
|
||||
searchService.Hide();
|
||||
}
|
||||
|
||||
private void OnFocus(object obj)
|
||||
{
|
||||
timer.Enabled = false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,21 +14,41 @@
|
||||
<FormInfoComponent>Add a input delay to constructing buildings for simulating worker movement and player micro.</FormInfoComponent>
|
||||
</FormNumberComponent>
|
||||
|
||||
<FormNumberComponent Max="600"
|
||||
Min="0"
|
||||
Value="@WaitTime"
|
||||
OnChange="@OnWaitTimeChanged">
|
||||
<FormLabelComponent>Wait Time</FormLabelComponent>
|
||||
<FormInfoComponent>Not implemented</FormInfoComponent>
|
||||
</FormNumberComponent>
|
||||
|
||||
|
||||
<ButtonComponent OnClick="OnWaitClicked">Add Wait</ButtonComponent>
|
||||
<div class="optionRow">
|
||||
<FormLayoutComponent>
|
||||
<FormNumberComponent Max="600"
|
||||
Min="0"
|
||||
Value="@WaitTime"
|
||||
OnChange="@OnWaitTimeChanged">
|
||||
<FormLabelComponent>Wait Time</FormLabelComponent>
|
||||
</FormNumberComponent>
|
||||
<ButtonComponent OnClick="OnWaitClicked">Add Wait</ButtonComponent>
|
||||
</FormLayoutComponent>
|
||||
<FormLayoutComponent>
|
||||
<FormNumberComponent Max="600"
|
||||
Min="0"
|
||||
Value="@WaitTime"
|
||||
OnChange="@OnWaitTimeChanged">
|
||||
<FormLabelComponent>Wait To</FormLabelComponent>
|
||||
</FormNumberComponent>
|
||||
<ButtonComponent OnClick="OnWaitClicked">Add Wait</ButtonComponent>
|
||||
</FormLayoutComponent>
|
||||
|
||||
</div>
|
||||
</FormLayoutComponent>
|
||||
|
||||
@code {
|
||||
<style>
|
||||
.optionRow {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
}
|
||||
</style>
|
||||
|
||||
@code {
|
||||
public int WaitTime { get; set; } = 30;
|
||||
public int WaitTo { get; set; } = 30;
|
||||
|
||||
|
||||
void OnBuildingInputDelayChanged(ChangeEventArgs changeEventArgs)
|
||||
{
|
||||
buildOrderService.BuildingInputDelay = int.Parse(changeEventArgs.Value!.ToString()!);
|
||||
@@ -46,6 +66,14 @@
|
||||
economyService.Calculate(buildOrderService, timingService, buildOrderService.GetLastRequestInterval());
|
||||
}
|
||||
}
|
||||
|
||||
public void OnWaitToClicked()
|
||||
{
|
||||
if (buildOrderService.AddWait(WaitTime))
|
||||
{
|
||||
economyService.Calculate(buildOrderService, timingService, buildOrderService.GetLastRequestInterval());
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool ShouldRender()
|
||||
{
|
||||
@@ -63,6 +91,5 @@
|
||||
#endif
|
||||
}
|
||||
|
||||
public int WaitTime { get; set; } = 30;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user